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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s596479305 | p02241 | u150984829 | 1520391309 | Python | Python3 | py | Accepted | 20 | 5904 | 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,782 |
s792030580 | p02241 | u150984829 | 1520392757 | Python | Python3 | py | Accepted | 20 | 5900 | 260 | 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,783 |
s700615267 | p02241 | u150984829 | 1520393806 | Python | Python3 | py | Accepted | 20 | 5984 | 437 | n=int(input())
edgeList=[]
for i in range(n):
a=list(map(int,input().split()))
for j in range(i):
if a[j]>=0:edgeList+=[(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]=getRoot(r)
return rootList[x]
edgeList.sort(key=lambda x:x[0])
for e in edgeLis... | 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,784 |
s143441361 | p02241 | u150984829 | 1520415817 | Python | Python3 | py | Accepted | 20 | 5900 | 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,785 |
s112092851 | p02241 | u912143677 | 1522320856 | Python | Python3 | py | Accepted | 20 | 5880 | 473 | n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
ans = 0
mincost = [2001] * n
flag = [0] * n
mincost[0] = 0
while 1:
v = -1
for j in range(n):
if flag[j] != 1 and (v == -1 or mincost[j] < mincost[v]):
v = j
if v == -1:
break
flag[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,786 |
s849833357 | p02241 | u912143677 | 1522322957 | Python | Python3 | py | Accepted | 20 | 5904 | 643 | INF = 1e9
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
def prim(n):
flag = [0] * n
d = [INF] * n
d[0] = 0
p = [-1] * n
while True:
min_cost = INF
for i in range(n):
if flag[i] != 1 and d[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,787 |
s250031954 | p02241 | u126478680 | 1525872260 | Python | Python3 | py | Accepted | 40 | 6576 | 1,024 | from enum import Enum, auto
class Color(Enum):
WHITE = auto()
GRAY = auto()
BLACK = auto()
n = int(input())
M = []
for i in range(n):
arr = [int(x) for x in input().split(' ') if x != '']
M.append(arr)
colors = []
d = []
p = [0 for i in range(n)]
INFTY = 2001
def prim():
global d
colors = ... | 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,788 |
s944866423 | p02241 | u269391636 | 1528040634 | Python | Python3 | py | Accepted | 50 | 6252 | 558 | n = int(input())
sides = []
ws = []
ss = []
for _ in range(n):
sides.append(list(map(int,input().split())))
for i in range(n):
for j in range(i+1,n):
if sides[i][j] >= 0:
ws.append([sides[i][j],i,j])
rs = [(i) for i in range(n)]
def root(x):
global rs
if rs[x] == x:
return(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,789 |
s307183244 | p02241 | u404682284 | 1528858963 | Python | Python3 | py | Accepted | 20 | 5980 | 800 | import sys
INF = float('inf')
n = int(input())
adja_matrix = [[int(i) for i in line.split()] for line in sys.stdin.read().splitlines()]
condition = ['INIT'] * n
distance = [INF] * n
p = [0] * n
distance[0] = 0
p[0] = -1
while True:
mincost = INF
for i in range(n):
if condition[i] != 'FINISH' and distan... | 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,790 |
s180656027 | p02241 | u089116225 | 1529057758 | Python | Python3 | py | Accepted | 30 | 6196 | 822 | n = int(input())
m = []
for _ in range(n):
tmp = [int(x) for x in input().split()]
m.append(tmp)
#辺を全て持つリストを作る
edge_list = []
j = 1
for i in range(n-1):
for k,x in enumerate(m[i][j:]):
if x != -1:
edge_list.append((x,i,k+j))
else:
pass
j += 1
edge_list.sort()
... | 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,791 |
s482051858 | p02241 | u023997525 | 1529747528 | Python | Python3 | py | Accepted | 30 | 6144 | 1,567 | #!/usr/bin/env python3
# Union find
class UnionFind:
def __init__(self, N):
self.N = N
self.parent = list(range(N))
def root(self, x):
path_to_root = []
while self.parent[x] != x:
path_to_root.append(x)
x = self.parent[x]
for node in path_to_roo... | 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,792 |
s456378817 | p02241 | u088372268 | 1529753186 | Python | Python3 | py | Accepted | 20 | 5728 | 940 | n = int(input())
INF = 2147483647
G = [[INF for j in range(n)] for i in range(n+1)]
check = [0 for i in range(n)]
def prim():
d = [INF for i in range(n)]
p = [-1 for i in range(n)]
d[0] = 0
cost = 0
while True:
min_cost = INF
for i in range(n):
if check[i] != 2 and 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,793 |
s859319077 | p02241 | u318430977 | 1530031154 | Python | Python3 | py | Accepted | 20 | 6672 | 2,111 | class UnionFindTree:
"""
Disjoint set data structure
Union-Find tree
complexity:
init: O(n)
find, unite, same: O(alpha(n))
"""
def __init__(self, n):
self.par = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.par[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,794 |
s935668037 | p02241 | u007270338 | 1530255872 | Python | Python3 | py | Accepted | 30 | 5868 | 817 | #coding:utf-8
inf = 1000000
n = int(input())
mtrx = []
for i in range(n):
nums = list(map(int,input().split()))
col = []
for j in range(n):
if nums[j] == -1:
col.append(inf)
else:
col.append(nums[j])
mtrx.append(col)
d = [inf for i in range(n)]
p = [-1 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,795 |
s614260568 | p02241 | u912237403 | 1376577376 | Python | Python | py | Accepted | 50 | 6000 | 899 | 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,796 |
s051648763 | p02241 | u782850731 | 1380757979 | Python | Python | py | Accepted | 40 | 4520 | 646 | #!/usr/bin/env python
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}
grav... | 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,797 |
s007434188 | p02241 | u782850731 | 1380759263 | Python | Python | py | Accepted | 40 | 4520 | 643 | #!/usr/bin/env python
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}
weig... | 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,798 |
s781761806 | p02241 | u733357255 | 1597764245 | Python | Python3 | py | Accepted | 30 | 6660 | 732 | from heapq import heappush, heappop, heapify
n = int(input())
g = [[] for _ in range(n)]
for i in range(n):
for j,k in enumerate(map(int,input().split())):
if k != -1:
g[i].append((j,k))
# print(g[i])
ocupied = [0]*n
que = [(j,k) for k,j in g[0]] # 重み、子の順番
#print(f'g[0]: {g[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,799 |
s493454919 | p02241 | u880802684 | 1597565470 | Python | Python3 | py | Accepted | 30 | 6292 | 1,904 | class UnionFind:
def __init__(self, n: int):
self.nodes = n
self.parents = [-1] * n
self.rank = [0] * n
# retrun the root of element x
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[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,800 |
s678512324 | p02241 | u793520502 | 1597051265 | Python | Python3 | py | Accepted | 20 | 5988 | 1,009 | from sys import stdin
input = stdin.readline
import heapq
def prim(N):
d[1] = 0
p[1] = -1
u = 1
while True:
mincost = 3000
for i in range(1, N+1):
if color[i] != 2 and d[i] < mincost:
mincost = d[i]
u = i
if mincost == 3000:
... | 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,801 |
s787525557 | p02241 | u914515588 | 1597032982 | Python | Python3 | py | Accepted | 70 | 7924 | 1,828 | import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = ... | 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,802 |
s892776443 | p02241 | u434132766 | 1595775457 | Python | Python3 | py | Accepted | 20 | 5956 | 832 | def prim():
visited = [0]*n
d = [float("inf")]*n
p = [-1]*n
d[0] = 0
while True:
mincost = float("inf")
for i in range(n):
if visited[i] != 2 and d[i] < mincost:
mincost = d[i]
u = i
if mincost == float("inf"):
br... | 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,803 |
s827085637 | p02241 | u748843150 | 1594729319 | Python | Python3 | py | Accepted | 20 | 5772 | 800 | n=int(input())
inf=10000
color=["white" for i in range(n)]
p=[-1 for i in range(n)]
d=[inf for i in range(n)]
M=[[] for i in range(n)]
for i in range(n):
tmp=list(map(int,input().split()))
for j in range(n):
if tmp[j]==-1:
M[i].append(inf)
else:
M[i].append(tmp[j])
def... | 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,804 |
s204753495 | p02241 | u450519077 | 1594448312 | Python | Python3 | py | Accepted | 20 | 5884 | 553 | n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
isVisited = [False] * n
d = [0] + [2001] * (n - 1)
p = [-1] * n
while True:
mincost = 2001
for i in range(n):
if (not isVisited[i]) and (d[i] < mincost):
mincost = d[i]
u = i
if mincost == 2001:
... | 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,805 |
s745744003 | p02241 | u878424017 | 1594259260 | Python | Python3 | py | Accepted | 20 | 5900 | 788 | def prim(n,M):
d = [None]*n
p = [None]*n
searched = [0]*n
for i in range(n):
d[i] = float("inf")
p[i] = -1
d[0] = 0
while True:
minv = float("inf")
u = -1
for i in range(n):
if minv > d[i] and not searched[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,806 |
s532688952 | p02241 | u951519498 | 1594195674 | Python | Python3 | py | Accepted | 20 | 5892 | 670 | def prim(n, cost):
mincost = [float("inf")]*n
used = [False] * n
mincost[0] = 0
res = 0
cnt = 1
while True:
u = -1
for i in range(n):
if (not used[i]) and (u == -1 or mincost[i] < mincost[u]):
u = i
if u == -1:
break
used[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,807 |
s266982704 | p02241 | u913305001 | 1592214804 | Python | Python3 | py | Accepted | 30 | 6552 | 1,043 | N = int(input())
P = [i for i in range(N)]
weight = []
def root(x):
path_to_root = []
while P[x] != x:
path_to_root.append(x)
x = P[x]
for node in path_to_root:
P[node] = x
return x
def is_same_set(x,y):
return root(x) == root(y)
def unite(x,y):
P[root(x)] = root(y)
... | 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,808 |
s029105112 | p02241 | u742290340 | 1592213700 | Python | Python3 | py | Accepted | 20 | 5992 | 590 | def root(x):
path_to_root = []
while P[x] != x:
path_to_root.append(x)
x = P[x]
for node in path_to_root:
P[node] = x
return x
def is_same_set(x,y):
return root(x) == root(y)
def unite(x,y):
P[root(x)] = root(y)
n= int(input())
a=[]
P=[i for i in range(n)]
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,809 |
s412547125 | p02241 | u515473089 | 1592212883 | Python | Python3 | py | Accepted | 20 | 6136 | 521 | n=int(input())
ds=[i for i in range(n)]
def root(x):
path_to_root = []
while ds[x] != x:
path_to_root.append(x)
x = ds[x]
for i in path_to_root:
ds[i] = x
return x
def same(x,y):
return root(x) == root(y)
def unite(x,y):
ds[root(x)] = root(y)
p=[] #[a,i,j]:i<j
for i in range(n):
a=list(map(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,810 |
s585903845 | p02241 | u903393228 | 1592212164 | Python | Python3 | py | Accepted | 20 | 5984 | 613 | N = int(input())
ep = []
for i in range (N):
a = list(map(int,input().strip().split()))
for j in range(i,N):
if a[j] != -1:
ep.append([a[j],i,j])
P = [i for i in range(N)]
def root(x):
path_to_root = []
while P[x] != x:
path_to_root.append(x)
x = P[x]
for node 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,811 |
s217804974 | p02241 | u647214684 | 1592211710 | Python | Python3 | py | Accepted | 30 | 5908 | 576 | n = int(input())
edge = []
for i in range(n):
a = list(map(int, input().split()))
for j in range(i + 1, n):
if a[j] != -1:
edge.append((a[j], i, j))
edge.sort()
ans = 0
tree = [i for i in range(n)]
def root(x):
pre = []
while x != tree[x]:
pre.append(x)
x = tree[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,812 |
s062681443 | p02241 | u512884261 | 1591877309 | Python | Python3 | py | Accepted | 40 | 6916 | 1,469 | import sys, collections
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return ... | 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,813 |
s962259729 | p02241 | u800829827 | 1591453458 | Python | Python3 | py | Accepted | 20 | 5892 | 1,413 | import sys
def readinput():
n=int(input())
nMat=[]
for _ in range(n):
m=list(map(int,input().split()))
nMat.append(m)
return n,nMat
WHITE=0
GRAY=1
BLACK=2
INFTY=sys.maxsize
def prim(n,nMat):
color=[WHITE]*n
d=[INFTY]*n
p=[-1]*n
d[0]=0
p[0]=-1
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,814 |
s798971462 | p02241 | u153034461 | 1591415449 | Python | Python3 | py | Accepted | 40 | 6828 | 1,136 | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import decimal
INF = 10**18
WHITE = 0
GRAY = 1
BLACK = 2
def Prim():
d = [INF]*(n)
c = [WHITE]*(n)
p = [-1]*(n)
d[0] = 0
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,815 |
s054733172 | p02241 | u900107726 | 1590821511 | Python | Python3 | py | Accepted | 20 | 6476 | 835 | import sys
import heapq
def main():
n = int(input())
next = []
for _ in range(n):
l = list(map(int, input().split()))
next.append([(c, i) for i, c in enumerate(l) if c != -1])
visited = [0] * n
connection = 0
q = [(0, 0)] # (cost, v)
heapq.heapify(q)
ans = 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,816 |
s628803096 | p02241 | u784856415 | 1590736687 | Python | Python3 | py | Accepted | 30 | 6480 | 1,202 | import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
class union_find():
def __init__(self,n):
self.n=n
self.root=[-1]*(n+1)
self.rank=[0]*(n+1)
def find_root(self,x):
if self.root[x]<0:
return x
else:
self.root[x]=self.find_root... | 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,817 |
s379502734 | p02241 | u119355204 | 1590711774 | Python | Python3 | py | Accepted | 20 | 5888 | 968 | N = int(input())
#M[u][v]:uからvへの重みを保存した隣接行列
M=[]
for n in range(N):
input_temp = list(map(int,input().split()))
M.append(input_temp)
#color:各頂点の訪問状態を示す
color=['white']*N
#d:TとV-Tを繋ぐ辺の中で重みが最小の辺の重みの値を保持
d=[10**10]*N
#p[v-1]:MSTにおけるvの親を保持
p=[-1]*N
#初期値
d[0] = 0
p[0] = -1
# ans=0
while True:
# ans+=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,818 |
s962009804 | p02241 | u798363880 | 1590222302 | Python | Python3 | py | Accepted | 20 | 5888 | 644 | N=int(input())
graph=[]
d=[2000]*(N)
p=[None]*(N)
color=["white"]*(N+1)
for i in range(N):
a=list(map(int,input().split()))
graph.append(a)
def prim():
d[0]=0
p[0]=-1
while (True):
mincost=2000
for i in range(N):
if color[i]!="black" and d[i]<mincost:
minc... | 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,819 |
s952233584 | p02241 | u781474375 | 1589845244 | Python | Python3 | py | Accepted | 30 | 6360 | 1,100 | import heapq
def make_adj_list(v):
adj_list = [[-1 for i in range(v)] for j in range(v)]
return adj_list
def prim(adj_list, v, s):
# スタートを0とする
min_d = 0
heap = []
used = []
for i in range(v):
used.append(False)
used[s] = True
for i in range(v):
if adj_list[s][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,820 |
s182215929 | p02241 | u483082413 | 1589747307 | Python | Python3 | py | Accepted | 40 | 5776 | 900 | n = int(input())
inf = float('inf')
graphs = []
for i in range(n):
weights = list(map(int, input().split()))
weights = [inf if weight == -1 else weight for weight in weights]
graphs.append(weights)
# print(graphs)
# M =graphs
color = ['WHITE' for _ in range(n)]
d = [inf for _ in range(n)]
p = [i 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,821 |
s523192940 | p02241 | u590535211 | 1589464045 | Python | Python3 | py | Accepted | 20 | 6212 | 540 | import heapq
n = int(input())
M = [list(map(int,input().split())) for _ in range(n)]
q = []
visited = [False]*n
adjs = []
sum_cost = 0
node = 0
visited[node] = True
cnt = 1
while 1:
for i in range(n):
if M[node][i] != -1 and visited[i] == False:
heapq.heappush(q, (M[node][i], i))
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,822 |
s611563661 | p02241 | u176870835 | 1588820633 | Python | Python3 | py | Accepted | 30 | 6596 | 949 | #!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split()) for _ 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,823 |
s046772835 | p02241 | u720435112 | 1588411193 | Python | Python3 | py | Accepted | 20 | 5896 | 869 | n = int(input())
G = [list(map(int, input().split())) for _ in range(n)]
color = ['White']*n
d = [10**6]*n # 移動コスト
d[0] = 0 # 0にはコストゼロ
p = [-1]*n # 親ノード
p[0] = -1 # 0には親なし
def prim():
while True:
mincost = 10**6
u = -1
# 最小コストを選ぶ
for i in range(n):
if color[i] != 'Black... | 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,824 |
s435543043 | p02241 | u486183171 | 1588396872 | Python | Python3 | py | Accepted | 20 | 5904 | 602 | INF = float('inf')
N = int(input())
M = []
D = []
P = []
visited = []
for i in range(N):
M.append([a if a != -1 else INF for a in map(int, input().split())])
D.append(INF)
P.append(-1)
visited.append(False)
D[0] = 0
P[0] = None
while True:
min_cost = INF
u = -1
for i in range(N):
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,825 |
s568251710 | p02241 | u940492895 | 1588020433 | Python | Python3 | py | Accepted | 20 | 5776 | 787 | # 最小全域木 Minumum spannin tree
MAX_EDGE_COST = 2001
n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
A[i] = [int(i) for i in input().split()]
col = [-1 for i in range(n)]
d = [MAX_EDGE_COST for i in range(n)]
p = [-1 for i in range(n)]
d[0] = 0
while True:
mincost = MAX_EDGE_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,826 |
s430449917 | p02241 | u132112086 | 1587193702 | Python | Python3 | py | Accepted | 20 | 6260 | 1,950 | def main():
n = int(input())
a_list = [list(map(int, input().split())) for _ in [0]*n]
abc = []
for i in range(n):
for j in range(i+1, n):
if a_list[i][j] > -1:
abc.append((i, j, a_list[i][j]))
def Kruskal(n, abc, weight=True):
class unionfind():
... | 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,827 |
s797319746 | p02241 | u259225866 | 1587178787 | Python | Python3 | py | Accepted | 20 | 5836 | 1,503 | #0オリジンで行うので注意
import sys
input = sys.stdin.buffer.readline
INF = 10 ** 9
#隣接行列
n = int(input())
G = []
for _ in range(n):
G.append(list(map(int, input().split())))
for i in range(n):
for j in range(n):
if G[i][j] == -1:
G[i][j] = INF
#到着してない:white, 到着後:gray, 確定:black
white, gray, black =... | 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,828 |
s607970756 | p02241 | u258049727 | 1586676993 | Python | Python3 | py | Accepted | 20 | 5908 | 1,252 | def prim():
mindist[0] = 0
parent[0] = -1
while True:
#MSTに追加する頂点を決定
mincost = INF
u = -1
for i in range(n):
if color[i] != black and mindist[i] < mincost:
mincost = mindist[i]
u = i
if u == -1: break
color[u] = bl... | 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,829 |
s883040663 | p02241 | u146816547 | 1586467044 | Python | Python3 | py | Accepted | 40 | 8032 | 758 | import heapq
def prim(G):
n = len(G)
is_visited = [False for _ in range(n)]
que = []
heapq.heappush(que, (0, 0))
ret = 0
while que:
cost, cur_v = heapq.heappop(que)
if is_visited[cur_v]:
continue
is_visited[cur_v] = True
ret += cost
for (ad... | 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,830 |
s255375516 | p02241 | u820842907 | 1585976905 | Python | Python3 | py | Accepted | 20 | 5892 | 955 | def minimum_spanning_tree(adj_mat, cost, color, parent):
N = len(cost)
cost[0] = 0
parent[0] = -1
while True:
mincost = 2000000
for i in range(N):
if color[i] != "B" and cost[i] < mincost:
mincost = cost[i]
cur = i
if mincost == 2000... | 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,831 |
s173249233 | p02241 | u737337423 | 1585755066 | Python | Python3 | py | Accepted | 100 | 6508 | 393 | # Minimum Spanning Tree
INF = 10**5
N, *W = map(int, open(0).read().split())
W = tuple(zip(*[iter(INF if w < 0 else w for w in W)]*N))
S = set([0])
ans = 0
while len(S) < N:
min_w = INF
u = -1
for v in S:
for j, w in enumerate(W[v]):
if j not in S and w < min_w:
min_w =... | 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,832 |
s839858194 | p02241 | u838900850 | 1585666139 | Python | Python3 | py | Accepted | 20 | 6356 | 769 |
import heapq
def main():
INF = 1000000009
n = int(input())
e = [[] for _ in range(n)]
for i in range(n):
inf = list(map(int,input().split()))
for j in range(n):
if inf[j]!=-1:e[i].append([j,inf[j]])
dp = [INF]*n
finished = [False]*n
dp[0] = 0
pq = [[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,833 |
s355058710 | p02241 | u577681189 | 1585469485 | Python | Python3 | py | Accepted | 70 | 9100 | 1,359 | import queue
INFTY=1<<21
#プリム法
def prim(n,EdgeMatrix):
EdgeList=queue.PriorityQueue() #探索対象の辺
used=[False]*n #頂点の使用情報
used[0]=True #0から探索を始める
LastNode=0 #最新の頂点
count=1 #つないだ頂点の数
EdgeSum=0 #重みの合計
while count<n:
for i in range(len(EdgeMatrix[LastNode])):
#探索していない頂点へ辺が... | 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,834 |
s831204878 | p02241 | u230072054 | 1585061417 | Python | Python3 | py | Accepted | 30 | 6652 | 499 | N = int(input())
G = [[] for i in range(N)]
for v in range(N):
for w, c in enumerate(map(int, input().split())):
if c != -1:
G[v].append((w, c))
from heapq import heappush, heappop, heapify
used = [0]*N
que = [(c, w) for w, c in G[0]]
used[0] = 1
heapify(que)
ans = 0
while que:
cv, v = hea... | 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,835 |
s382503234 | p02241 | u217435805 | 1584405207 | Python | Python3 | py | Accepted | 20 | 5896 | 883 | import sys
# sys.stdin = open('input.txt')
def createMatrix():
matrix = [[i for i in map(int, input().split())] for i in range(n)]
return matrix
def prim():
d[0] = 0
p[0] = -1
while True:
mincost = INFTY
for i in range(n):
if status[i] != VISITED and 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,836 |
s190588517 | p02241 | u327242612 | 1584060693 | Python | Python3 | py | Accepted | 20 | 5764 | 1,116 | from sys import stdin
input = stdin.readline
INFTY = 2**21
WHITE = 0
GRAY = 1
BLACK = 2
n = int(input())
M = [[0]*n for _ in range(n)]
for i in range(n):
ee = map(int, input().split())
for j, e in enumerate(ee): # 先に1行分読み込んでから、eにわける
if e == -1:
M[i][j] = INFTY
else:
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,837 |
s995163501 | p02241 | u925219592 | 1583915548 | Python | Python3 | py | Accepted | 30 | 5908 | 784 | def prim():
INFTY = float('inf')
color = ['WHITE' for _ in range(n)]
d = [INFTY for _ in range(n)]
p = [None for _ in range(n)]
d[0] = 0
p[0] = -1
while True:
mincost = INFTY
for i in range(n):
if color[i] != 'BLACK' 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,838 |
s046070656 | p02241 | u357050809 | 1583748071 | Python | Python3 | py | Accepted | 60 | 7148 | 1,559 | class UnionFind:
def __init__(self, v):
# number of vertices
self.v = v
# parents of each node
self.parents = [None] * v
# heights of each node
self.height = [None] * v
def init(self):
for i in range(self.v):
self.parents[i] = i
self.height[i] = 0
def find(self, p):
#... | 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,839 |
s910341145 | p02241 | u209037521 | 1582042004 | Python | Python3 | py | Accepted | 20 | 5892 | 900 | n = int(input())
primINF = 2000000000
matrix = []
numV = n
for i in range(n):
matrix.append(list(map(int, input().split())))
visited = [False] * numV
cost = [primINF] * numV # cost
parent = [-1] * numV # parent node
cost[0] = 0
parent[0] = -1
while True:
# 訪問済み隣接の最小コストのノードを探索する
mincost = primINF
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,840 |
s475584685 | p02241 | u078455793 | 1581753989 | Python | Python3 | py | Accepted | 20 | 6012 | 598 | # input
n = int(input())
A = []
for _ in range(n):
A.append(list(map(int, input().split())))
# 変数定義
inf = 100 * 2000 + 1
M = A.copy()
M = [[a if a > -1 else inf for a in line] for line in M]
d = [inf] * n
V = set([i for i in range(n)])
T = set()
# 探索
start = 0
target = start
d[target] = 0
T.add(target)
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,841 |
s194855752 | p02241 | u647694976 | 1580827355 | Python | Python3 | py | Accepted | 20 | 5784 | 837 | def prim(n):
inf=float("inf")
D=[inf for i in range(n)]
P=[0 for i in range(n)]
M=[[inf for i in range(n)] for j in range(n)]
color=["white" for i in range(n)]
P[0]=-1
D[0]=0
for i in range(n):
for j,num in enumerate(list(map(int,input().split()))):
if num!=-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,842 |
s180814573 | p02241 | u369455271 | 1580221471 | Python | Python3 | py | Accepted | 20 | 6056 | 969 | inf = float("inf")
class Node():
def __init__(self, _id):
self.id = _id
self.d = inf
self.pi = None
self.color = 0
def input_data(self):
data = [int(i) for i in input().split()]
self.adj = {G[i]: d
for i, d in enumerate(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,843 |
s970327444 | p02241 | u299931928 | 1580191748 | Python | Python3 | py | Accepted | 30 | 6716 | 1,462 | # -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''
# ライブラリのインポート
#import re #正規表現
import sys
#import heapq
import bisect
#import collections
#import math
def main():
n = int(input())
X = [[] for i in range(n)]
l = []
for i, line in enumerate(sys.stdin):
X[i] = list(line.strip("\n").split())
... | 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,844 |
s931139143 | p02241 | u894062759 | 1578280259 | Python | Python3 | py | Accepted | 60 | 6096 | 877 | from collections import deque
class Node:
def __init__(self, val):
self.val = val
self.child = []
n = int(input())
g = []
# mst = [[] for _ in range(n)]
# mst = [None for _ in range(n)]
for i in range(n):
g.append(list(map(int, input().split())))
# print(g)
for i in range(n):
for j 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,845 |
s277723550 | p02241 | u529459816 | 1577547072 | Python | Python3 | py | Accepted | 30 | 5920 | 1,485 | # minimum_spanning_tree
def prim(adj_matrix, n):
dist = [float("inf") for _ in range(n)] # 訪問確定したノードからの最短距離
visited = [False for _ in range(n)] # ノードの訪問が確定したか
parent = [-1 for _ in range(n)] # start -> endを保存するためのstart?
cost = 0
inf = float("inf")
start = 0
visited[start] = True
dist... | 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,846 |
s248302303 | p02241 | u123563150 | 1576662630 | Python | Python3 | py | Accepted | 30 | 6624 | 431 | M=[]
n=int(input())
for i in range(n):
b=list(map(int,input().split()))
M.append(b)
ans=0
from copy import copy
t=[0]
dis=copy(M[0])
dis[0]=10**12
for i in range(n):
if dis[i]==-1:
dis[i]=10**10
for i in range(n-1):
p=10**10
for j in range(n):
if dis[j]<p:
p=dis[j]
q=j
ans+=p
t.append(q)
dis[q]=10**12... | 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,847 |
s844747768 | p02241 | u794140916 | 1575957540 | Python | Python3 | py | Accepted | 20 | 5772 | 877 |
WHITE = 0
GRAY = 1
BLACK = 2
INF = 2000000000
def prim():
d[0] = 0
p[0] = -1
while True:
mincost = INF
for i in range(n):
if color[i] != BLACK and d[i] < mincost:
mincost = d[i]
u = i
if mincost == INF:
break
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,848 |
s534246405 | p02241 | u637097953 | 1575956311 | Python | Python3 | py | Accepted | 20 | 5768 | 741 | n = int(input())
edges = [[-1 for i in range(n)] for j in range(n)]
for i in range(n):
for index, j in enumerate(list(map(int, input().split()))):
edges[i][index] = j
inf = 9999999999999999
distances = [inf] * n
colors = ["white"] * n
def mst(u):
distances[u] = 0
colors[u] = "gray"
while True:
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,849 |
s096222769 | p02241 | u026821956 | 1574789980 | Python | Python3 | py | Accepted | 40 | 7212 | 616 | import heapq
n = int(input())
ans = 0
cost = []
for i in range(n):
L = list(map(int,input().split()))
cost.append(L)
used = [False]*n
used[0] = True #島0から探索を始める。
edge = []
for i in range(n):
T = []
edge.append(T)
for i in range(n):
for j in range(n):
if cost[i][j] != -1:
edge[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,850 |
s792837975 | p02241 | u608189632 | 1574004349 | Python | Python3 | py | Accepted | 20 | 5896 | 1,023 |
def prim():
global n, color, M, d, p
d[0] = 0
while True:
min_cost = 10000000000
u = -1
# まず始点を決める。
for i in range(n):
if color[i] != 'BLACK' and d[i] < min_cost:
min_cost = d[i]
u = i # エッジが繋がる中で、最小のもの??
if u == -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,851 |
s222378173 | p02241 | u638043175 | 1573779496 | Python | Python3 | py | Accepted | 20 | 5984 | 1,063 | import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
M = []
def prim(G, root, n):
BLACK = 1<<10
WHITE = 1<<20
nodes = [WHITE] * n
d = [INF] * n
d[root] = 0
p = [0] * n
p[root] = -1
while True:
mincost = 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,852 |
s183698438 | p02241 | u537758214 | 1573650728 | Python | Python3 | py | Accepted | 20 | 6404 | 1,001 | def main():
N = int(input())
c = [[int(i) for i in input().split()] for j in range(N)]
edges = []
for i in range(N):
for j in range(i+1, N):
if c[i][j] != -1:
edges.append((c[i][j], (i, j)))
edges.sort()
par = [i for i in range(N)]
rank = [0 for i in rang... | 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,853 |
s337056823 | p02241 | u957523223 | 1573212955 | Python | Python3 | py | Accepted | 30 | 6760 | 1,224 | def kruskal(edges):
edges.sort(key=lambda pair:pair[2])
uf_tree = UnionFindTree(n_node)
total_cost = 0
for i, j, cost in edges:
if cost < 0:
continue
if not uf_tree.have_same_root(i, j):
uf_tree.unite(i, j)
total_cost += cost
return total_cost
c... | 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,854 |
s006720759 | p02241 | u137240270 | 1573001417 | Python | Python3 | py | Accepted | 20 | 5820 | 1,004 | N = 100
INF = float('inf')
M = [[INF for _ in range(N)] for _ in range(N)]
n = 0
WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(N)]
d = [INF for _ in range(N)]
p = [0 for _ in range(N)]
def main():
global N
n = int(input())
for i in range(n):
a_s = list(map(int, input().split(' ')[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,855 |
s715463765 | p02241 | u525329683 | 1572617871 | Python | Python3 | py | Accepted | 20 | 5896 | 2,905 | # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/12/ALDS1_12_A
# 本よりこっちのほうがぶっちゃけわかりやすい http://www.deqnotes.net/acmicpc/prim/
# 螺旋本ではダイクストラとの違いをあまり解説していないが、違いはダイクストラのところで考えよう
# 記号は本に合わせる。
# 制約条件によりノードはたかだか100なのでオーダーを木にせずにナイーブに実装できる。本ではdを導入することにより計算量を少し削減している
INF = 10**5
# load data
N = int(input())
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,856 |
s124006907 | p02241 | u639928232 | 1572536978 | Python | Python3 | py | Accepted | 20 | 5760 | 959 |
INFINITY = 10 ** 10
WHITE = 0
GRAY = 1
BLACK = 2
n = int(input())
M = [[INFINITY] * n for _ in range(n)]
for i in range(n):
for j, weight in enumerate(map(int, input().split())):
if weight == -1:
weight = INFINITY
M[i][j] = weight
def prim():
color = [WHITE] * n
d = [INFIN... | 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,857 |
s904906552 | p02241 | u909811933 | 1572396380 | Python | Python3 | py | Accepted | 20 | 6660 | 628 | from heapq import heappush, heappop, heapify
n = int(input())
G = [[] for _ in range(n)]
for i in range(n):
for j,dist in enumerate(map(int,input().split())):
if dist != -1:
G[i].append((j,dist))
sum = 0
def prim(n):
que = [(w,c) for c,w in G[0]]
heapify(que)
color = [0]*n
col... | 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,858 |
s007701666 | p02241 | u121563294 | 1571450976 | Python | Python3 | py | Accepted | 20 | 5904 | 405 | N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
vis = [False] * N
inf = 1e9
d = [inf] * N
d[0] = 0
cost = 0
for _ in range(N):
nv, ni = inf, -1
for i in range(N):
if not vis[i] and d[i] < nv:
nv, ni = d[i], i
vis[ni] = True
cost += nv
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,859 |
s291755826 | p02241 | u778781355 | 1571130049 | Python | Python3 | py | Accepted | 20 | 5896 | 672 | INF = 10000
def prim():
color = ["WHITE" for _ in range(n)]
d = [INF for _ in range(n)]
pi = [None for _ in range(n)]
d[0] = 0
while True:
mincost = INF
for i in range(n):
if color[i] != "BLACK" and d[i] < mincost:
mincost = d[i]
u = i
if mincost == INF:
break
color[u] = "BLACK"
for v 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,860 |
s406537739 | p02241 | u367619546 | 1570712020 | Python | Python3 | py | Accepted | 30 | 5960 | 867 | #ALDS1_12_A Minimum Spanning Tree
import sys
n = int(input())
G = []
for i in range(n):
input_list = list(map(int, sys.stdin.readline().strip().split()))
adj = [j if j != -1 else float('inf') for j in input_list]
adj[i] = 0
G.append(adj)
p = ['unexplored'] * n # 親を保存するリスト
d = [float('inf')] * 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,861 |
s856249207 | p02241 | u139489012 | 1570157213 | Python | Python3 | py | Accepted | 30 | 6352 | 1,098 | import heapq
def make_adj_list(v):
adj_list = [[-1 for i in range(v)] for j in range(v)]
return adj_list
def prim(adj_list, v, s):
# スタートを0とする
min_d = 0
heap = []
used = []
for i in range(v):
used.append(False)
used[s] = True
for i in range(v):
if adj_list[s][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,862 |
s996747396 | p02241 | u153665391 | 1569887936 | Python | Python3 | py | Accepted | 20 | 5892 | 500 | N = int(input())
M = [list(map(int, input().split())) for i in range(N)]
INF = 2001
MAX = 100
d = [INF for i in range(N)]
d[0] = 0
p = [MAX for i in range(N)]
p[0] = -1
mst = [False for i in range(N)]
while True:
min_w = INF
for i in range(N):
if not mst[i] and d[i] < min_w:
min_w = d[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,863 |
s991315844 | p02241 | u134521115 | 1569666989 | Python | Python3 | py | Accepted | 20 | 5884 | 821 | import sys
input = sys.stdin.readline
INF = 100100
def prim(n: int, M: list):
ans = 0
visited = [False] * n
d = [INF] * n
p = [-1] * n
d[0] = 0
while True:
mincost = INF
for i in range(n):
if not visited[i] and d[i] < mincost:
mincost = 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,864 |
s636391288 | p02241 | u183700122 | 1569316881 | Python | Python3 | py | Accepted | 50 | 6484 | 849 | from heapq import heappush, heappop
def search(v, u):
while v != root[v]: v = root[v]
while u != root[u]: u = root[u]
return v, u
def rebuild(v, u, r):
while v != root[v]: v, root[v] = root[v], r
while u != root[u]: u, root[u] = root[u], r
return v, u
n = int(input())
root = [i for i 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,865 |
s067541628 | p02241 | u631142478 | 1566558042 | Python | Python3 | py | Accepted | 20 | 6292 | 899 | import heapq
def prim(adj):
INF = 3000
n = len(adj)
state, d, p = [False] * n, [INF] * n, [-1] * n
d[0] = 0
pq = [(d[0], 0)]
while pq:
f, u = heapq.heappop(pq)
state[u] = True
if d[u] < f:
continue
for v, c in adj[u]:
if state[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,866 |
s808659305 | p02241 | u817810878 | 1565165699 | Python | Python3 | py | Accepted | 60 | 7984 | 999 | from heapq import heappush, heappop, heapify
from typing import List, Tuple
if __name__ == "__main__":
num_vertices = int(input())
adj_list: List[List[Tuple[int, int]]] = [[] for _ in range(num_vertices)]
for vertex in range(num_vertices):
for adj, cost in enumerate(map(lambda x: int(x), input().... | 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,867 |
s453479561 | p02241 | u135880652 | 1562375201 | Python | Python3 | py | Accepted | 20 | 5900 | 922 | WHITE = 0
GRAY = 1
BLACK = 2
INF = 1.0e+6
def prim(M):
n = len(M)
color = [WHITE] * n
d = [INF] * n
p = [-1] * n
d[0] = 0
while True:
minv = INF
u = -1
for i in range(n):
if minv > d[i] and color[i] != BLACK:
u = i
minv = 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,868 |
s158009527 | p02241 | u902579831 | 1561720718 | Python | Python3 | py | Accepted | 30 | 5760 | 957 | INFINITY = 10 ** 10
WHITE = 0
GRAY = 1
BLACK = 2
n = int(input())
M = [[INFINITY] * n for _ in range(n)]
for i in range(n):
for j, weight in enumerate(map(int, input().split())):
if weight == -1:
weight = INFINITY
M[i][j] = weight
def prim():
color = [WHITE] * n
d = [INFINI... | 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,869 |
s619730955 | p02241 | u528682978 | 1561173037 | Python | Python3 | py | Accepted | 30 | 6252 | 686 | def root(x):
path_to_root = []
while x != P[x]:
path_to_root.append(x)
x = P[x]
for node in path_to_root:
P[node]=x
return x
def unite(x,y):
P[root(x)] = root(y)
def is_same_set(x,y):
return root(x) == root(y)
n = int(input())
P = [i for i in range(n)]
length=[]
points... | 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,870 |
s068911306 | p02241 | u772853944 | 1561116969 | Python | Python3 | py | Accepted | 20 | 6376 | 1,610 | def main():
def root(x):
path=[]
while x!=P[x]:
path.append(x)
x=P[x]
for i in path:
P[i]=x
return x
def is_same_set(x,y):
return root(x)==root(y)
def unite(x,y):
P[root(x)]=root(y)
... | 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,871 |
s489466902 | p02241 | u010611609 | 1560946539 | Python | Python3 | py | Accepted | 20 | 6252 | 786 | import itertools
n = int(input())
A = [list(map(int, input().strip().split(' '))) for _ in range(n)]
uvc = [] # A list of tuples of start, end, and cost
for i in range(n-1):
for j in range(i+1, n):
if A[i][j] >= 0:
uvc.append((i, j, A[i][j]))
# コストでソート
uvc.sort(key=lambda x: x[2])
uf = list(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,872 |
s018331777 | p02241 | u100569186 | 1560856621 | Python | Python3 | py | Accepted | 20 | 5724 | 629 | N = int(input())
color = ["w" for _ in range(N)]
d = [float("inf") for _ in range(N)]
p = [-1 for _ in range(N)]
# Make M
M = [list(map(int, input().split())) for _ in range(N)]
d[0] = 0
while True:
mincost = float("inf")
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,873 |
s730185882 | p02241 | u481944101 | 1560842194 | Python | Python3 | py | Accepted | 30 | 6248 | 613 | n=int(input())
matrix=[list(map(int,input().split())) for _ in range(n)]
weight=[]
for x in range(n):
for y in range(x,n):
if matrix[x][y]>=0: weight.append((x,y,matrix[x][y]))
weight.sort(key=lambda x:x[2])
ans=0
p=[i for i in range(n)]
def root(x):
path_to_root=[]
while p[x]!=x:
path_to_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,874 |
s777118506 | p02241 | u353547847 | 1560771000 | Python | Python3 | py | Accepted | 40 | 6552 | 679 | def root(x):
path = []
while P[x] != x:
path.append(x)
x = P[x]
for node in path:
P[node] = x
return x
def check(x,y):
if root(x) == root(y):
return 1
else:
return 0
def unite(x,y):
P[root(x)] = root(y)
n = int(input())
P = [i 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,875 |
s432149340 | p02241 | u694199042 | 1560018365 | Python | Python3 | py | Accepted | 20 | 5880 | 608 | n = int(input())
A = []
# A = [[] for _ in range(n)]
for i in range(n):
A.append(list(map(int, input().split())))
# A[i] = list(map(int, input().split()))
max_d = 2001
flag = [0] * n
d = [max_d] * n
d[0] = 0
p = [-1] * n
while True:
min_d = max_d
for i in range(n):
if flag[i] == 0 and 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,876 |
s118330819 | p02241 | u454636644 | 1557853508 | Python | Python3 | py | Accepted | 20 | 5888 | 919 | def prim(n):
d[0] = 0
while True:
cost_min = 10**9
u = -1
for i in range(n):
weight = d[i]
if flag_list[i] < 2 and weight < cost_min:
u = i
cost_min = weight
if u == -1:
break
flag_list[u] = 2
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,877 |
s886049486 | p02241 | u967553879 | 1555481453 | Python | Python3 | py | Accepted | 20 | 5896 | 1,157 | n = int(input())
M = [list(map(int, input().split())) for _ in range(n)]
WHITE = 0
GREY = 1
BLACK = 2
INFTY = 10**10
color = [WHITE] * n
d = [INFTY] * n
p = [-1] * n
def prim():
# すべての頂点u について color[u] をwhiteとして、d[u]をINFINITYへ
d[0] = 0
p[0] = -1 # 親なし
while True:
mincost = INFTY
fo... | 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,878 |
s088791156 | p02241 | u597769560 | 1554544307 | Python | Python3 | py | Accepted | 30 | 5908 | 635 | # -*- coding: utf-8 -*-
"""
Created on Sat Apr 6 18:01:32 2019
@author: Yamazaki Kenichi
"""
n = int(input())
A = [list(map(int,input().split())) for i in range(n)]
INFTY = 10**6
T = [-1 for i in range(n)]
d = [INFTY for i in range(n)]
p = [0 for i in range(n)]
d[0], p[0] = 0, -1
for j in range(n):
mincost = 10*... | 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,879 |
s078182926 | p02241 | u062898953 | 1554188233 | Python | Python3 | py | Accepted | 50 | 5716 | 443 | n = int(input())
g = [[] for i in range(n)]
for i in range(n):
*v, = map(int, input().split())
for j in range(n):
if v[j] < 0:
v[j] = 10000
g[i] = v
ans = 0
t = [0]
v = [i for i in range(1, n)]
while len(t) < n:
u = [2000, 0, 0]
for tv in t:
for vv in v:
if 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,880 |
s355290386 | p02241 | u805716376 | 1553692762 | Python | Python3 | py | Accepted | 20 | 5916 | 569 | #minimum spaning tree
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
d = [0] + [1e4]*(n-1)
color = [0]*n
# break = 1 ; glay = 2
while 1:
mincost = pow(10, 4)
for i in range(n):
if color[i] != 1 and d[i] < mincost:mincost = d[i];min_key = i
if mincost == pow(10,4):
... | 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,881 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.