結果

問題 No.330 Eigenvalue Decomposition
ユーザー ayaoniayaoni
提出日時 2021-04-19 03:56:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 1,321 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 80,532 KB
最終ジャッジ日時 2023-09-17 08:12:23
合計ジャッジ時間 6,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
78,928 KB
testcase_01 AC 73 ms
71,308 KB
testcase_02 AC 89 ms
76,984 KB
testcase_03 AC 122 ms
78,912 KB
testcase_04 AC 73 ms
71,284 KB
testcase_05 AC 90 ms
76,552 KB
testcase_06 AC 125 ms
78,644 KB
testcase_07 AC 74 ms
71,284 KB
testcase_08 AC 114 ms
78,324 KB
testcase_09 AC 146 ms
77,424 KB
testcase_10 AC 72 ms
71,332 KB
testcase_11 AC 110 ms
77,276 KB
testcase_12 AC 171 ms
79,064 KB
testcase_13 AC 74 ms
71,100 KB
testcase_14 AC 119 ms
77,672 KB
testcase_15 AC 103 ms
79,156 KB
testcase_16 AC 72 ms
71,208 KB
testcase_17 AC 121 ms
77,848 KB
testcase_18 AC 154 ms
79,332 KB
testcase_19 AC 75 ms
71,572 KB
testcase_20 AC 135 ms
78,168 KB
testcase_21 AC 306 ms
80,532 KB
testcase_22 AC 91 ms
76,820 KB
testcase_23 AC 168 ms
78,276 KB
testcase_24 AC 145 ms
76,896 KB
testcase_25 AC 71 ms
71,436 KB
testcase_26 AC 89 ms
76,684 KB
testcase_27 AC 80 ms
77,900 KB
testcase_28 AC 73 ms
71,328 KB
testcase_29 AC 79 ms
76,844 KB
testcase_30 AC 74 ms
71,396 KB
testcase_31 AC 73 ms
71,460 KB
testcase_32 AC 73 ms
71,524 KB
testcase_33 AC 75 ms
71,448 KB
testcase_34 AC 75 ms
71,300 KB
testcase_35 AC 75 ms
71,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)

    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)

    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x


N,M = MI()

UF = UnionFind(N)
for _ in range(M):
    a,b,c = MI()
    UF.unite(a,b)

ans = sum(UF.find(i) == i for i in range(1,N+1))
print(ans)
0