結果

問題 No.1640 簡単な色塗り
ユーザー convexineqconvexineq
提出日時 2021-08-06 22:59:23
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 822 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 111,596 KB
最終ジャッジ日時 2023-09-12 03:03:01
合計ジャッジ時間 24,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,432 KB
testcase_01 AC 69 ms
71,252 KB
testcase_02 AC 69 ms
71,144 KB
testcase_03 AC 68 ms
71,256 KB
testcase_04 AC 238 ms
110,272 KB
testcase_05 AC 234 ms
110,260 KB
testcase_06 AC 70 ms
71,560 KB
testcase_07 AC 69 ms
71,100 KB
testcase_08 AC 71 ms
71,468 KB
testcase_09 AC 71 ms
71,252 KB
testcase_10 AC 320 ms
97,648 KB
testcase_11 AC 268 ms
94,056 KB
testcase_12 AC 254 ms
91,912 KB
testcase_13 AC 442 ms
110,324 KB
testcase_14 AC 451 ms
110,276 KB
testcase_15 AC 217 ms
88,180 KB
testcase_16 AC 238 ms
90,204 KB
testcase_17 AC 368 ms
103,388 KB
testcase_18 AC 142 ms
79,648 KB
testcase_19 AC 247 ms
92,048 KB
testcase_20 AC 302 ms
96,664 KB
testcase_21 AC 263 ms
93,800 KB
testcase_22 AC 135 ms
79,536 KB
testcase_23 AC 320 ms
98,324 KB
testcase_24 AC 174 ms
83,432 KB
testcase_25 AC 253 ms
92,228 KB
testcase_26 AC 346 ms
100,852 KB
testcase_27 AC 210 ms
87,452 KB
testcase_28 AC 411 ms
107,140 KB
testcase_29 AC 339 ms
100,248 KB
testcase_30 AC 141 ms
79,484 KB
testcase_31 AC 436 ms
111,180 KB
testcase_32 AC 363 ms
105,268 KB
testcase_33 AC 265 ms
95,836 KB
testcase_34 AC 335 ms
102,412 KB
testcase_35 AC 288 ms
96,176 KB
testcase_36 AC 140 ms
79,496 KB
testcase_37 AC 150 ms
80,728 KB
testcase_38 AC 378 ms
105,772 KB
testcase_39 AC 208 ms
88,620 KB
testcase_40 AC 210 ms
88,732 KB
testcase_41 AC 318 ms
102,932 KB
testcase_42 AC 233 ms
92,592 KB
testcase_43 AC 244 ms
93,360 KB
testcase_44 AC 237 ms
92,824 KB
testcase_45 AC 197 ms
87,956 KB
testcase_46 AC 164 ms
79,744 KB
testcase_47 AC 132 ms
79,224 KB
testcase_48 AC 391 ms
107,908 KB
testcase_49 AC 123 ms
78,628 KB
testcase_50 AC 68 ms
71,524 KB
testcase_51 WA -
testcase_52 AC 451 ms
111,444 KB
testcase_53 AC 451 ms
111,596 KB
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
deg = [0]*n
g = [[] for _ in range(n)]
edges = []
for i in range(n):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    g[a].append((b,i))
    g[b].append((a,i))
    edges.append((a,b,i))

used = [0]*n
ans = [-1]*n
q = [i for i in range(n) if deg[i] == 1]
while q:
    v = q.pop()
    for c,i in g[v]:
        if used[i]: continue
        deg[c] -= 1
        used[i] = 1
        ans[i] = v
        if deg[c] == 1:
            q.append(c)

edges.sort(key=lambda x:x[0])
for a,b,i in edges:
    if used[i]: continue
    if (deg[a] == 2 and deg[b] == 2) or deg[a] == 1:
        ans[i] = a
        deg[b] -= 1
    else:
        ans[i] = b
        deg[a] -= 1

if sorted(ans) == list(range(n)):
    print("Yes")
    for i in ans: print(i+1)
else:
    print("No")
    
0