結果
問題 | No.1640 簡単な色塗り |
ユーザー | NatsubiSogan |
提出日時 | 2021-08-06 22:47:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,139 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,004 KB |
実行使用メモリ | 352,728 KB |
最終ジャッジ日時 | 2024-06-29 15:53:18 |
合計ジャッジ時間 | 58,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
61,308 KB |
testcase_01 | AC | 41 ms
54,892 KB |
testcase_02 | AC | 42 ms
54,564 KB |
testcase_03 | AC | 42 ms
54,660 KB |
testcase_04 | AC | 307 ms
138,252 KB |
testcase_05 | AC | 985 ms
249,068 KB |
testcase_06 | AC | 42 ms
54,328 KB |
testcase_07 | AC | 42 ms
55,572 KB |
testcase_08 | AC | 42 ms
56,108 KB |
testcase_09 | AC | 41 ms
55,228 KB |
testcase_10 | AC | 969 ms
128,984 KB |
testcase_11 | AC | 802 ms
116,276 KB |
testcase_12 | AC | 738 ms
111,064 KB |
testcase_13 | AC | 1,265 ms
150,916 KB |
testcase_14 | AC | 1,324 ms
150,264 KB |
testcase_15 | AC | 622 ms
100,864 KB |
testcase_16 | AC | 721 ms
107,448 KB |
testcase_17 | AC | 1,187 ms
143,692 KB |
testcase_18 | AC | 271 ms
83,476 KB |
testcase_19 | AC | 759 ms
111,376 KB |
testcase_20 | AC | 1,000 ms
125,104 KB |
testcase_21 | AC | 851 ms
118,104 KB |
testcase_22 | AC | 205 ms
81,680 KB |
testcase_23 | AC | 1,053 ms
130,396 KB |
testcase_24 | AC | 495 ms
91,856 KB |
testcase_25 | AC | 825 ms
112,664 KB |
testcase_26 | AC | 1,046 ms
133,176 KB |
testcase_27 | AC | 604 ms
100,060 KB |
testcase_28 | AC | 1,150 ms
148,516 KB |
testcase_29 | AC | 1,044 ms
135,712 KB |
testcase_30 | AC | 473 ms
107,620 KB |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | AC | 1,259 ms
211,592 KB |
testcase_34 | AC | 1,417 ms
209,364 KB |
testcase_35 | AC | 1,261 ms
214,252 KB |
testcase_36 | AC | 478 ms
109,736 KB |
testcase_37 | AC | 503 ms
110,248 KB |
testcase_38 | AC | 1,866 ms
273,360 KB |
testcase_39 | AC | 973 ms
173,628 KB |
testcase_40 | AC | 921 ms
148,932 KB |
testcase_41 | AC | 1,597 ms
242,936 KB |
testcase_42 | AC | 1,039 ms
162,016 KB |
testcase_43 | AC | 1,183 ms
233,028 KB |
testcase_44 | AC | 1,139 ms
214,008 KB |
testcase_45 | AC | 717 ms
129,576 KB |
testcase_46 | AC | 485 ms
112,192 KB |
testcase_47 | AC | 318 ms
94,736 KB |
testcase_48 | AC | 1,655 ms
223,604 KB |
testcase_49 | AC | 186 ms
83,048 KB |
testcase_50 | AC | 40 ms
55,236 KB |
testcase_51 | AC | 38 ms
55,800 KB |
testcase_52 | TLE | - |
testcase_53 | TLE | - |
07_evil_01.txt | TLE | - |
07_evil_02.txt | TLE | - |
ソースコード
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.buffer.readline #Union-Find class UnionFind(): def __init__(self, n: int) -> None: self.n = n self.par = list(range(self.n)) self.rank = [1] * self.n def find(self, x: int) -> int: if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> None: p = self.find(x) q = self.find(y) if p == q: return None if p > q: p, q = q, p self.rank[p] += self.rank[q] self.par[q] = p def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def size(self, x: int) -> int: return self.rank[x] n = int(input()) G = [[] for i in range(n)] UF = UnionFind(n) from collections import defaultdict ed_ind = defaultdict(list) for i in range(n): a, b = map(int, input().split()) if a > b: a, b = b, a G[a - 1].append(b - 1) G[b - 1].append(a - 1) UF.unite(a - 1, b - 1) ed_ind[(a - 1, b - 1)].append(i) done = [0] * n visit = [0] * n used = defaultdict(int) def dfs(v): visit[v] = 1 for u in G[v]: if not visit[u]: dfs(u) used[(min(u, v), max(u, v))] += 1 for i in range(n): dfs(i) def dfs2(v): for u in G[v]: if used[(min(u, v), max(u, v))] > 0: for i in ed_ind[(min(u, v), max(u, v))]: if ans[i] == 0: ans[i] = u + 1 dfs2(u) break ans = [0] * n for i in range(n): if not done[UF.find(i)]: for v in G[i]: if used[(min(v, i), max(v, i))] < len(ed_ind[(min(v, i), max(v, i))]): for x in ed_ind[(min(v, i), max(v, i))]: if ans[x] == 0: ans[x] = i + 1 dfs2(i) break done[UF.find(i)] = 1 break if any(i == 0 for i in ans) or len(set(ans)) != n: exit(print("No")) print("Yes") print(*ans, sep="\n")