結果
問題 | No.1640 簡単な色塗り |
ユーザー | roaris |
提出日時 | 2021-08-06 22:29:29 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,986 bytes |
コンパイル時間 | 161 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 130,960 KB |
最終ジャッジ日時 | 2024-06-29 15:34:12 |
合計ジャッジ時間 | 17,804 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
55,328 KB |
testcase_01 | AC | 35 ms
54,328 KB |
testcase_02 | AC | 36 ms
53,868 KB |
testcase_03 | AC | 39 ms
54,536 KB |
testcase_04 | AC | 219 ms
130,960 KB |
testcase_05 | WA | - |
testcase_06 | AC | 36 ms
54,316 KB |
testcase_07 | AC | 35 ms
54,460 KB |
testcase_08 | WA | - |
testcase_09 | AC | 35 ms
54,132 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 | 126 ms
80,156 KB |
testcase_31 | AC | 235 ms
96,168 KB |
testcase_32 | AC | 215 ms
93,436 KB |
testcase_33 | AC | 168 ms
88,980 KB |
testcase_34 | AC | 184 ms
91,204 KB |
testcase_35 | AC | 168 ms
88,052 KB |
testcase_36 | AC | 122 ms
79,852 KB |
testcase_37 | AC | 131 ms
80,748 KB |
testcase_38 | AC | 224 ms
94,264 KB |
testcase_39 | AC | 155 ms
84,328 KB |
testcase_40 | AC | 151 ms
85,176 KB |
testcase_41 | AC | 190 ms
91,768 KB |
testcase_42 | AC | 153 ms
85,904 KB |
testcase_43 | AC | 158 ms
87,144 KB |
testcase_44 | AC | 165 ms
85,464 KB |
testcase_45 | AC | 153 ms
83,968 KB |
testcase_46 | AC | 135 ms
80,288 KB |
testcase_47 | AC | 123 ms
79,052 KB |
testcase_48 | AC | 226 ms
94,412 KB |
testcase_49 | AC | 97 ms
77,820 KB |
testcase_50 | AC | 37 ms
53,928 KB |
testcase_51 | AC | 37 ms
55,616 KB |
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: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 else: self.par[rx] += self.par[ry] self.par[ry] = rx def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] def bfs(s): dist[s] = 0 q = deque([s]) while q: v = q.popleft() for nv in G[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist N = int(input()) AB = [] uf = Unionfind(N) ex_edges = set() G = [[] for _ in range(N)] for _ in range(N): A, B = map(int, input().split()) AB.append((A-1, B-1)) if uf.is_same(A-1, B-1): ex_edges.add((A-1, B-1)) else: uf.unite(A-1, B-1) G[A-1].append(B-1) G[B-1].append(A-1) ex_cnt = defaultdict(int) for A, _ in ex_edges: ex_cnt[uf.root(A)] += 1 rs = set(uf.root(i) for i in range(N)) for r in rs: if ex_cnt[r]==0: exit(print('No')) dist = [-1]*N for A, _ in ex_edges: bfs(A) print('Yes') for A, B in AB: if (A, B) in ex_edges: print(A+1) else: if dist[A]>dist[B]: print(A+1) else: print(B+1)