結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,452 KB
testcase_01 AC 41 ms
55,452 KB
testcase_02 AC 42 ms
55,452 KB
testcase_03 AC 41 ms
55,452 KB
testcase_04 AC 152 ms
86,380 KB
testcase_05 AC 191 ms
98,064 KB
testcase_06 AC 42 ms
55,452 KB
testcase_07 AC 41 ms
55,452 KB
testcase_08 AC 42 ms
55,452 KB
testcase_09 AC 41 ms
55,452 KB
testcase_10 AC 236 ms
90,084 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 318 ms
96,924 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 182 ms
85,416 KB
testcase_17 AC 271 ms
92,660 KB
testcase_18 WA -
testcase_19 AC 190 ms
86,064 KB
testcase_20 AC 226 ms
89,804 KB
testcase_21 AC 203 ms
86,720 KB
testcase_22 AC 109 ms
77,304 KB
testcase_23 AC 247 ms
90,632 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 267 ms
91,472 KB
testcase_27 AC 166 ms
82,704 KB
testcase_28 AC 314 ms
96,096 KB
testcase_29 AC 277 ms
91,468 KB
testcase_30 AC 96 ms
77,780 KB
testcase_31 AC 234 ms
93,232 KB
testcase_32 AC 209 ms
89,776 KB
testcase_33 AC 171 ms
86,800 KB
testcase_34 AC 188 ms
88,560 KB
testcase_35 AC 158 ms
84,452 KB
testcase_36 AC 99 ms
77,724 KB
testcase_37 AC 102 ms
78,196 KB
testcase_38 AC 222 ms
92,164 KB
testcase_39 AC 126 ms
82,680 KB
testcase_40 AC 128 ms
82,776 KB
testcase_41 AC 192 ms
88,640 KB
testcase_42 AC 140 ms
83,312 KB
testcase_43 AC 142 ms
83,452 KB
testcase_44 AC 139 ms
83,348 KB
testcase_45 AC 130 ms
82,260 KB
testcase_46 AC 99 ms
77,888 KB
testcase_47 AC 93 ms
77,448 KB
testcase_48 AC 214 ms
92,412 KB
testcase_49 AC 88 ms
76,992 KB
testcase_50 AC 41 ms
55,452 KB
testcase_51 AC 42 ms
55,452 KB
testcase_52 AC 327 ms
98,592 KB
testcase_53 AC 343 ms
98,592 KB
07_evil_01.txt AC 676 ms
122,604 KB
07_evil_02.txt AC 1,049 ms
146,272 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 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