結果

問題 No.1390 Get together
ユーザー 小野寺健小野寺健
提出日時 2021-05-24 22:40:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 46,452 KB
最終ジャッジ日時 2024-04-21 08:09:43
合計ジャッジ時間 18,857 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 29 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 28 ms
10,752 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 28 ms
10,752 KB
testcase_15 AC 28 ms
10,880 KB
testcase_16 AC 814 ms
33,472 KB
testcase_17 AC 922 ms
27,920 KB
testcase_18 AC 777 ms
46,452 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)
        
F = [i for i in par if i in E]

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