結果
問題 | No.1390 Get together |
ユーザー |
|
提出日時 | 2021-03-09 10:14:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 397 ms / 2,000 ms |
コード長 | 689 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 102,556 KB |
最終ジャッジ日時 | 2024-10-11 01:02:14 |
合計ジャッジ時間 | 8,205 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
N,M=map(int,input().split())l=[[] for i in range(N)]for i in range(N):b,c=map(int,input().split())b-=1c-=1l[c].append(b)root=[i for i in range(M)]height=[0]*Mdef find(a):f=aif a==root[a]:return awhile a!=root[a]:a=root[a]root[f]=areturn adef union(a,b):A=find(a)B=find(b)if A==B:return 0if height[A]>height[B]:root[B]=root[A]return 1else:root[A]=root[B]if height[A]==height[B]:height[B]+=1return 1ans=0for i in l:if len(i)<2:continueS=i[0]for j in range(1,len(i)):ans+=union(i[j],S)print(ans)