結果
問題 | No.1640 簡単な色塗り |
ユーザー | momoyuu |
提出日時 | 2022-08-03 01:57:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 380 ms / 2,000 ms |
コード長 | 1,255 bytes |
コンパイル時間 | 515 ms |
コンパイル使用メモリ | 81,892 KB |
実行使用メモリ | 102,008 KB |
最終ジャッジ日時 | 2024-07-23 20:04:09 |
合計ジャッジ時間 | 23,915 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,632 KB |
testcase_01 | AC | 43 ms
53,632 KB |
testcase_02 | AC | 42 ms
54,016 KB |
testcase_03 | AC | 42 ms
54,272 KB |
testcase_04 | AC | 216 ms
100,888 KB |
testcase_05 | AC | 239 ms
101,208 KB |
testcase_06 | AC | 46 ms
54,144 KB |
testcase_07 | AC | 45 ms
54,272 KB |
testcase_08 | AC | 42 ms
54,272 KB |
testcase_09 | AC | 41 ms
54,016 KB |
testcase_10 | AC | 253 ms
91,520 KB |
testcase_11 | AC | 239 ms
89,716 KB |
testcase_12 | AC | 223 ms
87,424 KB |
testcase_13 | AC | 346 ms
99,036 KB |
testcase_14 | AC | 347 ms
98,944 KB |
testcase_15 | AC | 188 ms
84,952 KB |
testcase_16 | AC | 205 ms
86,912 KB |
testcase_17 | AC | 297 ms
95,360 KB |
testcase_18 | AC | 133 ms
78,244 KB |
testcase_19 | AC | 217 ms
87,552 KB |
testcase_20 | AC | 256 ms
91,264 KB |
testcase_21 | AC | 236 ms
88,448 KB |
testcase_22 | AC | 129 ms
78,432 KB |
testcase_23 | AC | 274 ms
92,288 KB |
testcase_24 | AC | 160 ms
81,792 KB |
testcase_25 | AC | 219 ms
88,032 KB |
testcase_26 | AC | 289 ms
94,592 KB |
testcase_27 | AC | 188 ms
84,736 KB |
testcase_28 | AC | 332 ms
98,104 KB |
testcase_29 | AC | 284 ms
94,320 KB |
testcase_30 | AC | 148 ms
81,116 KB |
testcase_31 | AC | 347 ms
100,464 KB |
testcase_32 | AC | 307 ms
97,280 KB |
testcase_33 | AC | 224 ms
86,272 KB |
testcase_34 | AC | 259 ms
90,712 KB |
testcase_35 | AC | 224 ms
85,888 KB |
testcase_36 | AC | 146 ms
80,640 KB |
testcase_37 | AC | 147 ms
80,768 KB |
testcase_38 | AC | 315 ms
94,576 KB |
testcase_39 | AC | 196 ms
83,840 KB |
testcase_40 | AC | 193 ms
83,328 KB |
testcase_41 | AC | 256 ms
89,472 KB |
testcase_42 | AC | 213 ms
87,808 KB |
testcase_43 | AC | 215 ms
88,320 KB |
testcase_44 | AC | 214 ms
88,288 KB |
testcase_45 | AC | 187 ms
85,600 KB |
testcase_46 | AC | 147 ms
81,352 KB |
testcase_47 | AC | 134 ms
78,208 KB |
testcase_48 | AC | 301 ms
92,968 KB |
testcase_49 | AC | 118 ms
77,928 KB |
testcase_50 | AC | 44 ms
54,272 KB |
testcase_51 | AC | 44 ms
54,144 KB |
testcase_52 | AC | 375 ms
101,760 KB |
testcase_53 | AC | 380 ms
102,008 KB |
07_evil_01.txt | AC | 689 ms
125,312 KB |
07_evil_02.txt | AC | 1,036 ms
149,504 KB |
ソースコード
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])