結果

問題 No.1640 簡単な色塗り
ユーザー qibqib
提出日時 2023-03-10 02:22:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 987 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 81,612 KB
実行使用メモリ 98,532 KB
最終ジャッジ日時 2023-10-18 06:35:14
合計ジャッジ時間 23,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,452 KB
testcase_01 AC 41 ms
55,452 KB
testcase_02 AC 41 ms
55,452 KB
testcase_03 AC 41 ms
55,452 KB
testcase_04 AC 200 ms
98,332 KB
testcase_05 WA -
testcase_06 AC 42 ms
55,452 KB
testcase_07 AC 42 ms
55,452 KB
testcase_08 WA -
testcase_09 AC 41 ms
55,452 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 98 ms
77,652 KB
testcase_31 AC 234 ms
93,280 KB
testcase_32 AC 202 ms
89,848 KB
testcase_33 AC 164 ms
86,828 KB
testcase_34 AC 188 ms
88,616 KB
testcase_35 AC 153 ms
84,512 KB
testcase_36 AC 98 ms
77,592 KB
testcase_37 AC 103 ms
78,280 KB
testcase_38 AC 216 ms
92,200 KB
testcase_39 AC 130 ms
82,872 KB
testcase_40 AC 131 ms
82,964 KB
testcase_41 AC 189 ms
88,700 KB
testcase_42 AC 139 ms
83,420 KB
testcase_43 AC 140 ms
83,536 KB
testcase_44 AC 137 ms
83,512 KB
testcase_45 AC 125 ms
82,288 KB
testcase_46 AC 100 ms
77,744 KB
testcase_47 AC 93 ms
77,364 KB
testcase_48 AC 228 ms
92,448 KB
testcase_49 AC 90 ms
76,968 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 333 ms
98,532 KB
testcase_53 AC 344 ms
98,472 KB
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0