結果

問題 No.1640 簡単な色塗り
ユーザー vwxyzvwxyz
提出日時 2023-05-17 01:43:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 99,320 KB
最終ジャッジ日時 2023-08-21 11:54:33
合計ジャッジ時間 21,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,052 KB
testcase_01 AC 70 ms
71,380 KB
testcase_02 AC 71 ms
71,200 KB
testcase_03 AC 70 ms
71,220 KB
testcase_04 AC 169 ms
99,212 KB
testcase_05 AC 167 ms
99,320 KB
testcase_06 AC 75 ms
71,104 KB
testcase_07 AC 71 ms
71,304 KB
testcase_08 AC 71 ms
71,148 KB
testcase_09 AC 70 ms
71,348 KB
testcase_10 AC 194 ms
91,160 KB
testcase_11 AC 179 ms
87,548 KB
testcase_12 AC 167 ms
86,432 KB
testcase_13 AC 252 ms
99,280 KB
testcase_14 AC 257 ms
99,000 KB
testcase_15 AC 147 ms
84,428 KB
testcase_16 AC 157 ms
85,920 KB
testcase_17 AC 211 ms
93,760 KB
testcase_18 AC 115 ms
78,556 KB
testcase_19 AC 158 ms
86,576 KB
testcase_20 AC 185 ms
90,388 KB
testcase_21 AC 168 ms
87,312 KB
testcase_22 AC 118 ms
78,616 KB
testcase_23 AC 198 ms
91,288 KB
testcase_24 AC 137 ms
80,884 KB
testcase_25 AC 172 ms
86,572 KB
testcase_26 AC 205 ms
93,300 KB
testcase_27 AC 147 ms
84,132 KB
testcase_28 AC 245 ms
96,604 KB
testcase_29 AC 202 ms
93,536 KB
testcase_30 AC 98 ms
79,572 KB
testcase_31 AC 178 ms
94,112 KB
testcase_32 AC 156 ms
89,840 KB
testcase_33 AC 134 ms
87,120 KB
testcase_34 AC 145 ms
88,728 KB
testcase_35 AC 136 ms
87,100 KB
testcase_36 AC 90 ms
76,252 KB
testcase_37 AC 102 ms
80,332 KB
testcase_38 AC 163 ms
89,856 KB
testcase_39 AC 116 ms
81,452 KB
testcase_40 AC 115 ms
81,644 KB
testcase_41 AC 153 ms
89,168 KB
testcase_42 AC 117 ms
82,024 KB
testcase_43 AC 115 ms
82,108 KB
testcase_44 AC 115 ms
82,212 KB
testcase_45 AC 109 ms
81,320 KB
testcase_46 AC 100 ms
79,532 KB
testcase_47 AC 95 ms
76,628 KB
testcase_48 AC 156 ms
90,300 KB
testcase_49 AC 87 ms
76,556 KB
testcase_50 AC 71 ms
70,916 KB
testcase_51 AC 69 ms
70,968 KB
testcase_52 AC 243 ms
99,104 KB
testcase_53 AC 242 ms
99,228 KB
07_evil_01.txt AC 501 ms
127,760 KB
07_evil_02.txt AC 750 ms
145,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

N=int(readline())
used=[False]*N
cnt=[0]*N
graph=[[] for x in range(N)]
for i in range(N):
    a,b=map(int,readline().split())
    a-=1;b-=1
    graph[a].append((b,i))
    graph[b].append((a,i))
    cnt[a]+=1
    cnt[b]+=1
ans_lst=[None]*N
if 0 in cnt:
    print("No")
    exit()
stack=[x for x in range(N) if cnt[x]==1]
while stack:
    x=stack.pop()
    for y,i in graph[x]:
        if not used[i]:
            cnt[x]-=1
            ans_lst[i]=x+1
            used[i]=True
            cnt[y]-=1
            if cnt[y]==1:
                stack.append(y)
            break
    else:
        print("No")
        exit()
for x in range(N):
    if cnt[x]==0:
        continue
    while cnt[x]:
        for y,i in graph[x]:
            if not used[i]:
                cnt[x]-=1
                cnt[y]-=1
                ans_lst[i]=x+1
                used[i]=True
                x=y
                break
print("Yes")
print(*ans_lst,sep="\n")
0