結果

問題 No.1390 Get together
ユーザー 小野寺健小野寺健
提出日時 2021-05-25 08:35:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,113 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 46,676 KB
最終ジャッジ日時 2024-04-21 17:48:16
合計ジャッジ時間 19,662 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 48 ms
11,520 KB
testcase_04 AC 43 ms
11,392 KB
testcase_05 AC 47 ms
11,264 KB
testcase_06 AC 44 ms
11,520 KB
testcase_07 AC 42 ms
11,520 KB
testcase_08 AC 42 ms
11,264 KB
testcase_09 AC 49 ms
11,776 KB
testcase_10 AC 29 ms
10,624 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 30 ms
10,624 KB
testcase_15 AC 30 ms
10,752 KB
testcase_16 AC 823 ms
33,468 KB
testcase_17 AC 948 ms
28,016 KB
testcase_18 AC 799 ms
46,676 KB
testcase_19 AC 1,083 ms
43,048 KB
testcase_20 AC 1,102 ms
31,560 KB
testcase_21 AC 1,113 ms
31,596 KB
testcase_22 AC 949 ms
40,880 KB
testcase_23 AC 967 ms
40,692 KB
testcase_24 AC 942 ms
40,736 KB
testcase_25 AC 1,054 ms
43,512 KB
testcase_26 AC 1,050 ms
43,528 KB
testcase_27 AC 1,068 ms
43,760 KB
testcase_28 AC 1,077 ms
43,608 KB
testcase_29 AC 1,046 ms
43,772 KB
testcase_30 AC 1,058 ms
43,684 KB
testcase_31 AC 1,054 ms
43,788 KB
権限があれば一括ダウンロードができます

ソースコード

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)
        
F = set([find(i) for i in par if i in E])

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