結果
問題 | No.1640 簡単な色塗り |
ユーザー | NatsubiSogan |
提出日時 | 2021-08-06 22:47:55 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,139 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 87,364 KB |
実行使用メモリ | 846,216 KB |
最終ジャッジ日時 | 2023-09-12 02:49:05 |
合計ジャッジ時間 | 31,305 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
71,696 KB |
testcase_01 | AC | 95 ms
71,780 KB |
testcase_02 | AC | 96 ms
71,736 KB |
testcase_03 | AC | 94 ms
71,872 KB |
testcase_04 | AC | 370 ms
141,492 KB |
testcase_05 | AC | 1,093 ms
255,552 KB |
testcase_06 | AC | 97 ms
71,752 KB |
testcase_07 | AC | 95 ms
71,608 KB |
testcase_08 | AC | 94 ms
71,504 KB |
testcase_09 | AC | 95 ms
71,364 KB |
testcase_10 | AC | 1,162 ms
148,680 KB |
testcase_11 | AC | 974 ms
126,876 KB |
testcase_12 | AC | 911 ms
124,712 KB |
testcase_13 | AC | 1,479 ms
165,976 KB |
testcase_14 | AC | 1,529 ms
166,096 KB |
testcase_15 | AC | 765 ms
114,596 KB |
testcase_16 | AC | 897 ms
120,816 KB |
testcase_17 | AC | 1,385 ms
168,028 KB |
testcase_18 | AC | 349 ms
89,432 KB |
testcase_19 | AC | 927 ms
121,412 KB |
testcase_20 | AC | 1,183 ms
137,308 KB |
testcase_21 | AC | 1,014 ms
131,020 KB |
testcase_22 | AC | 288 ms
88,844 KB |
testcase_23 | AC | 1,254 ms
150,800 KB |
testcase_24 | AC | 611 ms
99,840 KB |
testcase_25 | AC | 1,034 ms
125,380 KB |
testcase_26 | AC | 1,211 ms
149,804 KB |
testcase_27 | AC | 730 ms
109,120 KB |
testcase_28 | AC | 1,377 ms
176,008 KB |
testcase_29 | AC | 1,209 ms
151,604 KB |
testcase_30 | AC | 855 ms
282,356 KB |
testcase_31 | MLE | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
07_evil_01.txt | -- | - |
07_evil_02.txt | -- | - |
ソースコード
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")