結果
問題 | No.330 Eigenvalue Decomposition |
ユーザー | vwxyz |
提出日時 | 2021-11-26 03:39:10 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 555 ms / 5,000 ms |
コード長 | 2,071 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 16,768 KB |
最終ジャッジ日時 | 2024-06-28 20:08:20 |
合計ジャッジ時間 | 7,574 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 254 ms
12,800 KB |
testcase_01 | AC | 41 ms
12,032 KB |
testcase_02 | AC | 45 ms
11,904 KB |
testcase_03 | AC | 259 ms
12,544 KB |
testcase_04 | AC | 40 ms
11,904 KB |
testcase_05 | AC | 43 ms
11,904 KB |
testcase_06 | AC | 276 ms
12,800 KB |
testcase_07 | AC | 40 ms
11,904 KB |
testcase_08 | AC | 191 ms
12,288 KB |
testcase_09 | AC | 473 ms
12,032 KB |
testcase_10 | AC | 40 ms
11,904 KB |
testcase_11 | AC | 175 ms
11,904 KB |
testcase_12 | AC | 510 ms
16,128 KB |
testcase_13 | AC | 41 ms
11,904 KB |
testcase_14 | AC | 166 ms
12,544 KB |
testcase_15 | AC | 64 ms
16,768 KB |
testcase_16 | AC | 40 ms
11,904 KB |
testcase_17 | AC | 51 ms
12,288 KB |
testcase_18 | AC | 126 ms
16,256 KB |
testcase_19 | AC | 40 ms
11,904 KB |
testcase_20 | AC | 56 ms
12,416 KB |
testcase_21 | AC | 555 ms
13,440 KB |
testcase_22 | AC | 49 ms
12,032 KB |
testcase_23 | AC | 71 ms
12,032 KB |
testcase_24 | AC | 473 ms
11,904 KB |
testcase_25 | AC | 41 ms
12,032 KB |
testcase_26 | AC | 56 ms
11,904 KB |
testcase_27 | AC | 53 ms
16,512 KB |
testcase_28 | AC | 40 ms
11,904 KB |
testcase_29 | AC | 46 ms
14,208 KB |
testcase_30 | AC | 40 ms
11,904 KB |
testcase_31 | AC | 41 ms
11,904 KB |
testcase_32 | AC | 42 ms
11,904 KB |
testcase_33 | AC | 41 ms
11,904 KB |
testcase_34 | AC | 41 ms
11,904 KB |
testcase_35 | AC | 41 ms
12,032 KB |
ソースコード
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter, deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as Gcd read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines class UnionFind: def __init__(self,n): self.n=n self.parents=[-1]*n def Find(self,x): stack=[] while self.parents[x]>=0: stack.append(x) x=self.parents[x] for y in stack: self.parents[y]=x return x def Union(self,x,y): x=self.Find(x) y=self.Find(y) if x==y: return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x def Size(self,x): return -self.parents[self.Find(x)] def Same(self,x,y): return self.Find(x)==self.Find(y) def Members(self,x): root = self.Find(x) return [i for i in range(self.n) if self.Find(i)==root] def Roots(self): return [i for i, x in enumerate(self.parents) if x<0] def Group_Count(self): return len(self.Roots()) def All_Group_Members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.Find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.All_Group_Members().items()) N,M=map(int,readline().split()) UF=UnionFind(N) for _ in range(M): A,B,C=map(int,readline().split()) A-=1;B-=1 UF.Union(A,B) ans=UF.Group_Count() print(ans)