結果
問題 |
No.483 マッチ並べ
|
ユーザー |
|
提出日時 | 2017-02-11 13:11:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,744 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-12-29 12:13:23 |
合計ジャッジ時間 | 3,325 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 WA * 12 |
ソースコード
import sys from collections import deque def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def paint_col(Adj, cols_v, cols_e, i, col): cols_v[i] = col nxts = deque([i]) while nxts: u = nxts.popleft() for v in Adj[u]: if cols_e[min(u, v), max(u, v)] == 0: cols_e[min(u, v), max(u, v)] = col if cols_v[v] == 0: cols_v[v] = col nxts.append(v) return None def solve(): N = int(input()) p2n = {} node = 0 Adj = [] cols_v = [] cols_e = {} for i in range(N): r0, c0, r1, c1 = map(int, input().split()) if (r0, c0) not in p2n: p2n[r0, c0] = node cols_v.append(0) node += 1 Adj.append([]) if (r1, c1) not in p2n: p2n[r1, c1] = node cols_v.append(0) node += 1 Adj.append([]) u, v = p2n[r0, c0], p2n[r1, c1] Adj[u].append(v) Adj[v].append(u) cols_e[min(u, v), max(u, v)] = 0 # debug(cols_v, locals()) # debug(cols_e, locals()) # debug(Adj, locals()) col = 1 for i in range(len(cols_v)): if cols_v[i] == 0: paint_col(Adj, cols_v, cols_e, i, col) col += 1 # debug(cols_v, locals()) # debug(cols_e, locals()) for c in range(1, col): num_v = sum(i == c for i in cols_v) num_e = sum(i == c for i in cols_e.values()) if num_v - num_e < 1: print('NO') break else: print('YES') if __name__ == '__main__': solve()