結果
問題 |
No.1390 Get together
|
ユーザー |
|
提出日時 | 2021-03-09 10:11:45 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 687 bytes |
コンパイル時間 | 423 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 98,448 KB |
最終ジャッジ日時 | 2024-10-11 00:59:46 |
合計ジャッジ時間 | 9,294 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 RE * 18 |
ソースコード
N,M=map(int,input().split()) l=[[] for i in range(N)] for i in range(N): b,c=map(int,input().split()) b-=1 c-=1 l[c].append(b) root=[i for i in range(M)] height=[0]*M def find(a): f=a if a==root[a]: return a while a!=root[a]: a=root[a] root[f]=a return a def union(a,b): A=find(a) B=find(b) if A==B: return if height[A]>height[B]: root[B]=root[A] return 1 else: root[A]=root[B] if height[A]==height[B]: height[B]+=1 return 1 ans=0 for i in l: if len(i)<2: continue S=i[0] for j in range(1,len(i)): ans+=union(i[j],S) print(ans)