結果
問題 | No.483 マッチ並べ |
ユーザー | nanae |
提出日時 | 2017-02-11 13:17:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 1,745 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-06-09 08:13:06 |
合計ジャッジ時間 | 3,342 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 32 ms
10,624 KB |
testcase_02 | AC | 31 ms
10,624 KB |
testcase_03 | AC | 30 ms
10,624 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 30 ms
10,880 KB |
testcase_06 | AC | 31 ms
10,752 KB |
testcase_07 | AC | 30 ms
10,880 KB |
testcase_08 | AC | 30 ms
10,880 KB |
testcase_09 | AC | 30 ms
10,752 KB |
testcase_10 | AC | 31 ms
10,752 KB |
testcase_11 | AC | 31 ms
10,752 KB |
testcase_12 | AC | 31 ms
10,624 KB |
testcase_13 | AC | 31 ms
10,880 KB |
testcase_14 | AC | 31 ms
10,624 KB |
testcase_15 | AC | 31 ms
10,752 KB |
testcase_16 | AC | 30 ms
10,880 KB |
testcase_17 | AC | 31 ms
10,752 KB |
testcase_18 | AC | 31 ms
10,752 KB |
testcase_19 | AC | 31 ms
10,624 KB |
testcase_20 | AC | 31 ms
10,624 KB |
testcase_21 | AC | 31 ms
10,752 KB |
testcase_22 | AC | 31 ms
10,624 KB |
testcase_23 | AC | 31 ms
10,880 KB |
testcase_24 | AC | 30 ms
10,880 KB |
testcase_25 | AC | 30 ms
10,624 KB |
testcase_26 | AC | 31 ms
10,880 KB |
testcase_27 | AC | 31 ms
10,752 KB |
testcase_28 | AC | 31 ms
10,752 KB |
testcase_29 | AC | 31 ms
10,624 KB |
testcase_30 | AC | 32 ms
10,752 KB |
testcase_31 | AC | 31 ms
10,752 KB |
testcase_32 | AC | 32 ms
10,752 KB |
testcase_33 | AC | 31 ms
10,624 KB |
testcase_34 | AC | 30 ms
10,880 KB |
testcase_35 | AC | 32 ms
10,624 KB |
testcase_36 | AC | 31 ms
10,624 KB |
testcase_37 | AC | 31 ms
10,880 KB |
testcase_38 | AC | 32 ms
10,752 KB |
testcase_39 | AC | 32 ms
10,752 KB |
testcase_40 | AC | 31 ms
10,624 KB |
testcase_41 | AC | 31 ms
11,008 KB |
testcase_42 | AC | 31 ms
10,752 KB |
testcase_43 | AC | 32 ms
10,752 KB |
testcase_44 | AC | 31 ms
10,752 KB |
testcase_45 | AC | 32 ms
11,008 KB |
testcase_46 | AC | 30 ms
10,624 KB |
testcase_47 | AC | 31 ms
10,880 KB |
testcase_48 | AC | 31 ms
10,624 KB |
testcase_49 | AC | 31 ms
10,752 KB |
testcase_50 | AC | 31 ms
10,880 KB |
testcase_51 | AC | 31 ms
10,624 KB |
testcase_52 | AC | 31 ms
10,880 KB |
testcase_53 | AC | 30 ms
10,752 KB |
testcase_54 | AC | 31 ms
10,752 KB |
testcase_55 | AC | 31 ms
10,880 KB |
ソースコード
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 + 1 <= num_e: print('NO') break else: print('YES') if __name__ == '__main__': solve()