結果

問題 No.1640 簡単な色塗り
ユーザー sotanishysotanishy
提出日時 2021-08-06 22:07:00
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 417 ms / 2,000 ms
コード長 1,017 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 122,196 KB
最終ジャッジ日時 2023-09-12 02:07:51
合計ジャッジ時間 21,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,172 KB
testcase_01 AC 76 ms
71,692 KB
testcase_02 AC 76 ms
71,540 KB
testcase_03 AC 76 ms
71,384 KB
testcase_04 AC 223 ms
119,324 KB
testcase_05 AC 224 ms
121,912 KB
testcase_06 AC 78 ms
71,296 KB
testcase_07 AC 75 ms
71,312 KB
testcase_08 AC 77 ms
71,280 KB
testcase_09 AC 76 ms
71,596 KB
testcase_10 AC 279 ms
99,160 KB
testcase_11 AC 251 ms
97,448 KB
testcase_12 AC 237 ms
95,952 KB
testcase_13 AC 391 ms
114,308 KB
testcase_14 AC 389 ms
114,536 KB
testcase_15 AC 187 ms
86,732 KB
testcase_16 AC 218 ms
93,368 KB
testcase_17 AC 348 ms
111,220 KB
testcase_18 AC 136 ms
80,532 KB
testcase_19 AC 239 ms
95,928 KB
testcase_20 AC 280 ms
98,456 KB
testcase_21 AC 248 ms
97,312 KB
testcase_22 AC 129 ms
79,496 KB
testcase_23 AC 289 ms
101,420 KB
testcase_24 AC 151 ms
82,096 KB
testcase_25 AC 234 ms
95,872 KB
testcase_26 AC 322 ms
107,548 KB
testcase_27 AC 183 ms
85,240 KB
testcase_28 AC 376 ms
111,924 KB
testcase_29 AC 324 ms
107,448 KB
testcase_30 AC 114 ms
81,072 KB
testcase_31 AC 258 ms
105,800 KB
testcase_32 AC 242 ms
104,320 KB
testcase_33 AC 184 ms
93,700 KB
testcase_34 AC 204 ms
95,016 KB
testcase_35 AC 185 ms
93,648 KB
testcase_36 AC 116 ms
80,720 KB
testcase_37 AC 120 ms
81,576 KB
testcase_38 AC 249 ms
104,788 KB
testcase_39 AC 140 ms
82,840 KB
testcase_40 AC 142 ms
82,888 KB
testcase_41 AC 223 ms
102,316 KB
testcase_42 AC 165 ms
91,836 KB
testcase_43 AC 166 ms
91,948 KB
testcase_44 AC 170 ms
91,800 KB
testcase_45 AC 134 ms
82,580 KB
testcase_46 AC 118 ms
81,144 KB
testcase_47 AC 113 ms
80,296 KB
testcase_48 AC 253 ms
104,992 KB
testcase_49 AC 97 ms
76,816 KB
testcase_50 AC 75 ms
71,300 KB
testcase_51 AC 75 ms
71,452 KB
testcase_52 AC 417 ms
122,196 KB
testcase_53 AC 415 ms
122,160 KB
07_evil_01.txt AC 803 ms
167,388 KB
07_evil_02.txt AC 1,217 ms
214,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
G = [set() for _ in range(N)]
deg = [0] * N
for i in range(N):
    A, B = map(lambda x: int(x) - 1, input().split())
    G[A].add((B, i))
    G[B].add((A, i))
    deg[A] += 1
    deg[B] += 1
if 0 in deg:
    print("No")
    exit()
st = []
for v in range(N):
    if deg[v] == 1:
        st.append(v)
ans = [0] * N
while st:
    v = st.pop()
    if deg[v] == 0:
        print("No")
        exit()
    u, i = next(iter(G[v]))
    deg[v] -= 1
    deg[u] -= 1
    G[v].remove((u, i))
    if u != v:
        G[u].remove((v, i))
    ans[i] = v
    if deg[u] == 1:
        st.append(u)
for s in range(N):
    if deg[s] == 0:
        continue
    st.append(s)
    while st:
        v = st.pop()
        u, i = next(iter(G[v]))
        deg[v] -= 1
        deg[u] -= 1
        G[v].remove((u, i))
        if u != v:
            G[u].remove((v, i))
        ans[i] = v
        if deg[u] == 1:
            st.append(u)
print("Yes")
print(*map(lambda x: x + 1, ans), sep='\n')
0