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
s152828931
p02241
u798796508
1548752122
Python
Python3
py
Accepted
30
5892
635
n = int(input()) M = [list(map(int, input().split())) for _ in range(n)] INF = 100000000000 color = ['White']*n d = [INF]*n p = [-1]*n d[0] = 0 sum = 0 while True: minct = INF u = -1 for i in range(n): if color[i] != 'Black' and d[i] < minct: minct = d[i] u = i if minct ...
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,882
s532199719
p02241
u800534567
1544775619
Python
Python3
py
Accepted
60
5932
465
import sys n = int(sys.stdin.readline()) g = [list(map(int, sys.stdin.readline().split())) for _ in range(n)] V = set(range(n)) U = set() E = [] U.add(V.pop()) while len(U)<n: minw = 1e10 mine = [] for u in U: for v in V: if g[u][v]>=0 and minw>g[u][v]: minw = g[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,883
s213362309
p02241
u697145890
1544273111
Python
Python3
py
Accepted
80
7888
1,808
import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush, heappop BIG_NUM = 2000000000 MOD = 1000000007 EPS = 0.000000001 class UnionFind: def __init__(self,arg_V): self.V = arg_V self.boss = [None]*arg_V self.height = [None]*arg_...
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,884
s959296428
p02241
u025180675
1542763269
Python
Python3
py
Accepted
30
6348
728
import heapq 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) W = 0 N = int(input().strip()) P = [i for i 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,885
s692855863
p02241
u160320718
1542626297
Python
Python3
py
Accepted
30
6248
630
n = int(input()) T = [i for i in range(n)] def root(x): path_to_root = [] while T[x] != x: path_to_root.append(x) x = T[x] for node in path_to_root: T[node] = x return x def is_same_set(x,y): return root(x) == root(y) def unite(x,y): T[root(x)] = root(y) A = [] W = [] 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,886
s198581812
p02241
u487861672
1539399283
Python
Python3
py
Accepted
30
6396
1,031
from sys import maxsize from functools import reduce WHITE = 0 GRAY = 1 BLACK = 2 def read_adj_mat(): n = int(input()) M = [] for _ in range(n): M.append([maxsize if x == "-1" else int(x) for x in input().split()]) return n, M def min_sp_tree(n, M): 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,887
s128064009
p02241
u260980560
1538408292
Python
Python3
py
Accepted
20
6656
498
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,888
s976932852
p02241
u255317651
1537592822
Python
Python3
py
Accepted
30
6628
857
# -*- coding: utf-8 -*- """ Created on Sat Sep 22 11:44:37 2018 ALDS1-12-A @author: maezawa """ import heapq n = int(input()) amat = [[] for _ in range(n)] for i in range(n): amat[i] = list(map(int, input().split())) adj = [[] for _ in range(n+1)] for i in range(n): for j in range(i, n): if amat[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,889
s669811613
p02241
u578148790
1534062022
Python
Python3
py
Accepted
20
5892
913
INFTY = 1 << 21 WHITE = 0 GRAY = 1 BLACK = 2 def prim(n, m): d = [INFTY] * n p = [-1] * n color = [WHITE] * n d[0] = 0 while True: minv = INFTY u = -1 for i in range(n): if minv > d[i] and color[i] != BLACK: u = i minv = 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,890
s452752129
p02241
u269568674
1533004035
Python
Python3
py
Accepted
50
6248
531
n = int(input()) a = [] b = [] c = [] def root(x): global rs if rs[x] == x: return(x) else: return(root(rs[x])) for _ in range(n): a.append(list(map(int,input().split()))) for i in range(n): for j in range(i+1,n): if a[i][j] >= 0: b.append([a[i][j],i,j]) rs = [(...
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,891
s267787322
p02241
u940395729
1533001981
Python
Python3
py
Accepted
20
5888
717
infinity = 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: line[i] = infinity a.append(line) checked = [False] * n d = [infinity] * n checked[0] = True ansswer = 0 next = 0 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,892
s494063565
p02241
u424720817
1532406360
Python
Python3
py
Accepted
20
5892
469
n = int(input()) a = [list(map(int, input().split())) for i in range(n)] m = [2001] * n f = [0] * n sum = 0 m[0] = 0 f[0] = 1 v = 0 for i in range(n-1) : for j in range(n) : if (a[v][j] < m[j]) & (f[j] == 0) & (a[v][j] != -1): m[j] = a[v][j] min = 2001 minj = 0 for j 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,893
s046451705
p02241
u281836941
1529316474
Python
Python3
py
Accepted
30
6088
438
# coding: utf-8 import heapq n=int(input()) cost=[] used=[False for i in range(n)] for i in range(n): cost.append(list(map(int,input().split()))) q=[] heapq.heappush(q,(0,0)) ans=0 while len(q): c,newv=heapq.heappop(q) if used[newv]: continue used[newv]=True ans+=c for nxt 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,894
s294365949
p02241
u079141094
1468307419
Python
Python3
py
Accepted
40
8000
707
# Graph II - Minimum Spanning Tree def mst(length, adj_m): """ Prims's Algorithm """ cost = 0 X,Y = [0], [i+1 for i in range(length-1)] while len(Y): min_cost = 2001 ey = -1 for x in X: for y in Y: t = adj_m[x][y] if not t == -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,895
s451037113
p02242
u551083572
1531041767
Python
Python3
py
Accepted
20
5980
771
# coding: utf-8 import heapq def dj(adjm, start): n = len(adjm) d = [float("inf")] * n d[start] = 0 q = [] heapq.heappush(q, (0, start)) while(q): td, v = heapq.heappop(q) for k in adjm[v].keys(): nd = td + adjm[v][k] if d[k] > nd: d[k]...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,896
s707218680
p02242
u255317651
1531656336
Python
Python3
py
Accepted
20
6156
1,174
# -*- coding: utf-8 -*- """ Created on Sat Jul 14 19:11:44 2018 @author: maezawa """ infinity = 2*10**9 n = int(input()) adj = [[] for _ in range(n)] for j in range(n): ain = list(map(int, input().split())) u = ain[0] k = ain[1] for i in range(2,2+2*k,2): adj[u].append([ain[i],ain[i+1]]) ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,897
s455586095
p02242
u684241248
1531657864
Python
Python3
py
Accepted
20
6244
4,357
# -*- coding: utf-8 -*- from heapq import heappop, heappush def dijkstra(edges, start, *, adj_matrix=False, default_value=float('inf')): ''' Returns best costs to each node from 'start' node in the given graph. (Single Source Shortest Path - SSSP) If edges only include costs and destination nodes on ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,898
s034866716
p02242
u197615397
1531808739
Python
Python3
py
Accepted
20
6264
1,393
import sys def dijkstra(v_count: int, edges: list, start: int, *, adj_matrix: bool = False, unreachable=float("inf")) -> list: """ ダイクストラ法 :param v_count: 頂点数 :param edges: 辺のリスト(隣接リストor隣接行列) :param start: スタートする頂点 :param adj_matrix: edgesに渡したリストが隣接行列ならTrue :param unreachable: 到達不能...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,899
s338873314
p02242
u197615397
1531809376
Python
Python3
py
Accepted
20
5988
1,479
import sys def dijkstra(v_count: int, edges: list, start: int, *, adj_matrix: bool = False, unreachable=float("inf")) -> list: """ ダイクストラ法 :param v_count: 頂点数 :param edges: 辺のリスト(隣接リストor隣接行列) :param start: スタートする頂点 :param adj_matrix: edgesに渡したリストが隣接行列ならTrue :param unreachable: 到達不能...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,900
s204881959
p02242
u279605379
1534814333
Python
Python3
py
Accepted
40
6228
550
from collections import deque import sys import heapq n = int(input()) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h,(dis[i],i)) while(len(h)>0): node = heapq.heappop(h) tmp = node[1] for i in range(V...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,901
s139255315
p02242
u279605379
1534817074
Python
Python3
py
Accepted
30
5952
520
import sys import heapq n = int(input()) V = [[int(i) for i in input().split()] for _ in range(n)] dis = [sys.maxsize for _ in range(n)] dis[0] = 0 h = [] for i in range(n): heapq.heappush(h,(dis[i],i)) while(len(h)>0): node = heapq.heappop(h) tmp = node[1] for i in range(V[tmp][1]): ind = V[tmp...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,902
s321564363
p02242
u007270338
1535935285
Python
Python3
py
Accepted
20
5732
959
#coding: utf-8 inf = 1000000000 def dijkstra(s): d = [inf for i in range(n)] color = ["white" for i in range(n)] p = [-1 for i in range(n)] d[s] = 0 while True: mincost = inf for i in range(n): if color[i] != "black" and d[i] < mincost: mincost = d[i] ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,903
s612598170
p02242
u726330006
1540452393
Python
Python3
py
Accepted
20
5820
1,022
n=int(input()) graph=[[0]*n for i in range(n)] #graph[i][j]は、頂点iから頂点jへの枝の重みを表す(0は枝なし) for loop in range(n): tmp_ope=list(map(int,input().split())) for j in range(1,tmp_ope[1]+1): graph[tmp_ope[0]][tmp_ope[2*j]]=tmp_ope[2*j+1] #S[i]=1の時、頂点iは走査済み S=[0]*n #d[i]はSに含まれる点のみを使って、頂点iにたどり着くときの最短パス d=[999999]...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,904
s781007349
p02242
u165578704
1556445904
Python
Python3
py
Accepted
20
6216
1,494
# -*- coding: utf-8 -*- import sys from heapq import heappush, heappop 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') # ダイクストラ(頂点数, 隣接リスト(0-i...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,905
s708647496
p02242
u232404920
1556785562
Python
Python3
py
Accepted
40
6748
751
from collections import namedtuple Edge = namedtuple('Edge', ('fr', 'to', 'cost')) inf = 1e9 def bf(n, s, es): d = [inf for _ in range(n)] d[s] = 0 while True: updated = False for e in es: if d[e.fr] != inf and d[e.fr] + e.cost < d[e.to]: updated = True ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,906
s426959261
p02242
u232404920
1556786904
Python
Python3
py
Accepted
40
6740
1,412
from collections import namedtuple Edge = namedtuple('Edge', ('fr', 'to', 'cost')) inf = 1e9 def bellman_ford(n, start, edges): dists = [inf for _ in range(n)] dists[start] = 0 while True: updated = False for e in edges: if dists[e.fr] != inf and dists[e.fr] + e.cost < dists[e...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,907
s614415874
p02242
u350698365
1559491113
Python
Python3
py
Accepted
20
6124
1,259
n = int(input()) adjc_list = [[] for _ in range(n)] INF = 99999999999999999999 V = [ele for ele in range(n)] S = [] d = [INF] * n p = [ele for ele in range(n)] for i in range(n): tmp = [int(ele) for ele in input().split()] for j in range(1, tmp[1]*2, 2): v = tmp[j+1] w = tmp[j+2] adjc_l...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,908
s702101761
p02242
u881590806
1452475144
Python
Python
py
Accepted
40
6792
814
INFTY = 100000000000000000000000000 n = int(raw_input()) graph = {} for i in range(n): entry = map(int, raw_input().split(' ')) u = entry[0] k = entry[1] graph[u] = {} for j in range(k): v = entry[2+j*2] c = entry[2+j*2+1] graph[u][v] = c d = {} visited = {} for i in range(n...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,909
s510054992
p02242
u669284080
1454070921
Python
Python3
py
Accepted
30
8516
681
#!/usr/bin/python3 from heapq import heappop, heappush n = int(input()) inf = 100 * 100000 M = [[] for i in range(n)] for i in range(n): L = list(map(int, input().split())) u = L[0] k = L[1] v = L[2::2] c = L[3::2] for j in range(k): M[u].append((v[j], c[j])) result = [0] * n S = set()...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,910
s487044866
p02242
u731976921
1454469085
Python
Python
py
Accepted
10
6684
783
#!/usr/bin/python import sys def parse(): n = int(raw_input()) A = [] for line in sys.stdin: fields = line.split() u = int(fields.pop(0)) k = int(fields.pop(0)) edges = {} for i in range(k): edges[int(fields[2*i])] = int(fields[2*i + 1]) A.append(edges) return A def dijkstra(s, ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,911
s012623674
p02242
u000228958
1454733520
Python
Python
py
Accepted
10
6828
943
n = input() M = [[float("inf") for j in xrange(n)] 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(tmp[1]): M[i][tmp[(j + 1)*2]] = tmp[j*2 + 3] def dijksrra(s): color = ["WHITE" for i in xrange(n)] d = [float("inf") for i...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,912
s504469015
p02242
u970436839
1454759281
Python
Python
py
Accepted
20
6468
852
n = input() INFTY = 1000000 color = [0 for i in xrange(n)] d = [INFTY for i in xrange(n)] M = [[INFTY for i in xrange(n)] for i in xrange(n)] p = [-1 for i in xrange(n)] def SSSP1(): d[0] = 0 while True: cost = INFTY for i in xrange(n): if color[i] != 2 and d[i] < cost: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,913
s609649731
p02242
u038005340
1454869326
Python
Python
py
Accepted
30
6660
707
INFTY = 100000000 n = int( raw_input() ) graph = {} for i in range(n): In = map( int , raw_input().split(' ') ) u = In[0] k = In[1] graph[u] = {} for j in range(k): v = In[2+j*2] c = In[2+j*2+1] graph[u][v] = c da = {} visited = {} for i in range(n): da[i] = INFTY visited[i] = False s = 0 da...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,914
s454300248
p02242
u038005340
1454869355
Python
Python
py
Accepted
10
6652
712
INFTY = 100000000 n = int( raw_input() ) graph = {} for i in range(n): In = map( int , raw_input().split(' ') ) u = In[0] k = In[1] graph[u] = {} for j in range(k): v = In[2+j*2] c = In[2+j*2+1] graph[u][v] = c da = {} visited = {} for i in range(n): da[i] = INFTY visited[i] = False s = 0 da...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,915
s290000805
p02242
u334643297
1454949972
Python
Python
py
Accepted
10
6696
644
n = int(raw_input()) a = [0 for i in xrange(n)] adj = [[0 for i in xrange(n)] for j in xrange(n)] for i in xrange(n): a[i] = map(int,raw_input().split()) for i in xrange(n): for j in xrange(2, a[i][1]*2+1, 2): adj[a[i][0]][a[a[i][0]][j]] = a[a[i][0]][j+1] MAX = 100000000 end = [1] * n cost = [MAX] * n cost[0] = 0 p...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,916
s692892536
p02242
u563876281
1455003064
Python
Python
py
Accepted
10
6664
688
from __future__ import division, print_function from sys import stdin, maxint def main(): num = int(stdin.readline()) y = [] for _ in xrange(num): it = iter(int(s) for s in stdin.readline().split()[1:]) y.append([(next(it), next(it)) for _ in xrange(next(it))]) weight = [maxint] ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,917
s497621948
p02242
u885467869
1455008606
Python
Python
py
Accepted
30
6532
1,123
def dijkstra(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] an...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,918
s956034562
p02242
u619765879
1455032831
Python
Python
py
Accepted
10
6528
705
n = input() inf = 1000000000 M = [[inf for i in range(n)] for i in range(n)] for i in range(n): str = map(int, raw_input().split()) u = str[0] k = str[1] for j in range(k): v = str[2+2*j] c = str[3+2*j] M[u][v] = c d = [inf for i in range(n)] color = [0 for i in range(n)] d[0] = 0 color[0] = 1 w...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,919
s152566940
p02242
u177808190
1455081944
Python
Python
py
Accepted
10
6460
901
MAX = 100 INF = 1000000 WHITE = 0 GRAY = 1 BLACK = 2 n = int(raw_input()) M = [[INF for i in range(n)]for j in range(n)] d = [INF for i in range(MAX)] Color = [WHITE for i in range(MAX)] for i in range(n): tmp = map(int,raw_input().split()) u = tmp[0] k = tmp[1] for j in range(1, k + 1): v = tm...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,920
s152258605
p02242
u797673668
1455085191
Python
Python3
py
Accepted
30
8676
649
import heapq n = int(input()) edges = [None] * n for _ in range(n): l = list(map(int, input().split())) edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2))) min_costs = [0] * n visited = [False] * n visited[0] = True queue = list(edges[0]) heapq.heapify(queue) while queue: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,921
s381692273
p02242
u341533698
1455246989
Python
Python
py
Accepted
10
6524
877
WHITE = 0 GRAY = 1 BLACK = 2 n = int(raw_input()) M = [ [-1] * n for _ in xrange(n)] color = [WHITE] * n d = [float('inf')] * n for i in xrange(n): a = map(int, raw_input().split()) for j in xrange(a[1]): M[a[0]][a[2*(j+1)]] = a[2*(j+1)+1] def dijkstra(): d[0] = 0 while True: mincos...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,922
s603200196
p02242
u663227983
1455291489
Python
Python
py
Accepted
10
6672
1,105
infty = 10**21 white = 0 gray = 1 black = 2 n = input() m = [[infty for i in xrange(n)] for j in xrange(n)] l = [[0 for i in xrange(n)] for j in xrange(n)] d = [0 for i in xrange(n)] color = [0 for i in xrange(n)] def dijkstra(): for i in xrange(n): d[i] = infty color[i] = white d[0...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,923
s008212394
p02242
u408260374
1455861788
Python
Python3
py
Accepted
30
8204
1,548
import heapq class ShortestPath: """Dijkstra's algorithm : find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, V, E, start, INF=10**9): """ V: the number of vertexes E: adjacency list (all edge in E must be 0 or positi...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,924
s130075283
p02242
u731710433
1457281024
Python
Python3
py
Accepted
20
7904
613
def dijkstra(n): inf = 10 ** 6 + 1 dist = [0] + [inf] * (n - 1) visited = [False] * n while not all(visited): dmin = inf for i, (d, v) in enumerate(zip(dist, visited)): if dmin > d and not v: dmin, u = d, i visited[u] = True for (v, c) in edge...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,925
s847015383
p02242
u894114233
1459586633
Python
Python
py
Accepted
30
6488
836
def dijkstra(s): global d color=[0]*n d=[float('inf')]*n d[s]=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 color[u]=2 ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,926
s600925743
p02242
u567281053
1463712850
Python
Python
py
Accepted
20
6484
643
import sys def dijkstra(W, n): U = [i for i in range(1, n)] D = [W[0][i] for i in range(n)] D[0] = 0 while len(U) != 0: mind, minu = 200001, -1 for u in U: if D[u] <= mind: mind, minu = D[u], u U.remove(minu) for i in range(1, n): ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,927
s953974026
p02242
u342312206
1465485623
Python
Python3
py
Accepted
70
9600
815
from queue import PriorityQueue def sssp(adj_list): n = len(adj_list) d = [None]*n pq = PriorityQueue() pq.put((0, 0)) # d, v while(not pq.empty()): d_v, v = pq.get() if d[v] is not None: continue d[v] = d_v for u, c_vu in adj_list[v]: pq.put...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,928
s377817592
p02242
u072053884
1466048814
Python
Python3
py
Accepted
20
7856
863
n = int(input()) adj = [[100001 for j in range(n)] for i in range(n)] for u in range(n): x = list(map(int, input().split())) for v, c in zip(x[2::2], x[3::2]): adj[u][v] = c isVisited = [False] * n distance = [9900001] * n def dijkstra(s): distance[s] = 0 while True: mincost = 990...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,929
s437948217
p02242
u072053884
1466133653
Python
Python3
py
Accepted
30
7824
826
n = int(input()) adj = [[100001 for j in range(n)] for i in range(n)] for u in range(n): x = list(map(int, input().split())) for v, c in zip(x[2::2], x[3::2]): adj[u][v] = c unvisited = {v for v in range(n)} distance = [9900001] * n def dijkstra(s): distance[s] = 0 while True: min...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,930
s989261940
p02242
u072053884
1466133725
Python
Python3
py
Accepted
20
7844
826
n = int(input()) adj = [[100001 for j in range(n)] for i in range(n)] for u in range(n): x = list(map(int, input().split())) for v, c in zip(x[2::2], x[3::2]): adj[u][v] = c unvisited = {v for v in range(n)} distance = [9900001] * n def dijkstra(s): distance[s] = 0 while True: min...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,931
s076428027
p02242
u072053884
1466134194
Python
Python3
py
Accepted
30
7944
825
n = int(input()) adj = [[100001 for j in range(n)] for i in range(n)] for u in range(n): x = list(map(int, input().split())) for v, c in zip(x[2::2], x[3::2]): adj[u][v] = c unvisited = [v for v in range(n)] distance = [9900001] * n def dijkstra(s): distance[s] = 0 while True: min...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,932
s918636568
p02242
u072053884
1466134265
Python
Python3
py
Accepted
20
7848
825
n = int(input()) adj = [[100001 for j in range(n)] for i in range(n)] for u in range(n): x = list(map(int, input().split())) for v, c in zip(x[2::2], x[3::2]): adj[u][v] = c unvisited = [v for v in range(n)] distance = [9900001] * n def dijkstra(s): distance[s] = 0 while True: min...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,933
s428637848
p02242
u894114233
1473314127
Python
Python
py
Accepted
10
6780
671
import heapq def dijkstra(s,g,c): d=[float('inf')]*n d[s]=0 heapq.heappush(pq,[0,s]) while len(pq)!=0: t,u=heapq.heappop(pq) if d[u]<t: continue for v in g[u]: if d[u]+c[u][v]<d[v]: d[v]=d[u]+c[u][v] heapq.heappush(pq,[d[v]...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,934
s267089308
p02242
u890722286
1479021631
Python
Python3
py
Accepted
20
7828
801
def relax(u, v, w): if D[u] + w < D[v]: D[v] = D[u] + w P[v] = u INF = float('inf') N = int(input()) D = [INF for i in range(N)] P = [None for i in range(N)] C = ['w' for i in range(N)] D[0] = 0 G = [[INF for j in range(N)] for i in range(N)] for i in range(N): x = list(map(int, input().split(...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,935
s094088766
p02242
u022407960
1479748513
Python
Python3
py
Accepted
30
8776
1,883
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for v_detail in v_info: v_index = int(v_detail[0]) v_adj_length = int(v_detail[1]) v_adj_list = v_detail[2:] # assert len(v_adj_list) == v_a...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,936
s343574088
p02242
u022407960
1479748933
Python
Python3
py
Accepted
30
8692
1,951
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for v_detail in v_info: v_index = int(v_detail[0]) v_adj_length = int(v_detail[1]) v_adj_list = v_detail[2:] # assert len(v_adj_list) == v_a...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,937
s294327262
p02242
u022407960
1479782393
Python
Python3
py
Accepted
40
8956
2,248
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys import heapq as hp WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for v_detail in v_info: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,938
s171216273
p02242
u022407960
1479782441
Python
Python3
py
Accepted
40
8900
2,248
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys import heapq as hp WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for v_detail in v_info: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,939
s999625718
p02242
u022407960
1479783970
Python
Python3
py
Accepted
50
8908
2,326
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys import heapq as hp WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for v_detail in v_info: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,940
s061698784
p02242
u022407960
1479786827
Python
Python3
py
Accepted
30
8252
2,244
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys import heapq as hp WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for each in v_info: v_...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,941
s737523127
p02242
u022407960
1479789029
Python
Python3
py
Accepted
20
8076
2,132
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys WHITE, GRAY, BLACK = 0, 1, 2 D_MAX = int(1e7 + 1) def generate_adj_matrix(v_info): for each in v_info: v_index, v_adj_length...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,942
s232076975
p02242
u022407960
1480485450
Python
Python3
py
Accepted
30
8268
1,851
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3 output: 0 0 1 2 2 2 3 1 4 3 """ import sys import heapq as hp WHITE, GRAY, BLACK = 0, 1, 2 def generate_adj_table(v_table): for each in v_table: v_index, v_adj_length,...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,943
s680946332
p02242
u186082958
1480533653
Python
Python3
py
Accepted
50
8232
569
import heapq N=int(input()) ad_li=[[]for i in range(N)] for i in range(N): nums=list(map(int,input().split())) f=nums[0] for j in range(nums[1]): t=nums[j*2+2] c=nums[j*2+3] ad_li[f].append([t,c]) memo=[1E18 for i in range(N)] memo[0]=0 qu=[] heapq.heappush(qu,(0,0)) while len(qu)!=...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,944
s717717683
p02242
u811733736
1481419753
Python
Python3
py
Accepted
70
8292
2,118
from enum import Enum class Sssp(object): """ single source shortest path """ INFINITY = 999999999 class Status(Enum): """ ?????????????¨??????¶??? """ white = 1 # ????¨???? gray = 2 # ?¨??????? black = 3 #?¨??????? def __init__(self, data): num_of_nodes = l...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,945
s202562096
p02242
u159356473
1481526907
Python
Python3
py
Accepted
40
7860
968
#coding:utf-8 def Dijkestra(G,n): d=[100000000000]*n pi=[None]*n d[0]=0 C=[] for i in range(n): C.append(i) while len(C)!=0: u=C[0] for i in range(1,len(C)): if d[u]>d[C[i]]: u=C[i] C.remove(u) for i in range(len(G[u])): ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,946
s937035531
p02242
u923668099
1486721740
Python
Python3
py
Accepted
20
8020
1,076
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 SSSP(n, Adj): d = [inf] * n p = [-1] * n checked = [False] * n d[0] = 0 checked[0] = True ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,947
s683468846
p02242
u112247126
1488599135
Python
Python3
py
Accepted
40
7856
1,069
INF = float('inf') def dijkstra(source): distance[source] = 0 parent[source] = -1 while True: mincost = INF for i in range(n): if color[i] != 'black' and distance[i] < mincost: mincost = distance[i] u = i if mincost == INF: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,948
s201006385
p02242
u462831976
1490071169
Python
Python3
py
Accepted
30
8296
1,090
"""Shortest Path""" import sys import os import pprint #fd = os.open('ALDS1_12_B.txt', os.O_RDONLY) #os.dup2(fd, sys.stdin.fileno()) level = True def debug(v): if level: print(v) n = int(input()) INF = float('inf') W = [[INF for j in range(n)] for i in range(n)] for _ in range(n): l = list(map(int,...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,949
s463415409
p02242
u529386725
1491461676
Python
Python
py
Accepted
20
6660
657
import heapq def dijkstra(G, s): n = len(G) INF = float("inf") d = [INF] * n d[s] = 0 pq = [] heapq.heappush(pq, (0, s)) # (cost, vertex) while pq: c, v = heapq.heappop(pq) if d[v] < c: continue for nv, nc in G[v]: if d[nv] > d[v] + nc: ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,950
s896818255
p02242
u603049633
1496544944
Python
Python3
py
Accepted
20
7824
748
inf = float("inf") n = int(input()) M = [[inf for i in range(n)] for i in range(n)] for i in range(n): L = list(map(int, input().split())) for j in range(L[1]): M[L[0]][L[2 * j + 2]] = L[2 * j + 3] def dijkstra(s): color = [0] * n d = [inf] * n d[s] = 0 while True: mincost = i...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,951
s935159821
p02242
u370086573
1497684140
Python
Python3
py
Accepted
30
7924
1,089
INF = 1000000 def diikstraMethd(G, s): # ????????? n = len(G) # White:0 Gyay:1 Black:2 color = [0 for _ in range(n)] d = [INF for _ in range(n)] p = [None for _ in range(n)] d[s] = 0 while True: mincost = INF for i in range(n): if color[i] != 2 and d[i] < ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,952
s606451180
p02242
u426534722
1500048847
Python
Python3
py
Accepted
20
7796
844
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 u in range(0, n): U = list(map(int, stdin.readline().split()[2:])) for j in range(0, len(U), 2): M[u][U[j]] = U[j + 1] d = [INF] * n d[0] = 0 color = [WHITE] * n color[0] = GRAY...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,953
s225144804
p02242
u514487486
1501220631
Python
Python
py
Accepted
30
6476
903
n = int(raw_input()) matrix = [[100001 for i in range(n)] for j in range(n)] for i in range(n): line = raw_input() splited = line.split() splited = map(lambda x: int(x), splited) u = splited[0] k = splited[1] for j in range(k): matrix[u][splited[2 + j * 2]] = splited[2 + j * 2 + 1] co...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,954
s118232345
p02242
u881590806
1502604618
Python
Python3
py
Accepted
30
8416
2,159
from collections import defaultdict def dijkstra(G, s): heap = Heap() heap.push((s, 0)) fixed = set() d = defaultdict(lambda: 999999999999999999999) d[s] = 0 while len(heap.data) > 0: v = heap.pop() if v in fixed: continue for u in G[v]: if u in fixed: continue c = G[v...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,955
s468982843
p02242
u510829608
1502892538
Python
Python3
py
Accepted
20
7852
902
INF = 1e9 n = int(input()) adj_matrix = [[INF for i in range(n)] for j in range(n)] for i in range(n): u, k, *line = list(map(int, input().split())) for j in range(k): adj_matrix[u][line[2*j]] = line[2*j+1] def dijkstra(x): isVisited = [False] * x d = [INF] * x d[0] = 0 p = [0] * x ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,956
s074360151
p02242
u855199458
1503054035
Python
Python3
py
Accepted
30
7812
838
# -*- coding: utf-8 -*- N = int(input()) INF = float("inf") adj = [[INF]*N for _ in range(N)] for n in range(N): inp = tuple(map(int, input().split())) assert n == inp[0] for i in range(inp[1]): adj[inp[0]][inp[2*i+2]] = inp[2*i+3] not_MST = list(range(1, N)) MST = [0] costs = {n:INF for n in ran...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,957
s886236182
p02242
u855199458
1503384863
Python
Python3
py
Accepted
20
8248
635
# -*- coding: utf-8 -*- from heapq import heappush, heappop N = int(input()) INF = float("inf") adj = [] for _ in range(N): inp = tuple(map(int, input().split())) adj.append(tuple(zip(inp[2::2], inp[3::2]))) checked = [False for _ in range(N)] d = [float("inf") for _ in range(N)] d[0] = 0 heap = [[0, 0]] # c...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,958
s426318391
p02242
u519227872
1505130972
Python
Python3
py
Accepted
30
8616
656
n = int(input()) from collections import defaultdict G = defaultdict(list) for i in range(n): i = [int(i) for i in input().split()] k = i[1] G[i[0]] = list(zip(i[2::2],i[3::2])) def mind(Q, d): c = float('inf') ret = 0 for i, j in enumerate(d): if c > j and i in Q: c = j ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,959
s407317831
p02242
u368364462
1506403473
Python
Python
py
Accepted
10
6548
950
def dijkstra(): N = input() M = [ [float('inf')] * N for i in xrange(N)] color = [0] * N d = [float('inf')] * N p = [-1] * N d[0] = 0 p[0] = -1 for i in xrange(N): l = map(int, raw_input().split()) for j in xrange(l[1]): M[i][l[2 * (j+1)]] = l[2 * (j+1) + 1...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,960
s041296555
p02242
u796784914
1506763316
Python
Python
py
Accepted
10
6548
901
def main(): n = input() inf = float('inf') M = [[inf]*n for i in xrange(n)] for i in xrange(n): Ai = map(int,raw_input().split()) for j in xrange(Ai[1]): M[i][Ai[2+2*j]] = Ai[3+2*j] d = dijkstra(0,M,n) for i in xrange(n): print i, d[i] def dijkstra(s,M,n): ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,961
s637472494
p02242
u024715419
1511164022
Python
Python3
py
Accepted
30
8284
586
import heapq n = int(input()) d = [float("inf") for i in range(n)] d[0] = 0 g = [] q = [] for i in range(n): heapq.heappush(q, (d[i], i)) inp = list(map(int, input().split())) tmp = [] for j in range(inp[1]): tmp.append(inp[2*j+2:2*j+4]) g.append(tmp) while q: q_pop = heapq.heappop(q)...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,962
s086784022
p02242
u626266743
1511970414
Python
Python3
py
Accepted
30
5884
941
from sys import stdin INFTY = 1 << 21 WHITE = 0 GRAY = 1 BLACK = 2 n = int(stdin.readline()) M = [[INFTY for i in range(n)] for j in range(n)] for u in range(n): U = list(map(int, stdin.readline().split()[2:])) for j in range(0, len(U), 2): M[u][U[j]] = U[j+1] d = [INFTY for i in range(n)] color = [...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,963
s993770804
p02242
u236679854
1511997788
Python
Python3
py
Accepted
20
5860
733
inf = float('inf') n = int(input()) g = [] for i in range(n): line = list(map(int, input().split())) k = line[1] c = [inf] * n for j in range(k): v = line[2 + 2 * j] c[v] = line[3 + 2 * j] g.append(c) distance = [inf] * n distance[0] = 0 visited = [False] * n current = 0 while not ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,964
s007316450
p02242
u736039489
1515304849
Python
Python3
py
Accepted
20
5976
638
# -*- coding: utf-8 -*- import heapq q = [] # プライオリティキュー n = int(input()) V = dict() d = dict() for i in range(n): data = list(map(int, input().split())) V[data[0]] = data[2:] d[data[0]] = float('inf') d[0] = 0 heapq.heappush(q, (0, 0)) #(d[id], id) S = set() while len(S) != len(V): dist, node_id ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,965
s797782433
p02242
u672443148
1516807447
Python
Python3
py
Accepted
20
6184
714
from heapq import * #edge {to cost} #P {mindirection, modeNum} #G a list which contain informations of nodes # building G from input V=int(input()) G=[] for _ in range(V): temp=list(map(int,input().split())) l=[] for i in range(1,temp[1]+1): l.append(temp[2*i:2*(i+1)]) G.append(l) que=[] #hav...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,966
s859355769
p02242
u662418022
1518690798
Python
Python3
py
Accepted
30
5996
1,037
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) M = [[float("inf") for j in range(n)] for i in range(n)] for i in range(n): l = list(map(int, input().split(" "))) for k in range(l[1]): j = l[2 + 2 * k] c = l[2 + 2 * k + 1] M[i][j] =...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,967
s344792314
p02242
u426534722
1519396655
Python
Python3
py
Accepted
30
6304
570
from collections import deque INF = float("inf") def MAIN(): n = int(input()) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i + 1] dp = de...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,968
s870771616
p02242
u426534722
1519398522
Python
Python3
py
Accepted
20
6072
602
from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(input()) G = [[i, INF] for i in range(n)] G[0][1] = 0 m = {} for _ in range(n): A = list(map(int, input().split())) m[A[0]] = {} for i in range(2, len(A), 2): m[A[0]][A[i]] = A[i +...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,969
s109679572
p02242
u150984829
1520404729
Python
Python3
py
Accepted
20
5756
376
n=int(input()) M=[[-1]*n for _ in[0]*n] for _ in[0]*n: e=list(map(int,input().split())) for i in range(e[1]):k=2*-~i;M[e[0]][e[k]]=e[k+1] d=[0]+[1e6]*~-n c=[1]*n while 1: m,u=1e6,-1 for i in range(n): if m>d[i]and c[i]:m,u=d[i],i if u<0:break c[u]=0 for v in range(n): if c[v]and 1+M[u][v]and d[v]>d[u]+M[u][v...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,970
s393306829
p02242
u150984829
1520415863
Python
Python3
py
Accepted
20
5756
374
n=int(input()) M=[[-1]*n for _ in[0]*n] for _ in[0]*n: e=list(map(int,input().split())) for i in range(e[1]):k=2*-~i;M[e[0]][e[k]]=e[k+1] d=[0]+[1e6]*n c=[1]*n while 1: m,u=1e6,-1 for i in range(n): if m>d[i]and c[i]:m,u=d[i],i if u<0:break c[u]=0 for v in range(n): if c[v]and 1+M[u][v]and d[v]>d[u]+M[u][v]:...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,971
s440158685
p02242
u912143677
1522332999
Python
Python3
py
Accepted
30
5792
802
INF = 1e9 n = int(input()) a = [[-1 for i in range(n)]for i in range(n)] for i in range(n): b = list(map(int, input().split())) index = b[0] k = b[1] for j in range(k): a[index][b[2+j*2]] = b[3+j*2] def dijkstra(s): flag = [0] * n d = [INF] * n d[s] = 0 p = [-1] * n while...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,972
s798226146
p02242
u126478680
1526023592
Python
Python3
py
Accepted
30
6456
1,087
from enum import Enum, auto INFTY = float('inf') class Color(Enum): WHITE = auto() GRAY = auto() BLACK = auto() n = int(input()) M = [[-1 for i in range(n)] for i in range(n)] for i in range(n): line = list(map(int, input().split(' '))) if line[1] == 0: continue for j in range(2, 2+2*line[1],...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,973
s667350554
p02242
u912143677
1527415486
Python
Python3
py
Accepted
30
6224
571
n = int(input()) graph = [[] for i in range(n)] for i in range(n): a = list(map(int, input().split())) for j in range(a[1]): graph[a[0]].append(a[2+j*2:4+j*2]) #[頂点, cost] memo = [10**10 for i in range(n)] memo[0] = 0 import heapq q = [] heapq.heappush(q, (0, 0)) #(それまでのcost, 頂点) while len(q) != ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,974
s711133308
p02242
u646461156
1527415629
Python
Python3
py
Accepted
30
6220
1,745
# coding: utf-8 import heapq class Dijkstra: """ Dijkstra's algorithm: find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, V, G, INF=float("inf")): """ V: the number of vertexes E: adjacency list (all edge in G mu...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,975
s869855931
p02242
u368083894
1528693364
Python
Python3
py
Accepted
20
6208
876
import heapq def dijkstra(g, source): n = len(g) q = [] heapq.heapify(q) heapq.heappush(q, (0, source)) d = [float('inf') for _ in range(n)] d[source] = 0 while len(q) > 0: cur = heapq.heappop(q) cur_pos = cur[1] for next in g[cur_pos]: next_pos = next[0...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,976
s162046637
p02242
u088372268
1529808609
Python
Python3
py
Accepted
20
5724
952
n = int(input()) INF = 2147483647 M = [[INF for j in range(n)] for i in range(n)] check, dist = [0 for i in range(n)], [INF for i in range(n)] def dijkstra(s): p = [-1 for i in range(n)] dist[s] = 0 while True: min_cost = INF for i in range(n): if check[i] != 2 and dist[i] < ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,977
s913085186
p02242
u318430977
1530032486
Python
Python3
py
Accepted
30
6216
1,541
import heapq class Dijkstra: """ Dijkstra's algorithm: find the shortest paths from a vertex complexity: O(E + logV) """ def __init__(self, V, E, start, INF=10**9): """ :param V: the number of vertices :param E: adjacency list (all edge in E must be non n...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,978
s214752683
p02242
u007270338
1530285533
Python
Python3
py
Accepted
30
5872
965
#coding:utf-8 inf = 1000000 n = int(input()) M = [[inf for i in range(n)] for j in range(n)] for i in range(n): data = list(map(int,input().split())) u = data[0] k = data[1] for j in range(0,2*k,2): v, w = data[j+2], data[j+3] M[u][v] = w def dijkstra(s): color = ["white" for i in...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,979
s174549709
p02242
u007270338
1530294105
Python
Python3
py
Accepted
40
6240
1,062
#coding:utf-8 inf = 1000000 n = int(input()) M = [[inf for i in range(n)] for j in range(n)] vwMtrx = [] for i in range(n): data = list(map(int,input().split())) u = data[0] k = data[1] col = [] for j in range(0,2*k,2): v, w = data[j+2], data[j+3] M[u][v] = w col.append([v,w]...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,980
s317192194
p02242
u912237403
1376600460
Python
Python
py
Accepted
30
4816
1,083
import sys global nodes nodes = {} def shortest_path(GRAPH): global nodes p1 = 0 nodes[p1][1] = 0; edge={} total = 0 mini = 0 while True: nodes[p1][0]=True for p2 in range(len(nodes)): if nodes[p2][0]==False and GRAPH.has_key((p1, p2)): ...
p02242
<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>Single Source Shortest Path...
5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3
0 0 1 2 2 2 3 1 4 3
29,981