結果
問題 | No.1640 簡単な色塗り |
ユーザー | rlangevin |
提出日時 | 2023-12-25 20:33:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,751 bytes |
コンパイル時間 | 381 ms |
コンパイル使用メモリ | 82,232 KB |
実行使用メモリ | 180,924 KB |
最終ジャッジ日時 | 2024-09-27 14:39:58 |
合計ジャッジ時間 | 22,837 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
55,456 KB |
testcase_01 | AC | 40 ms
54,448 KB |
testcase_02 | AC | 41 ms
55,504 KB |
testcase_03 | AC | 41 ms
55,784 KB |
testcase_04 | AC | 230 ms
163,532 KB |
testcase_05 | WA | - |
testcase_06 | AC | 42 ms
54,144 KB |
testcase_07 | AC | 45 ms
53,760 KB |
testcase_08 | WA | - |
testcase_09 | AC | 42 ms
54,336 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 153 ms
80,376 KB |
testcase_31 | AC | 397 ms
141,460 KB |
testcase_32 | AC | 353 ms
128,768 KB |
testcase_33 | AC | 292 ms
122,752 KB |
testcase_34 | AC | 333 ms
138,656 KB |
testcase_35 | AC | 297 ms
125,796 KB |
testcase_36 | AC | 151 ms
80,040 KB |
testcase_37 | AC | 178 ms
86,968 KB |
testcase_38 | AC | 381 ms
147,136 KB |
testcase_39 | AC | 204 ms
92,288 KB |
testcase_40 | AC | 220 ms
93,696 KB |
testcase_41 | AC | 361 ms
136,812 KB |
testcase_42 | AC | 257 ms
112,128 KB |
testcase_43 | AC | 255 ms
110,904 KB |
testcase_44 | AC | 245 ms
113,200 KB |
testcase_45 | AC | 209 ms
95,616 KB |
testcase_46 | AC | 166 ms
88,760 KB |
testcase_47 | AC | 133 ms
79,616 KB |
testcase_48 | AC | 378 ms
145,172 KB |
testcase_49 | AC | 111 ms
78,080 KB |
testcase_50 | AC | 44 ms
54,016 KB |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
07_evil_01.txt | WA | - |
07_evil_02.txt | WA | - |
ソースコード
import sys input = sys.stdin.readline from collections import * class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N = int(input()) A, B = [0] * N, [0] * N G = [[] for i in range(N)] U = UnionFind(N) for i in range(N): A[i], B[i] = map(int, input().split()) A[i], B[i] = A[i] - 1, B[i] - 1 G[A[i]].append((B[i], i)) G[B[i]].append((A[i], i)) U.union(A[i], B[i]) Q = [deque() for _ in range(N)] cnt = [0] * N ans, seen = [-1] * N, [0] * N for i in range(N): ui = U.find(A[i]) cnt[ui] += 1 if cnt[ui] == U.get_size(ui): Q[ui].append(A[i]) ans[i] = A[i] + 1 seen[A[i]] = 1 elif cnt[ui] > U.get_size(i): print("No") exit() for s in range(N): while Q[s]: u = Q[s].popleft() for v, ind in G[u]: if seen[v]: continue ans[ind] = v + 1 Q[s].append(v) seen[v] = 1 print("Yes") for a in ans: print(a)