結果
問題 | No.1640 簡単な色塗り |
ユーザー | raven7959 |
提出日時 | 2021-08-18 10:35:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,508 bytes |
コンパイル時間 | 497 ms |
コンパイル使用メモリ | 87,108 KB |
実行使用メモリ | 86,528 KB |
最終ジャッジ日時 | 2023-09-12 04:08:35 |
合計ジャッジ時間 | 22,635 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,332 KB |
testcase_01 | AC | 67 ms
71,244 KB |
testcase_02 | AC | 68 ms
71,148 KB |
testcase_03 | AC | 69 ms
71,288 KB |
testcase_04 | AC | 161 ms
82,512 KB |
testcase_05 | AC | 165 ms
82,852 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 68 ms
71,112 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 188 ms
79,852 KB |
testcase_31 | AC | 326 ms
85,104 KB |
testcase_32 | AC | 310 ms
84,324 KB |
testcase_33 | AC | 269 ms
82,604 KB |
testcase_34 | AC | 289 ms
83,248 KB |
testcase_35 | AC | 276 ms
82,888 KB |
testcase_36 | AC | 189 ms
80,236 KB |
testcase_37 | AC | 202 ms
79,768 KB |
testcase_38 | AC | 317 ms
83,908 KB |
testcase_39 | AC | 238 ms
81,548 KB |
testcase_40 | AC | 237 ms
80,832 KB |
testcase_41 | AC | 288 ms
83,356 KB |
testcase_42 | AC | 244 ms
81,436 KB |
testcase_43 | AC | 251 ms
82,284 KB |
testcase_44 | AC | 249 ms
81,572 KB |
testcase_45 | AC | 228 ms
80,960 KB |
testcase_46 | AC | 190 ms
79,584 KB |
testcase_47 | AC | 169 ms
78,896 KB |
testcase_48 | AC | 314 ms
84,124 KB |
testcase_49 | AC | 137 ms
78,232 KB |
testcase_50 | AC | 70 ms
71,296 KB |
testcase_51 | AC | 71 ms
71,568 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
07_evil_01.txt | WA | - |
07_evil_02.txt | WA | - |
ソースコード
N=int(input()) A=[0]*N B=[0]*N for i in range(N): A[i],B[i]=map(lambda x:int(x)-1,input().split()) par=[i for i in range(N)] #par[x]はxの親の番号,初期状態では全ての頂点が根なのでpar[x]=x size=[1]*N rank=[0]*(N+1) #ランクを用意 def root(x): #xが属する木の根を求める if par[x]==x: #xが根なら終わり return x else: par[x]=root(par[x]) #でなければ親の根につける return par[x] #再帰の終わりにはたどった頂点全てが根についてる def unite(x,y): rx,ry=root(x),root(y) if rx==ry: #はなから同じグループに属してるなら何もしない return else: if rank[x]<rank[y]: #xの属する木の方が低いなら par[rx]=ry #xの根をyの根につける size[ry]+=size[rx]-1 else: par[ry]=rx #でなければyの根をxの根につけた上で size[rx]+=size[ry]-1 if rank[x]==rank[y]: rank[x]+=1 #高さが同じならxの属する木の高さが1増える def same(x,y): #x,yが同じグループに属するかどうかをTrue/Falseで返す rx,ry=root(x),root(y) return rx==ry def get_size(x): return size[root(x)] for i in range(N): if not same(A[i],B[i]): unite(A[i],B[i]) else: size[root(A[i])]-=1 flg=True for i in range(N): if size[i]<0: flg=False if not flg: print("No") exit() print("Yes") seen=[0]*N for i in range(N): if not seen[A[i]]: print(A[i]+1) seen[A[i]]=1 else: print(B[i]+1) seen[B[i]]=1