結果

問題 No.1640 簡単な色塗り
ユーザー momoyuumomoyuu
提出日時 2022-08-03 01:57:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 105,352 KB
最終ジャッジ日時 2023-10-01 02:36:02
合計ジャッジ時間 25,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,376 KB
testcase_01 AC 88 ms
71,580 KB
testcase_02 AC 89 ms
71,592 KB
testcase_03 AC 88 ms
71,504 KB
testcase_04 AC 278 ms
104,844 KB
testcase_05 AC 255 ms
104,792 KB
testcase_06 AC 85 ms
71,688 KB
testcase_07 AC 87 ms
71,716 KB
testcase_08 AC 88 ms
71,596 KB
testcase_09 AC 90 ms
71,744 KB
testcase_10 AC 289 ms
93,400 KB
testcase_11 AC 264 ms
92,472 KB
testcase_12 AC 251 ms
89,128 KB
testcase_13 AC 369 ms
101,032 KB
testcase_14 AC 370 ms
100,716 KB
testcase_15 AC 222 ms
88,448 KB
testcase_16 AC 238 ms
88,260 KB
testcase_17 AC 344 ms
96,896 KB
testcase_18 AC 171 ms
80,856 KB
testcase_19 AC 257 ms
89,600 KB
testcase_20 AC 282 ms
92,340 KB
testcase_21 AC 263 ms
90,228 KB
testcase_22 AC 169 ms
80,044 KB
testcase_23 AC 299 ms
93,372 KB
testcase_24 AC 190 ms
82,788 KB
testcase_25 AC 251 ms
89,224 KB
testcase_26 AC 315 ms
95,300 KB
testcase_27 AC 220 ms
86,320 KB
testcase_28 AC 348 ms
99,840 KB
testcase_29 AC 313 ms
97,696 KB
testcase_30 AC 173 ms
83,056 KB
testcase_31 AC 364 ms
104,436 KB
testcase_32 AC 336 ms
98,588 KB
testcase_33 AC 266 ms
92,232 KB
testcase_34 AC 296 ms
95,328 KB
testcase_35 AC 268 ms
92,240 KB
testcase_36 AC 171 ms
83,192 KB
testcase_37 AC 177 ms
82,920 KB
testcase_38 AC 337 ms
99,388 KB
testcase_39 AC 221 ms
87,720 KB
testcase_40 AC 225 ms
87,680 KB
testcase_41 AC 294 ms
95,736 KB
testcase_42 AC 233 ms
89,372 KB
testcase_43 AC 238 ms
90,064 KB
testcase_44 AC 236 ms
90,076 KB
testcase_45 AC 212 ms
86,684 KB
testcase_46 AC 175 ms
82,448 KB
testcase_47 AC 166 ms
80,868 KB
testcase_48 AC 341 ms
100,168 KB
testcase_49 AC 151 ms
79,480 KB
testcase_50 AC 89 ms
71,596 KB
testcase_51 AC 89 ms
71,660 KB
testcase_52 AC 400 ms
105,232 KB
testcase_53 AC 394 ms
105,352 KB
07_evil_01.txt AC 680 ms
128,688 KB
07_evil_02.txt AC 1,000 ms
155,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
def f(n):
    return int(n) - 1
ab = [list(map(f,input().split())) for _ in range(N)]
d = [0 for _ in range(N)]
l = [0 for _ in range(N)]
ll = [[] for _ in range(N)]
lll = [0 for _ in range(N)]
now = 0
for i in range(N):
    a,b = ab[i]
    d[a] += 1
    d[b] += 1
    ll[a].append(i)
    ll[b].append(i)

from collections import deque
que = deque()
for i in range(N):
    if d[i] == 1:
        que.append(i)

while now != N:
    while que:
        i = que.popleft()
        for j in ll[i]:
            if l[j] != 0:
                continue
            l[j] = i + 1
            lll[i] = 1
            d[i] -= 1
            a,b = ab[j]
            c = a + b - i
            d[c] -= 1
            if d[c] == 1:
                que.append(c)
            elif d[c] <= 0 and lll[c] == 0:
                print("No")
                exit()
    if l[now] != 0:
        now += 1
        continue
    a,b = ab[now]
    if d[a] < d[b]:
        c = a
    else:
        c = b
    e = a + b - c
    l[now] = c + 1
    lll[c] = 1
    d[a] -= 1
    d[b] -= 1
    if d[e] == 1:
        que.append(e)
    now += 1
    continue
for i in range(N):
    if lll[i] == 0:
        print("No")
        exit()
print("Yes")
for i in range(len(l)):
    print(l[i])
0