s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
int64
0
100
memory
stringlengths
4
6
code_size
int64
15
14.7k
code
stringlengths
15
14.7k
problem_id
stringlengths
6
6
problem_description
stringlengths
358
9.83k
input
stringlengths
2
4.87k
output
stringclasses
807 values
__index_level_0__
int64
1.1k
1.22M
s792135224
p02241
u007270338
1535703572
Python
Python3
py
Accepted
30
5908
894
#coding: utf-8 inf = 1000000000 n = int(input()) mtrx = [] for i in range(n): col2 = list(map(int,input().split())) col = [] for num in col2: if num == -1: num = inf col.append(num) mtrx.append(col) def prim(): color = ["white" for i in range(n)] d = [inf for i in r...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,682
s706199840
p02241
u726330006
1540448018
Python
Python3
py
Accepted
50
6696
1,074
def judge_reachable(graph,start,end,flag): flag[start]=1 for vertex in graph[start]: if(flag[vertex]==1): continue if (vertex==end): return 1 if(judge_reachable(graph,vertex,end,flag)): return 1 return 0 graph_n=int(input()) edge_dict={} f...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,683
s421093238
p02241
u637322311
1541232434
Python
Python3
py
Accepted
20
5904
866
from sys import stdin def read_matrix(n): A = [] for _ in range(n): a = [ int(i) for i in stdin.readline().strip().split() ] A.append(a) return A def prim(n, A): color = [ 'WHITE' for i in range(n) ] d = [ float('inf') for i in range(n) ] d[0] = 0 p = [-1] * n while Tr...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,684
s129746996
p02241
u629780968
1545454961
Python
Python3
py
Accepted
30
5772
851
n = int(input()) m = [[-1 for i in range(n)] for j in range(n)] #お隣さんへのコストを保存(この中から最小を探す) v = set() v.add(0) for i in range(n): #隣接の辺のコストを入力 nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] def prim_mst(n): isVisited = [False] * n d = [0] + [2001] * (n-1) #TとV-Tのを繋ぐ最小辺の重み...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,685
s515092830
p02241
u629780968
1545454997
Python
Python3
py
Accepted
20
5776
853
n = int(input()) m = [[-1 for i in range(n)] for j in range(n)] #お隣さんへのコストを保存(この中から最小を探す) v = set() v.add(0) for i in range(n): #隣接の辺のコストを入力 nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] def prim_mst(n): isVisited = [False] * n d = [0] + [2001] * (n-1) #TとV-Tのを繋ぐ最小辺の重み...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,686
s739976348
p02241
u629780968
1545456164
Python
Python3
py
Accepted
20
5904
258
n=int(input()) M=[list(map(int,input().split()))for _ in[0]*n] d=[0]+[1e4]*n b=[1]*n a=0 while 1: u=-1 for i in range(n): if b[i]and(u<0 or d[i]<d[u]):u=i if u<0:break b[u]=0 a+=d[u] for v in range(n): t=M[u][v] if t+1 and d[v]>t:d[v]=t print(a)
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,687
s242601432
p02241
u629780968
1545456223
Python
Python3
py
Accepted
20
5888
344
n=int(input()) m=[list(map(int,input().split()))for _ in[0]*n] # m = [[-1 for i in range(n)] for j in range(n)] d=[0]+[10**9]*n b=[1]*n a=0 while 1: u=-1 for i in range(n): if b[i] and (u<0 or d[i]<d[u]): u=i if u<0: break b[u]=0 a+=d[u] for v in range(n): t=m[u][v] if t+1 and d[v]>t: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,688
s565440432
p02241
u629780968
1545456275
Python
Python3
py
Accepted
20
5772
483
n=int(input()) # m=[list(map(int,input().split()))for _ in[0]*n] m = [[-1 for i in range(n)] for j in range(n)] for i in range(n): #隣接の辺のコストを入力 nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] d=[0]+[10**9]*n b=[1]*n a=0 while 1: u=-1 for i in range(n): if b[i] and (u<0 or d[...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,689
s982010771
p02241
u629780968
1545456395
Python
Python3
py
Accepted
20
5768
453
n=int(input()) m = [[-1 for i in range(n)] for j in range(n)] for i in range(n): #隣接の辺のコストを入力 nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] d=[0]+[10**9]*n visited=[0]*n a=0 while 1: u=-1 for i in range(n): if not visited[i] and (u<0 or d[i]<d[u]): u=i if u<0: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,690
s125212161
p02241
u629780968
1545456916
Python
Python3
py
Accepted
20
5776
487
n=int(input()) m = [[-1 for i in range(n)] for j in range(n)] for i in range(n): #隣接の辺のコストを入力 nums = list(map(int, input().split())) for j in range(n): m[i][j] = nums[j] d=[0]+[10**9]*(n-1) visited=[0]*n while 1: u=-1 for i in range(n): if not visited[i] and (u<0 or d[i]<d[u]): u = i if u < 0:...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,691
s969613038
p02241
u629780968
1545463192
Python
Python3
py
Accepted
20
6652
564
from heapq import heappush, heappop, heapify N = int(input()) edges = [[] for i in range(N)] for v in range(N): for w, c in enumerate(map(int, input().split())): if c != -1: edges[v].append((w, c)) visited = [0]*N que = [(c, w) for w, c in edges[0]] visited[0] = 1 heapify(que) d=[0]+[10**9]*(...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,692
s675905435
p02241
u165578704
1556444821
Python
Python3
py
Accepted
20
6020
2,846
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10 ** 9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) INF=float('inf') # Union-Find木 class UnionFind: def __init__(self, n): ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,693
s016310196
p02241
u276288047
1556615476
Python
Python3
py
Accepted
40
7176
1,307
# coding: utf-8 class UnionFind: def __init__(self,N): self.par = [i for i in range(N)] self.rank = [1]*N def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unit...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,694
s638123336
p02241
u567380442
1422447651
Python
Python3
py
Accepted
50
7168
1,028
class Forest: def __init__(self, g, id): self.forest = set([id]) self.graph = g self.next_wait = self.graph[id] self.wait = 0 def add_tree(self, id): self.wait += self.next_wait[id] self.forest.update([id]) self.marge_next_wait(id) def next_t...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,695
s247642466
p02241
u839012335
1437231330
Python
Python
py
Accepted
30
5584
1,252
class UnionFind: def __init__(self, n): self.par = range(n) self.rank = [0 for i in xrange(n)] def find(self, x): if self.par[x] == x: return x self.par[x] = self.find(self.par[x]) return self.par[x] def same(self, x, y): return self.find(x) == ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,696
s186185880
p02241
u881590806
1452159227
Python
Python
py
Accepted
10
6836
652
INFTY = 10000000000000000000000000000 n = int(raw_input()) A = {} for i in range(n): A[i] = {} for j,c in enumerate(raw_input().strip().split(' ')): c = int(c) if c > -1: A[i][j] = c d = {} chosen = {} for i in range(n): d[i] = INFTY chosen[i] = False d[0] = 0 ans = 0 while True: m...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,697
s860827047
p02241
u669284080
1453723491
Python
Python3
py
Accepted
60
7820
495
#!/usr/bin/python3 import itertools n = int(input()) A = [] for i in range(n): src = input() dst = src.replace('-1', '3000') ai = list(map(int, dst.split())) A.append(ai) # rand i = 0 S = 0 G = set() T = set(range(n)) T.remove(i) G.add(i) while len(T) > 0: m = 3000 mg = None mt = None ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,698
s290608449
p02241
u731976921
1454467401
Python
Python
py
Accepted
30
6592
706
#!/usr/bin/python import sys def parse(): A = [] n = raw_input() for line in sys.stdin: values = line.split() values = [ int(x) for x in values ] A.append(values) return A def prim(cost): res = 0 V = len(cost) mincost = [float("inf")] * V used = [False] * V mincost[0] = 0 ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,699
s450140372
p02241
u334643297
1454602382
Python
Python
py
Accepted
40
6492
333
n = int(raw_input()) A = [0] NY = range(1, n) a = [[0 for i in xrange(n)] for j in xrange(n)] for i in xrange(n): a[i] = map(int,raw_input().split()) long = 0 while NY != []: amin = 2001 for i in A: for j in NY: if 0 <= a[i][j] < amin: amin = a[i][j] addA = j A.append(addA) NY.remove(addA) long += am...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,700
s755549605
p02241
u069446126
1454602968
Python
Python
py
Accepted
10
6508
657
def prim(cost): sumcost = 0 V = len(cost) mincost = [float('inf')] * V used = [False] * V mincost[0] = 0 while True: j = -1 for i in range(V): if not used[i] and (j == -1 or mincost[i] < mincost[j]): j = i if j == -1: break ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,701
s386913008
p02241
u920118302
1454648873
Python
Python3
py
Accepted
20
7856
508
n = int(input()) G = [] for i in range(n): G.append(input().split()) for j in range(len(G[i])): G[i][j] = int(G[i][j]) ans = 0 mincost = [2001] * n flag = [0] * n mincost[0] = 0 while True: v = -1 for j in range(n): if flag[j] != 1 and (v == -1 or mincost[j] < mincost[v]): v...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,702
s906989175
p02241
u000228958
1454683503
Python
Python
py
Accepted
10
6780
816
# -*- coding: utf-8 -*- n = input() M = [[float("inf") for j in xrange(n)] for i in xrange(n)] color = ['WHITE' for i in xrange(n)] d = [float("inf") for i in xrange(n)] p = [-1 for i in xrange(n)] for i in xrange(n): tmp = map(int, raw_input().split()) for j in xrange(n): if tmp[j] != -1: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,703
s241013324
p02241
u970436839
1454757268
Python
Python
py
Accepted
10
6484
750
n = input() INFTY = 10000000 color = [0 for i in xrange(n)] M = [[INFTY for i in xrange(n)] for i in xrange(n)] d = [INFTY for i in xrange(n)] p = [-1 for i in xrange(n)] def MST(): d[0] = 0 while True: cost = INFTY for i in xrange(n): if color[i] != 2 and d[i] < cost: cost = d[i] ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,704
s527560610
p02241
u038005340
1454868061
Python
Python
py
Accepted
40
6556
396
n = int( raw_input() ) A = [0] p = range(1, n) a = [ [ 0 for i in xrange(n) ] for j in xrange(n) ] for i in xrange(n): a[i] = map( int,raw_input().split() ) l = 0 while p != []: a_min = 2001 for i in A: for j in p: if 0 <= a[i][j] < a_min: a_min = a[i][j] ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,705
s256336518
p02241
u967035362
1454941133
Python
Python
py
Accepted
30
6580
629
from __future__ import division, print_function from sys import stdin, maxint def main(): num = int(stdin.readline()) M = [] for _ in xrange(num): M.append([int(s) for s in stdin.readline().split()]) g = set(xrange(1, num+1)) index = g.pop() h = {index} weight = 0 while...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,706
s535178308
p02241
u655651061
1454995838
Python
Python
py
Accepted
40
6408
341
n = int(raw_input()) A = [0] B = range(1, n) a = [[0 for i in xrange(0,n)] for j in xrange(0,n)] for i in xrange(0,n): a[i] = map(int,raw_input().split()) count = 0 while B != []: smin = 2001 for i in A: for j in B: if 0 <= a[i][j] < smin: smin = a[i][j] addA = j A.append(addA) B.remove(addA) count...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,707
s534747592
p02241
u563876281
1455002159
Python
Python
py
Accepted
30
6476
619
from __future__ import division, print_function from sys import stdin, maxint def main(): x = int(stdin.readline()) y = [] for _ in xrange(x): y.append([int(s) for s in stdin.readline().split()]) g = set(xrange(1, x+1)) index = g.pop() h = {index} leng = 0 while g: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,708
s504855630
p02241
u020577611
1455004571
Python
Python
py
Accepted
30
6460
361
n=int(raw_input()) a=[[0 for i in xrange(0,n)] for j in xrange(0,n)] for i in xrange(n): a[i]=map(int,raw_input().split()) omomi=0 A=[0] B=range(1, n) while B!=[]: c=2000 for i in A: for j in B: if 0<=a[i][j]<=c: c=a[i][j] AA=j A.append(AA) B.r...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,709
s190994111
p02241
u885467869
1455007602
Python
Python
py
Accepted
10
6572
1,103
def prim(n): d = [None] * 100 p = [None] * 100 color = [None] * 100 for i in xrange(n): d[i] = float('inf') p[i] = -1 color[i] = 0 d[0] = 0 while(True): minv = float('inf') u = -1 for i in xrange(n): if minv > d[i] and co...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,710
s759218312
p02241
u078762447
1455008992
Python
Python
py
Accepted
30
6484
688
n = int(raw_input()) g = [[10000 for i in range(n)]for j in range(n)] c = [0 for i in range(n)] d = [10000 for i in range(n)] p = [-1 for i in range(n)] d[0] = 0 for i in range(n): g[i] = map(int,raw_input().split()) while 1: min = 10000 u = -1 for i in range(n): if c[i] != 2 and d[i] < min...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,711
s936297625
p02241
u119456964
1455009014
Python
Python
py
Accepted
10
6648
764
n = int(raw_input()) INFTY = float('inf') color = [0 for i in range(n)] M = [[INFTY for i in range(n)] for j in range(n)] d = [INFTY for i in range(n)] p = [-1 for i in range(n)] def MST(): d[0] = 0 while True: cost = INFTY for i in range(n): if color[i] != 2 and d[i] < cost: cost = d[...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,712
s137926427
p02241
u974554153
1455019263
Python
Python
py
Accepted
10
6508
658
def prim(cost): sumcost = 0 V = len(cost) mincost = [float('inf')] * V used = [False] * V mincost[0] = 0 while True: j = -1 for i in range(V): if not used[i] and (j == -1 or mincost[i] < mincost[j]): j = i if j == -1: break ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,713
s518939306
p02241
u619765879
1455026901
Python
Python
py
Accepted
10
6528
644
n = input() M = [] inf = 1000000000 for i in range(n): M.append(map(int, raw_input().split())) for i in range(n): for j in range(n): if M[i][j]==-1: M[i][j] = inf d = [inf for i in range(n)] p = [-1 for i in range(n)] color = [0 for i in range(n)] d[0] = 0 while 1: minv = inf u = -1 for i in range...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,714
s336122534
p02241
u038243492
1455028603
Python
Python
py
Accepted
40
6504
390
n = int(raw_input()) A = [0] NY = range(1, n) a = [[0 for i in xrange(n)] for j in xrange(n)] for i in xrange(n): a[i] = map(int,raw_input().split()) long = 0 while NY != []: amin = 2001 for i in A: for j in NY: if 0 <= a[i][j] < amin: amin = a[i][j] addA ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,715
s562715089
p02241
u393769849
1455028699
Python
Python
py
Accepted
10
6816
802
n = input() M = [[float("inf") for j in xrange(n)] for i in xrange(n)] color = ['WHITE' for i in xrange(n)] d = [float("inf") for i in xrange(n)] p = [-1 for i in xrange(n)] for i in xrange(n): tmp = map(int, raw_input().split()) for j in xrange(n): if tmp[j] != -1: M[i][j] = tmp[j] d[...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,716
s814546384
p02241
u536494052
1455029607
Python
Python
py
Accepted
40
8148
905
import sys global status, d status = {} d=0 def mst(p1, GRAPH): global status edge={} total = 0 mini = 0 while True: status[p1]=True for p2 in range(len(status)): if status[p2]==False and GRAPH.has_key((p1,p2)): edge[(p1, p2)]=GRAPH[(p1, p2)]...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,717
s070801419
p02241
u424209323
1455029771
Python
Python
py
Accepted
40
6488
387
n = int(raw_input()) A = [0] p = range(1, n) a = [[0 for i in range(n)]for j in range(n)] for i in range(n): a[i] = map(int, raw_input().split() ) l = 0 while p != []: a_min = 10000 for i in A: for j in p: if 0 <= a[i][j] < a_min: a_min = a[i][j] add_A ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,718
s274750748
p02241
u424209323
1455029791
Python
Python
py
Accepted
40
6488
378
n = input() A = [0] p = range(1, n) a = [[0 for i in range(n)]for j in range(n)] for i in range(n): a[i] = map(int, raw_input().split() ) l = 0 while p != []: a_min = 10000 for i in A: for j in p: if 0 <= a[i][j] < a_min: a_min = a[i][j] add_A = j A...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,719
s615831893
p02241
u424209323
1455030068
Python
Python
py
Accepted
40
6408
378
n = input() A = [0] p = range(1, n) a = [[0 for i in range(n)]for j in range(n)] for i in range(n): a[i] = map(int, raw_input().split() ) l = 0 while p != []: a_min = 10000 for i in A: for j in p: if 0 <= a[i][j] < a_min: a_min = a[i][j] add_A = j A...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,720
s834356297
p02241
u177808190
1455030225
Python
Python
py
Accepted
10
6492
958
MAX = 100 INF = 1000000 WHITE = 0 GRAY = 1 BLACK = 2 n = int(raw_input()) M = [[0 for i in range(n)]for j in range(n)] d = [0 for i in range(MAX)] p = [0 for i in range(MAX)] Color = [0 for i in range(MAX)] for i in range(n): a = map(int, raw_input().split()) for j in range(n): e = a[j] if e ==...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,721
s583321251
p02241
u253463900
1455031368
Python
Python3
py
Accepted
30
7968
1,112
class Node(object): def __init__(self, V): self.V = V self.d = float('inf') self.p = -1 self.state = -1 # -1 -> undiscovered # 1 -> finished # 0 -> found(not finished) M = [float('inf')] * 100 for i in range(100): M[i] = [float('inf')] * 100 n = int(i...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,722
s303736871
p02241
u613805578
1455033444
Python
Python
py
Accepted
10
6648
748
n = input() inf = 10000000 color = [0 for i in xrange(n)] M = [[inf for i in xrange(n)] for i in xrange(n)] d = [inf for i in xrange(n)] p = [-1 for i in xrange(n)] def mst(): d[0] = 0 while True: cost = inf for i in xrange(n): if color[i] != 2 and d[i] < cost: cost = d[i] u = ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,723
s028823307
p02241
u797673668
1455081977
Python
Python3
py
Accepted
90
8736
605
import heapq n = int(input()) edges = [set((w, j) for j, w in enumerate(map(int, input().split())) if w > -1) for _ in range(n)] def get_minimum(): global n, edges visited = [False] * n visited[0] = True queue = list(edges[0]) heapq.heapify(queue) total_cost = 0 while queue: cost,...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,724
s193094446
p02241
u797673668
1455082952
Python
Python3
py
Accepted
90
8704
515
import heapq n = int(input()) edges = [set((w, j) for j, w in enumerate(map(int, input().split())) if w > -1) for _ in range(n)] visited = [False] * n visited[0] = True queue = list(edges[0]) heapq.heapify(queue) total_cost, remains = 0, n - 1 while True: cost, vertex = heapq.heappop(queue) if visited[vertex]...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,725
s514279895
p02241
u797673668
1455083187
Python
Python3
py
Accepted
30
8704
553
import heapq n = int(input()) edges = [set((w, j) for j, w in enumerate(map(int, input().split())) if w > -1) for _ in range(n)] visited = [False] * n visited[0] = True queue = list(edges[0]) heapq.heapify(queue) total_cost, remains = 0, n - 1 while True: cost, vertex = heapq.heappop(queue) if visited[vertex]...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,726
s572221016
p02241
u663227983
1455287256
Python
Python
py
Accepted
30
6472
1,113
infty = 10**21 white = 0 gray = 1 black = 2 n = input() m = [[0 for i in xrange(n)] for j in xrange(n)] l = m d = [0 for i in xrange(n)] p = [0 for i in xrange(n)] color = [0 for i in xrange(n)] def prim(): for i in xrange(n): d[i] = infty p[i] = -1 color[i] = white d[0] = 0...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,727
s651427239
p02241
u803327846
1455376131
Python
Python
py
Accepted
40
6392
382
n = input() A = [0] p = range(1, n) a = [[0 for i in range(n)]for j in range(n)] for i in range(n): a[i] = map(int, raw_input().split() ) l = 0 while p != []: a_min = 10000 for i in A: for j in p: if 0 <= a[i][j] < a_min: a_min = a[i][j] add_A = j ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,728
s337687347
p02241
u408260374
1455861168
Python
Python3
py
Accepted
30
8612
2,109
class UnionFindTree: """Disjoint-Set Data Structure Union-Find Tree complexity: init: O(n) find, unite, same: O(alpha(n)) used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) """ def __init__(self, n): self.par = list(range(n)) # parent self.rank = [0] * n...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,729
s101227366
p02241
u408260374
1455861382
Python
Python3
py
Accepted
60
9032
1,100
import heapq class MinimumSpanningTree: """ Prim's algorithm: find minimum spanning tree Complexity: O(E log(V)) used in GRL2A(AOJ) """ def __init__(self, V, E, start=0, INF=10**9): """ V: the number of vertexes E: adjacency list (undirected graph) start: s...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,730
s288663547
p02241
u894114233
1459579421
Python
Python
py
Accepted
30
6580
651
def prim(): global n global ct color=[0]*n d=[float('inf')]*n d[0]=0 while True: mincost=float('inf') for i in xrange(n): if color[i]!=2 and d[i]<mincost: mincost=d[i] u=i if mincost==float('inf'): break ct+=...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,731
s260175194
p02241
u963402991
1463108154
Python
Python3
py
Accepted
70
7908
970
MAX = 100 INF = 1 << 21 WHITE = 0 # ?????¢?´¢ GRAY = 1 # ??¢?´¢????±? BLACK = 2 # ??¢?´¢?????? n = int(input()) M = [list(map(int, input().split())) for i in range(n)] for i in range(n): for j in range(n): if M[i][j] == -1: M[i][j] = INF d = [INF for i in range(n)] # ??¢?´¢????±? p = [-1 for...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,732
s792868277
p02241
u567281053
1463695377
Python
Python
py
Accepted
50
6456
583
import sys def prim(E): V = [0] for i in range(len(E)): E[i][0] = -1 n = len(E) sum = 0 while len(V) != n: mini, minj, mine = -1, -1, 2001 for i in V: for j in range(len(E[i])): if E[i][j] != -1 and E[i][j] < mine: mini, minj,...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,733
s256022027
p02241
u072053884
1465184201
Python
Python3
py
Accepted
20
7924
649
n = int(input()) adj = [list(map(int, input().split())) for i in range(n)] def prim_mst(vn): isVisited = [False] * vn d = [0] + [2001] * (vn - 1) p = [-1] * vn while True: mincost = 2001 for i in range(vn): if (not isVisited[i]) and (d[i] < mincost): minco...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,734
s342770378
p02241
u027872723
1478441521
Python
Python3
py
Accepted
30
7824
739
# -*- coding: utf_8 -*- level = False def debug(v): if level: print(v) n = int(input()) g = [] for i in range(n): v = input().split() g.append([int(x) for x in v]) debug(g) def prim(n): visited = [False] * n d = [0] + [2001] * (n - 1) p = [-1] * n while True: mincost = ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,735
s993498362
p02241
u890722286
1478646292
Python
Python3
py
Accepted
40
7908
980
def prim(): global M global n global INF color = ['w' for i in range(n)] d = [INF for i in range(n)] d[0] = 0 p = [-1 for i in range(n)] while True: mincost = INF u = -1 for i in range(n): if color[i] != 'b' and d[i] < mincost: mincost...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,736
s747313045
p02241
u022407960
1479714748
Python
Python3
py
Accepted
20
8308
1,213
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys WHITE, GRAY, BLACK = 0, 1, 2 def prim_span_tree(): min_weight_vertices[0] = 0 while True: min_cost = 2001 current_vertex = -1 for i in range(vertices_num): if color[i] != BLACK and min_weight_vertices[i] < min_cost...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,737
s177987977
p02241
u494314211
1481018506
Python
Python3
py
Accepted
30
8300
1,742
a=input() matrix=[] for i in range(int(a)): matrix.append(list(map(int,input().split()))) # ?????????O(n)????????£????????? class union_find(object): """union-find tree""" def __init__(self, length): self.length = length self.unionnumber=0 self.unionlist=[[]] self.num=list(-1 for i in range(length)) ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,738
s712904626
p02241
u159356473
1481264840
Python
Python3
py
Accepted
30
7852
733
#coding:utf-8 def prim(n,G): dist=0 visited=[False]*n cost=[1000000]*n pi=[0]*n cost[0]=0 pi[0]=-1 while True: mincost=1000000 u=0 for i in range(n): if visited[i]==False and cost[i]<mincost: mincost=cost[i] u=i if ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,739
s909200611
p02241
u811733736
1481332430
Python
Python3
py
Accepted
60
8288
2,027
from enum import Enum class Mst(object): """ minimum spanning tree """ INFINITY = 999999999 class Status(Enum): """ ?????????????¨??????¶??? """ white = 1 # ????¨???? gray = 2 # ?¨??????? black = 3 #?¨??????? def __init__(self, data): num_of_nodes = len(data...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,740
s166171600
p02241
u923668099
1486373724
Python
Python3
py
Accepted
80
7944
798
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): n = int(input()) a = [] for i in range(n): a.append([int(j) for j in input().split()]) checked ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,741
s131406114
p02241
u923668099
1486377567
Python
Python3
py
Accepted
20
7988
944
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): inf = float('inf') n = int(input()) a = [] for i in range(n): line = [int(i) for i in input().sp...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,742
s992055592
p02241
u923668099
1486377779
Python
Python3
py
Accepted
30
7872
957
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): inf = float('inf') n = int(input()) a = [] for i in range(n): line = [int(i) for i in input().sp...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,743
s787999177
p02241
u923668099
1486718456
Python
Python3
py
Accepted
20
7804
972
import sys inf = float('inf') def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def prim(n, As): checked = [False] * n d = [inf] * n checked[0] = True d[0] = 0 nxt = 0 to...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,744
s422127556
p02241
u112247126
1488597012
Python
Python3
py
Accepted
30
7932
966
def prim(): distance[0] = 0 parent[0] = -1 while True: mincost = float('inf') for i in range(n): if color[i] != 'black' and distance[i] < mincost: mincost = distance[i] u = i if mincost == float('inf'): break color[u] ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,745
s087672799
p02241
u551083572
1489039287
Python
Python3
py
Accepted
40
8064
904
# coding: utf-8 n = int(input()) ew = [None] * n for i in range(n): ew[i] = list(map(int, input().split())) elist = [] for i in range(n): for j in range(i+1, n): if ew[i][j] > -1: elist.append((ew[i][j], i, j)) class UnionFind(object): def __init__(self, n): self.parent = [i ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,746
s723822222
p02241
u462831976
1490064579
Python
Python3
py
Accepted
30
8368
1,211
# -*- coding: utf-8 -*- """Minimum Spanning Tree""" import sys import os import pprint DEBUG = False #fd = os.open('ALDS1_12_A.txt', os.O_RDONLY) #os.dup2(fd, sys.stdin.fileno()) n = int(input()) # n x n matrix M = [] for i in range(n): l = list(map(int, input().split())) M.append(l) # Prim's Algorithm I...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,747
s287191855
p02241
u603049633
1496536173
Python
Python3
py
Accepted
20
8128
670
n = int(input()) M = [[float("inf") for i in range(n)] for i in range(n)] for i in range(n): L = list(map(int, input().split())) for j,v in enumerate(L): if v != -1: M[i][j] = v def prim(): color = [0] * n d = [float("inf")] * n p = [-1] * n d[0] = 0 while True: minv = float("inf") u = -1 for i in r...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,748
s914885391
p02241
u603049633
1496536961
Python
Python3
py
Accepted
20
8136
583
n = int(input()) M = [[float("inf") for i in range(n)] for i in range(n)] for i in range(n): L = list(map(int, input().split())) for j,v in enumerate(L): if v != -1: M[i][j] = v def prim(): color = [0] * n d = [float("inf")] * n p = [-1] * n d[0] = 0 while True: minv = float("inf") u = -1 for i in r...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,749
s641405088
p02241
u603049633
1496537277
Python
Python3
py
Accepted
20
8092
555
n = int(input()) M = [[float("inf") for i in range(n)] for i in range(n)] for i in range(n): L = list(map(int, input().split())) for j,v in enumerate(L): if v != -1: M[i][j] = v def prim(): color = [0] * n d = [float("inf")] * n d[0] = 0 while True: minv = float("inf") u = -1 for i in range(n): if...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,750
s155295131
p02241
u370086573
1497677188
Python
Python3
py
Accepted
40
7860
728
INF = 9999 def prim(M): n = len(M) color = [0] * n d = [INF] * n d[0] = 0 while True: minv = INF u = -1 for i in range(n): # Black:2 if minv > d[i] and color[i] != 2: u = i minv = d[i] if u == -1: break ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,751
s496292938
p02241
u089830331
1497694793
Python
Python3
py
Accepted
30
7908
407
def solv(G): n = len(G) V = {0:0} new_V = [] cost = 0 while len(new_V) < n: u, e = min(V.items(), key=lambda x:x[1]) V.pop(u) new_V.append(u) cost += e for v, e in enumerate(G[u]): if e < 0 or v == u or v in new_V: continue V[v] = min(V[v], e) if v in V else e return cost ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,752
s230101754
p02241
u426534722
1499960745
Python
Python3
py
Accepted
30
7916
753
from sys import stdin INF = 1<<21 WHITE = 0 GRAY = 1 BLACK = 2 n = int(stdin.readline()) M = [[INF] * (n + 1) for _ in range(n + 1)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 t = [-1] * n color = [0] * n def prim(): ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,753
s340137083
p02241
u426534722
1499961562
Python
Python3
py
Accepted
20
7988
673
from sys import stdin INF = 1<<21 WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,754
s658478414
p02241
u426534722
1499961646
Python
Python3
py
Accepted
30
7872
680
from sys import stdin INF = float('inf') WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,755
s197853134
p02241
u426534722
1499961664
Python
Python3
py
Accepted
20
7860
673
from sys import stdin INF = 1<<21 WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [0] * n def prim(): while True: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,756
s935117504
p02241
u426534722
1499962081
Python
Python3
py
Accepted
20
7824
674
from sys import stdin INF = 1<<21 WHITE, GRAY, BLACK = 0, 1, 2 n = int(stdin.readline()) M = [[INF] * n for _ in range(n)] for i in range(0, n): for j, e in enumerate(list(map(int, stdin.readline().split()))): if e != -1: M[i][j] = e d = [INF] * n d[0] = 0 color = [False] * n def prim(): while True: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,757
s678616845
p02241
u278938795
1501220592
Python
Python
py
Accepted
10
6768
924
import sys from operator import add n = int(sys.stdin.readline().strip()) A = [ [0] for i in range(n)] for i in range(n): temp = map(int ,sys.stdin.readline().strip().split(" ")) A[i] = temp weight = [None for i in range(n)] mitayatu=[False for i in range(n)] def min(array): temp = 100000 index= 0 for i in ran...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,758
s866720650
p02241
u510829608
1502885119
Python
Python3
py
Accepted
50
9620
1,302
import array import collections import heapq INF = 1e9 N = int(input()) AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost') adjacency_list = collections.defaultdict(set) NO_VERTEX = -1 def compute_mst_prim(max_v, adj_list): pred = collections.defaultdict(lambda: NO_VERTEX) key = colle...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,759
s178618514
p02241
u510829608
1502888654
Python
Python3
py
Accepted
30
7952
719
INF = 1e9 n = int(input()) adj_matrix = [list(map(int, input().split())) for i in range(n)] def prim(x): isVisited = [False] * x d = [INF] * x d[0] = 0 p = [-1] * x while True: min_cost = INF for i in range(x): if isVisited[i] != True and d[i] < min_cos...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,760
s996223683
p02241
u491916705
1502983814
Python
Python
py
Accepted
10
6416
713
n = int(raw_input()) a = [] for i in range(n): a.append(map(int, raw_input().split())) def prim(a): color = ['white' for i in range(n)] d = [10**9 for i in range(n)] p = [-1 for i in range(n)] d[0] = 0 while True: mincost = 10**9 for i in range(n): if color[i] != 'bla...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,761
s959831310
p02241
u855199458
1503049077
Python
Python3
py
Accepted
60
7876
516
# -*- coding: utf-8 -*- from itertools import product N = int(input()) INF = float("inf") adj = [] for _ in range(N): adj.append([int(n) if n != "-1" else float("inf") for n in input().split()]) not_MST = list(range(1, N)) MST = [0] cost = 0 while len(not_MST): tmp_min = INF tmp_idx = -1 for m, n in...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,762
s510049835
p02241
u881590806
1503579550
Python
Python
py
Accepted
10
6952
802
from heapq import heappush, heappop def prim(G): n = len(G) heap = [] s = 0 for v, c in G[s].items(): heappush(heap, (c, v)) added = set() added.add(s) cost = 0 while len(added) < n: cu, u = heappop(heap) if u in added: continue added.add(u) ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,763
s160529064
p02241
u519227872
1505130799
Python
Python3
py
Accepted
70
7992
516
v = int(input()) G= [[int(i) for i in input().split()] for i in range(v)] def prim(G, v): Vn = set([1]) En = set([]) V = set(range(1, v+1)) while Vn != V: m = float('inf') for u in Vn: for v in V - Vn: if G[u - 1][v - 1] == -1:continue ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,764
s523292897
p02241
u796784914
1506758143
Python
Python
py
Accepted
10
6564
785
def main(): n = input() A = [] for i in xrange(n): A.append(map(int,raw_input().split())) inf = float('inf') d = [inf]*n p = [-1]*n c = [-1]*n d[0] = 0 while(True): mincost = inf for i in xrange(n): if(c[i] != 1) & (d[i] < mincost): ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,765
s112881569
p02241
u798803522
1509876887
Python
Python3
py
Accepted
30
8724
659
import heapq from collections import defaultdict v_num = int(input()) edges = defaultdict(list) for i in range(v_num): data = [int(n) for n in input().split(" ")[1:]] for j in range(i + 1, v_num): if data[j] != -1: edges[i].append([data[j], j]) edges[j].append([data[j], i]) queue...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,766
s706164222
p02241
u798803522
1509877346
Python
Python3
py
Accepted
50
8812
695
import heapq from collections import defaultdict v_num = int(input()) edges = defaultdict(list) for i in range(v_num): data = [int(n) for n in input().split(" ")[1:]] for j in range(i + 1, v_num): if data[j] != -1: edges[i].append([data[j], j]) edges[j].append([data[j], i]) queue...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,767
s383063200
p02241
u798803522
1509877370
Python
Python3
py
Accepted
70
9064
659
import heapq from collections import defaultdict v_num = int(input()) edges = defaultdict(list) for i in range(v_num): data = [int(n) for n in input().split(" ")[1:]] for j in range(i + 1, v_num): if data[j] != -1: edges[i].append([data[j], j]) edges[j].append([data[j], i]) queue...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,768
s874278442
p02241
u798803522
1509877395
Python
Python3
py
Accepted
30
8740
695
import heapq from collections import defaultdict v_num = int(input()) edges = defaultdict(list) for i in range(v_num): data = [int(n) for n in input().split(" ")[1:]] for j in range(i + 1, v_num): if data[j] != -1: edges[i].append([data[j], j]) edges[j].append([data[j], i]) queue...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,769
s089812771
p02241
u845643816
1511962985
Python
Python3
py
Accepted
40
6292
629
n = int(input()) edgeArray = [list(map(int, input().split())) for i in range(n)] edgeList = [] rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] for i in range(n): ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,770
s396024342
p02241
u845643816
1511963128
Python
Python3
py
Accepted
20
6116
584
n = int(input()) edgeList = [] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] != -1: edgeList.append([a[j], i, j]) rootList = [-1 for i in range(n)] sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,771
s029476324
p02241
u845643816
1511963585
Python
Python3
py
Accepted
30
5864
601
n = int(input()) edgeList = [] rootList = [-1 for i in range(n)] def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x] = getRoot(r) return rootList[x] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,772
s596958893
p02241
u845643816
1511963663
Python
Python3
py
Accepted
20
6116
568
n = int(input()) edgeList = [] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] != -1: edgeList.append([a[j], i, j]) rootList = [-1]*n sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,773
s701818625
p02241
u845643816
1511963772
Python
Python3
py
Accepted
30
6120
568
n = int(input()) edgeList = [] for i in range(n): a = list(map(int, input().split())) for j in range(i): if a[j] != -1: edgeList.append([a[j], i, j]) rootList = [-1]*n sumLength = 0 def getRoot(x): r = rootList[x] if r < 0: rootList[x] = x elif r != x: rootList[x...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,774
s418379928
p02241
u626266743
1511965599
Python
Python3
py
Accepted
30
5904
907
INFTY = 1 << 21 WHITE = 0 GRAY = 1 BLACK = 2 n = int(input()) M = [list(map(int, input().split())) for i in range(n)] d = [INFTY for i in range(n)] p = [-1 for i in range(n)] color = [WHITE for i in range(n)] for i in range(n): for j in range(n): if (M[i][j] == -1): M[i][j] = INFTY def prim(...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,775
s564170513
p02241
u236679854
1511994436
Python
Python3
py
Accepted
20
5892
648
inf = float('inf') n = int(input()) a = [] for i in range(n): line = list(map(int, input().split())) for i in range(len(line)): if line[i] == -1: # infinity weight if not connected line[i] = inf a.append(line) checked = [False] * n d = [inf] * n checked[0] = True ans = 0 nx...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,776
s617604920
p02241
u957470671
1512489468
Python
Python3
py
Accepted
60
5980
464
import itertools n = int(input()) A = [] for i in range(n): line = input() A.append([int(x) for x in line.split()]) V = set(range(n)) Vnew = {0} # ??¨???????°???¨????????? weights = [] while V != Vnew: T = V - Vnew minw = float('inf') for u, v in itertools.product(Vnew, T): w = A[u][v] ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,777
s335513234
p02241
u662418022
1518340063
Python
Python3
py
Accepted
20
5868
900
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) M = [list(map(int, input().split(" ")[1:])) for _ in range(n)] color = [0] * n d = [float("inf")] * n p = [None] * n def prim(): d[0] = 0 p[0] = -1 while True: mincost = float("inf") ...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,778
s270215431
p02241
u426534722
1519316962
Python
Python3
py
Accepted
20
5768
828
INF = float("inf") def MAIN(): n = int(input()) M = [[INF] * 101 for _ in range(101)] for i in range(n): for j, e in enumerate(map(int, input().split())): if e != -1: M[i][j] = e def prim(): d = [INF] * n t = [-1] * n color = [0] * n d[...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,779
s325801976
p02241
u150984829
1520391304
Python
Python3
py
Accepted
30
5908
322
n=int(input()) M=[list(map(int,input().split()))for _ in[0]*n] d=[0]+[1e4]*~-n p=[-1]*n b=[1]*n while 1: m,u=1e4,-1 for i in range(n): if m>d[i]and b[i]:m,u=d[i],i if u<0:break b[u]=0 for v in range(n): if b[v]and 1+M[u][v]and d[v]>M[u][v]: d[v],p[v]=M[u][v],u print(sum(M[i][p[i]]for i in range(n)if p[i]+1)...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,780
s311924162
p02241
u150984829
1520391306
Python
Python3
py
Accepted
30
5900
322
n=int(input()) M=[list(map(int,input().split()))for _ in[0]*n] d=[0]+[1e4]*~-n p=[-1]*n b=[1]*n while 1: m,u=1e4,-1 for i in range(n): if m>d[i]and b[i]:m,u=d[i],i if u<0:break b[u]=0 for v in range(n): if b[v]and 1+M[u][v]and d[v]>M[u][v]: d[v],p[v]=M[u][v],u print(sum(M[i][p[i]]for i in range(n)if p[i]+1)...
p02241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Minimum Spanning Tree</H1> ...
5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1
5
29,781