結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
ansain
|
| 提出日時 | 2021-08-06 21:25:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 2,813 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-09-17 01:17:09 |
| 合計ジャッジ時間 | 3,021 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
#from math import isqrt, prod, comb #python3.8用(notpypy)
#from bisect import bisect_left, bisect_right
#from functools import lru_cache, reduce
#from heapq import heappush, heappop, heapify, heappushpop, heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
#numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError, maximum_bipartite_matching, maximum_flow, minimum_spanning_tree
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)
from collections import defaultdict
# https://note.nkmk.me/python-union-find/から一部改変
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
self.group_num = n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
self.group_num -= 1
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 self.group_num
def all_group_members(self):
self.all_group_member = defaultdict(list)
for i in range(self.n):
self.all_group_member[self.find(i)].append(i)
return self.all_group_member
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
mod = 10**9+7
mod2 = 998244353
n=int(input())
uf=UnionFind(n)
ans=0
for i in range((n*(n-1))//2):
a,b,c=map(int, input().split())
a-=1
b-=1
if not uf.same(a,b):
uf.union(a,b)
ans=c
print(ans)
if __name__ == '__main__':
main()
ansain