結果
問題 |
No.556 仁義なきサルたち
|
ユーザー |
|
提出日時 | 2025-01-08 01:37:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 402 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 81,916 KB |
実行使用メモリ | 77,524 KB |
最終ジャッジ日時 | 2025-01-08 01:37:42 |
合計ジャッジ時間 | 2,829 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
N,M=map(int,input().split()) ne=[-1]*N def root(N): if ne[N]<0: return N else: ne[N]=root(ne[N]) return ne[N] def merge(x,y): x,y=root(x),root(y) if x==y: return if x>y: x,y=y,x if ne[x]>ne[y]: x,y=y,x ne[x]+=ne[y] ne[y]=x for _ in range(M): a,b=map(lambda x:int(x)-1,input().split()) a,b=max(a,b),min(a,b) merge(b,a) for i in range(N): print(root(i)+1)