結果
問題 | No.1390 Get together |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-12 21:33:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 807 bytes |
コンパイル時間 | 398 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 83,236 KB |
最終ジャッジ日時 | 2024-07-19 20:28:58 |
合計ジャッジ時間 | 5,860 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
""""""def uf_find(n,p):ufl = []while p[n] != n:ufl.append(n)n = p[n]for i in ufl:p[i] = nreturn ndef uf_union(a,b,p,rank):ap = uf_find(a,p)bp = uf_find(b,p)if ap == bp:return Trueelse:if rank[ap] > rank[bp]:p[bp] = apelif rank[ap] < rank[bp]:p[ap] = bpelse:p[bp] = aprank[ap] += 1return Falseimport sysfrom sys import stdinN,M = map(int,stdin.readline().split())ctop = [None] * (N+1)p = [i for i in range(M+1)]rank = [0] * (M+1)ans = 0for i in range(N):b,c = map(int,stdin.readline().split())if ctop[c] == None:ctop[c] = belif not uf_union(ctop[c],b,p,rank):ans += 1print (ans)