結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,420 KB
testcase_01 AC 42 ms
55,420 KB
testcase_02 AC 42 ms
55,420 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 197 ms
98,024 KB
testcase_06 AC 41 ms
55,420 KB
testcase_07 AC 42 ms
55,420 KB
testcase_08 WA -
testcase_09 AC 40 ms
55,420 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 345 ms
96,888 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 297 ms
92,788 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 213 ms
86,692 KB
testcase_22 AC 110 ms
77,268 KB
testcase_23 AC 256 ms
90,596 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 257 ms
91,436 KB
testcase_27 AC 158 ms
82,656 KB
testcase_28 AC 311 ms
96,060 KB
testcase_29 AC 246 ms
91,432 KB
testcase_30 AC 94 ms
77,736 KB
testcase_31 AC 228 ms
93,192 KB
testcase_32 AC 201 ms
89,740 KB
testcase_33 AC 160 ms
86,760 KB
testcase_34 AC 186 ms
88,520 KB
testcase_35 AC 147 ms
84,396 KB
testcase_36 AC 95 ms
77,680 KB
testcase_37 AC 100 ms
78,236 KB
testcase_38 AC 227 ms
92,124 KB
testcase_39 AC 129 ms
82,636 KB
testcase_40 AC 127 ms
82,740 KB
testcase_41 AC 180 ms
88,608 KB
testcase_42 AC 136 ms
83,272 KB
testcase_43 AC 140 ms
83,412 KB
testcase_44 AC 137 ms
83,308 KB
testcase_45 AC 125 ms
82,224 KB
testcase_46 AC 97 ms
77,856 KB
testcase_47 AC 93 ms
77,408 KB
testcase_48 AC 228 ms
92,372 KB
testcase_49 AC 89 ms
76,956 KB
testcase_50 AC 43 ms
55,420 KB
testcase_51 AC 42 ms
55,420 KB
testcase_52 AC 350 ms
98,468 KB
testcase_53 AC 350 ms
98,552 KB
07_evil_01.txt AC 678 ms
122,568 KB
07_evil_02.txt AC 1,044 ms
146,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())

g = [[] for _ in range(n)]
deg = [0 for _ in range(n)]
used = [False for _ in range(n)]
ans = [None for _ in range(n)]
for e in range(n):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  if a == b:
    used[a] = True
    ans[e] = a + 1
  else:
    g[a].append((b, e))
    g[b].append((a, e))
    deg[a] += 1
    deg[b] += 1

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] == 0:
      print("No")
      exit()
    elif 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()
    while len(g[cur]) > 0:
      nxt, e = g[cur].pop()
      if not ans[e] is None:
        continue
      ans[e] = cur + 1
      if used[nxt]:
        continue
      used[nxt] = True
      dq.append(nxt)
      break

if ans.count(None) > 0:
  print("No")
else:
  print("Yes")
  print(*ans, sep="\n")
0