結果
問題 |
No.1640 簡単な色塗り
|
ユーザー |
|
提出日時 | 2023-03-10 02:22:23 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 987 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 99,308 KB |
最終ジャッジ日時 | 2024-09-18 03:11:40 |
合計ジャッジ時間 | 17,033 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 WA * 26 |
ソースコード
from collections import deque n = int(input()) g = [[] for _ in range(n)] deg = [0 for _ in range(n)] for i in range(n): a, b = map(int, input().split()) a -= 1 b -= 1 g[a].append((b, i)) g[b].append((a, i)) deg[a] += 1 deg[b] += 1 used = [False for _ in range(n)] ans = [None for _ in range(n)] dq = deque() for u in range(n): if len(g[u]) == 0: print("No") exit() elif len(g[u]) == 1: used[u] = True dq.append(u) while len(dq) > 0: cur = dq.popleft() for nxt, e in g[cur]: if not ans[e] is None: continue deg[nxt] -= 1 ans[e] = cur + 1 if deg[nxt] == 1: used[nxt] = True dq.append(nxt) for src in range(n): if used[src]: continue dq.append(src) while len(dq) > 0: cur = dq.popleft() for nxt, e in g[cur]: if not ans[e] is None: continue if used[nxt]: continue ans[e] = nxt + 1 used[nxt] = True dq.append(nxt) print("Yes") print(*ans, sep="\n")