結果

問題 No.1390 Get together
ユーザー 小野寺健小野寺健
提出日時 2021-05-25 08:06:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 812 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 46,472 KB
最終ジャッジ日時 2024-04-21 17:21:52
合計ジャッジ時間 21,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,880 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 32 ms
10,880 KB
testcase_11 AC 32 ms
10,752 KB
testcase_12 AC 32 ms
10,752 KB
testcase_13 WA -
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 32 ms
10,752 KB
testcase_16 AC 894 ms
33,500 KB
testcase_17 AC 1,112 ms
27,940 KB
testcase_18 AC 814 ms
46,472 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())

par = [0] * N
rank = [0] * N

def init(n):
    for i in range(n):
        par[i] = i
        rank[i] = 0
        
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

def same(x, y):
    return find(x) == find(y)

init(N)
D = dict()
E = dict()

for _ in range(N):
    b, c = map(int, input().split())
    E[c-1] = 0
    if (b-1) not in D:
        D[b-1] = c-1
    else:
        unite(D[b-1], c-1)
        find(D[b-1])
        find(c-1)
        
F = set([i for i in par if i in E])

print(len(D) - len(F))
0