結果
問題 |
No.812 Change of Class
|
ユーザー |
|
提出日時 | 2019-04-12 21:58:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 907 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 29,312 KB |
最終ジャッジ日時 | 2024-06-12 07:11:36 |
合計ジャッジ時間 | 19,487 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 5 WA * 55 |
ソースコード
from collections import Counter def find(A,x): p = A[x] if p == x: return x a = find(A,p) A[x] = a return a def union(A, x, y): # bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。 if find(A,x) > find(A,y): bx, by = find(A,y), find(A,x) else: bx, by = find(A,x), find(A,y) A[y] = bx A[by] = bx N, M = map( int, input().split()) E = [ [] for _ in range(N)] V = [ i for i in range(N)] for _ in range(M): p, q = map( int, input().split()) p, q = p-1, q-1 union(V, p ,q) E[p].append(q) E[q].append(p) for i in range(N): _ = find(V,i) CV = Counter(V) Q = int( input()) A = [ int( input()) for _ in range(Q)] A = list( map( lambda x:x-1, A)) for i in range(Q): # print( CV[find(V,A[i])], len(E[A[i]]), A[i]) print( CV[find(V,A[i])]-1, CV[find(V,A[i])] -1 - len(E[A[i]]))