結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,420 KB
testcase_01 AC 42 ms
55,420 KB
testcase_02 AC 41 ms
55,420 KB
testcase_03 AC 42 ms
55,420 KB
testcase_04 AC 155 ms
86,344 KB
testcase_05 AC 189 ms
98,024 KB
testcase_06 AC 41 ms
55,420 KB
testcase_07 AC 42 ms
55,420 KB
testcase_08 AC 42 ms
55,420 KB
testcase_09 AC 42 ms
55,420 KB
testcase_10 AC 238 ms
90,048 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 314 ms
96,888 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 182 ms
85,380 KB
testcase_17 AC 275 ms
92,624 KB
testcase_18 WA -
testcase_19 AC 197 ms
86,016 KB
testcase_20 AC 236 ms
89,768 KB
testcase_21 AC 205 ms
86,708 KB
testcase_22 AC 111 ms
77,264 KB
testcase_23 AC 243 ms
90,596 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 260 ms
91,436 KB
testcase_27 AC 163 ms
82,652 KB
testcase_28 AC 311 ms
96,060 KB
testcase_29 AC 252 ms
91,432 KB
testcase_30 AC 97 ms
77,740 KB
testcase_31 AC 221 ms
93,192 KB
testcase_32 AC 193 ms
89,736 KB
testcase_33 AC 164 ms
86,760 KB
testcase_34 AC 178 ms
88,520 KB
testcase_35 AC 154 ms
84,396 KB
testcase_36 AC 94 ms
77,684 KB
testcase_37 AC 99 ms
78,236 KB
testcase_38 AC 219 ms
92,124 KB
testcase_39 AC 129 ms
82,640 KB
testcase_40 AC 128 ms
82,740 KB
testcase_41 AC 180 ms
88,604 KB
testcase_42 AC 135 ms
83,268 KB
testcase_43 AC 139 ms
83,416 KB
testcase_44 AC 137 ms
83,312 KB
testcase_45 AC 126 ms
82,224 KB
testcase_46 AC 97 ms
77,852 KB
testcase_47 AC 93 ms
77,408 KB
testcase_48 AC 215 ms
92,368 KB
testcase_49 AC 89 ms
76,952 KB
testcase_50 AC 41 ms
55,420 KB
testcase_51 AC 41 ms
55,420 KB
testcase_52 AC 321 ms
98,448 KB
testcase_53 AC 330 ms
98,556 KB
07_evil_01.txt AC 680 ms
122,568 KB
07_evil_02.txt AC 982 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 used[u]:
    continue
  if deg[u] == 0:
    print("No")
    exit()
  elif deg[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