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
s254931527
p02242
u912237403
1376686777
Python
Python
py
Accepted
20
4684
1,116
import sys def shortest_path(GRAPH, distance): nodes = set() p1 = 0 distance[p1] = 0 while True: dp1 = distance[p1] gp1 = GRAPH[p1] status[p1]=1 for p2 in gp1.keys(): tmp = gp1[p2] + dp1 if status[p2]==0 and tmp < distance[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,982
s830577202
p02242
u782850731
1380766733
Python
Python
py
Accepted
30
4392
701
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin, maxint def main(): num = int(stdin.readline()) L = [] for _ in xrange(num): L.append([int(s) for s in stdin.readline().split()]) weight = [maxint] * num weight[0] = 0 V = set(xrange(1, num)) ...
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,983
s762778076
p02242
u782850731
1380767608
Python
Python
py
Accepted
20
4672
701
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin, maxint def main(): num = int(stdin.readline()) L = [] for _ in xrange(num): it = iter(int(s) for s in stdin.readline().split()[1:]) L.append([(next(it), next(it)) for _ in xrange(next(it))]) ...
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,984
s497632364
p02242
u733357255
1597857774
Python
Python3
py
Accepted
30
6232
739
from heapq import heappush, heappop import math def dijkstra(N, G, s): dist = [math.inf] * N que = [(0,s)] dist[s] = 0 ans = [[] for i in range(N)] while que: c,v = heappop(que) if dist[v] < c: continue for t, cost in G[v]: if dist[v] + 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,985
s011840775
p02242
u610447658
1597584790
Python
Python3
py
Accepted
40
6460
921
from heapq import heappush, heappop, heappushpop, heapreplace, heapify #隣接リスト作成 v = int(input()) edge_list = [[] for _ in range(v)] for i in range(v): l = list(map(int, input().split())) for j in range(1,l[1]+1): edge_list[l[0]].append([l[2*j+1],l[2*j]]) def dijkstra(v, edges, start): d = [float("...
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,986
s493541602
p02242
u880802684
1597566416
Python
Python3
py
Accepted
30
6420
1,370
from heapq import heappop, heappush from collections import defaultdict class Dijkstra: """Graph input: { node:{node:cost,node:cost...}, node:{node:cost,node:cost...}, ... } """ def __init__(self, graph: dict, N: int): self.graph = graph self.costs = [float("inf")] * 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,987
s624951258
p02242
u793520502
1597053265
Python
Python3
py
Accepted
30
5720
905
from sys import stdin input = stdin.readline infty = 100_000_00 def dijkstra(N): d[0] = 0 p[0] = -1 u = 0 while True: mincost = infty for i in range(N): if color[i] != 2 and d[i] < mincost: mincost = d[i] u = i color[u] = 2 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,988
s021209193
p02242
u914515588
1597040107
Python
Python3
py
Accepted
50
7324
2,273
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 = ...
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,989
s781255878
p02242
u233634805
1596519125
Python
Python3
py
Accepted
20
5812
2,792
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/12/ALDS1_12_B # プリムのアルゴリズムと似ているが、求めているものが異なる(MSTの経路は必ずしも任意の点と点をつなぐ最小経路とはならない)。 # 次手の候補となるリストDの更新の仕方がprimとは異なる INF = 10**6 + 1 # load datas N = int(input()) M = [[INF] * N for _ in range(N)] # 隣接行列 for _ in range(N): tmp = 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,990
s938409307
p02242
u434132766
1596053124
Python
Python3
py
Accepted
30
6208
866
import heapq n = int(input()) adj = [[] for _ in range(n)] for _ in range(n): tmp = list(map(int, input().split())) if tmp[1] != 0: node = tmp[0] for i in range(2, 2 + tmp[1] * 2, 2): adj[node].append((tmp[i], tmp[i + 1])) def dijkstra(s): visited = [0]*n d = [float("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,991
s969196936
p02242
u748843150
1594733874
Python
Python3
py
Accepted
20
5776
873
n=int(input()) inf=10000000 p=[-1 for i in range(n)] M=[[inf for j in range(n)] for i in range(n)] d=[inf for i in range(n)] color=["white" for i in range(n)] for i in range(n): tmp=list(map(int,input().split())) root=tmp[0] k=tmp[1] for j in range(k): v=tmp[2*(j+1)] M[root][v]=tmp[2*(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,992
s044906617
p02242
u878424017
1594456404
Python
Python3
py
Accepted
20
5740
712
n = int(input()) INF = float("inf") M = [[INF for _ in range(n)] for _ in range(n)] for _ in range(n): a,*b = map(int,input().split()) if b[0] != 0: c = b[1:] for i in range(len(c)//2): k,w = c[2*i],c[2*i+1] M[a][k] = w searched = [0]*n d = [INF]*n p = [None]*n d[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,993
s818604674
p02242
u450519077
1594451272
Python
Python3
py
Accepted
20
6180
562
import heapq N = int(input()) A = [[]for i in range(N)] for i in range(N): u, k, *nums = list(map(int,input().split())) for j in range(k): t = nums[j*2] c = nums[j*2+1] A[u].append([t, c]) memo = [1E18] * N memo[0] = 0 qu = [] heapq.heappush(qu,(0,0)) while len(qu) != 0: atop = he...
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,994
s303900701
p02242
u512884261
1591878202
Python
Python3
py
Accepted
30
6536
1,140
import sys, collections, heapq 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(): ...
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,995
s330127571
p02242
u951519498
1591622946
Python
Python3
py
Accepted
30
6500
1,042
#!/usr/bin/env python # -*- coding: utf-8 -*- # # FileName: single_source_shortest_path # CreatedDate: 2020-06-08 21:54:58 +0900 # LastModified: 2020-06-08 22:28:47 +0900 # import os import sys from collections import deque #import numpy as np #import pandas as pd def main(): n = int(input()) graph = [[] ...
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,996
s777289004
p02242
u800829827
1591538419
Python
Python3
py
Accepted
20
5716
1,167
import sys INFTY=sys.maxsize WHITE=0 GRAY=1 BLACK=2 def readinput(): n=int(input()) nMap=[] for _ in range(n): nMap.append([INFTY]*n) for _i in range(n): l=list(map(int,input().split())) i=l[0] for jj in range(l[1]): j=l[2+jj*2] w=l[2+jj*2+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,997
s641165514
p02242
u784856415
1590741366
Python
Python3
py
Accepted
30
6208
762
import sys import heapq input=sys.stdin.readline INF=2<<28 def dijkstra(G,start,n):#グラフ,初期頂点,頂点数 dist=[INF]*n;dist[start]=0 used=[False]*n;used[0]=True q=[] for v in G[start]: heapq.heappush(q,v) while len(q)>0: now=heapq.heappop(q) if used[now[1]]: contin...
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,998
s285389307
p02242
u176870835
1590741314
Python
Python3
py
Accepted
20
6136
782
def shortest_path(V,uvc,start=0): distances = [INF]*V distances[start] = 0 parents = list(range(V)) for _ in range(V): modified = False for src,dst,cost in uvc: if distances[dst] > distances[src] + cost: distances[dst] = distances[src] + 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,999
s940638898
p02242
u119355204
1590713543
Python
Python3
py
Accepted
20
5848
1,085
N = int(input()) #M[u][v]:隣接行列 M=[] for n in range(N): input_temp=list(map(int,input().split())) M_temp=[-1]*N for k in range(0,2*input_temp[1],2): M_temp[input_temp[2+k]]=input_temp[2+k+1] M.append(M_temp) #color:各頂点の訪問状態を示す color=['white']*N #d:TとV-Tを繋ぐ辺の中で重みが最小の辺の重みの値を保持 d=[10**10]*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
30,000
s944239875
p02242
u798363880
1590226224
Python
Python3
py
Accepted
30
5720
749
N=int(input()) rinsetu=[[1000000 for i in range(N)] for j in range(N)] d=[1000000]*(N) color=["white"]*N for i in range(N): a=list(map(int,input().split())) for j in range(a[1]): j1=j*2+2 j2=j*2+3 rinsetu[i][a[j1]]=a[j2] def hunterhunter(): d[0]=0 while(True): mincost=100...
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
30,001
s769675933
p02242
u124936061
1589752476
Python
Python3
py
Accepted
30
5936
647
import sys readline = sys.stdin.readline from heapq import heapify, heappush, heappop INF = float("inf") def MAIN(): n = int(input()) adj = [[]] * n for _ in range(0, n): U = list(map(int, input().split())) adj[U[0]] = zip(U[2::2], U[3::2]) def dijkstra(): d = [0] + [INF] * (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
30,002
s266972518
p02242
u590535211
1589523053
Python
Python3
py
Accepted
80
5868
934
n = int(input()) C = [[] for _ in range(n)] for _ in range(n): tmp = list(map(int,input().split())) for i in range(1,tmp[1]+1): C[tmp[0]].append(tuple(tmp[2*i:2*i+2])) def dijkstra(start = 0): INF = 100000000 d = [INF]*n visited = [False]*n d[start] = 0 visited[start] = True 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
30,003
s429169575
p02242
u525329683
1589204393
Python
Python3
py
Accepted
30
6944
1,569
def graph_to_edges(graph): '''(cosr,from,to)を要素に持つリストに変換 未verify''' # edgeへの変換 edges = [] for ot, v in graph.items(): for to, c in v: edges.append((c, ot, to)) return edges def bellman_ford(edges, s, N): ''' edges ... (cost,from,to)を各要素に持つリスト s...始点ノード 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
30,004
s114599354
p02242
u528145125
1589037560
Python
Python3
py
Accepted
20
6236
698
import heapq n=int(input()) u=[0]*n k=[0]*n v=[0]*n z=[[] for _ in range(n) ] for i in range(n): u[i],k[i],*v[i] = map(int,input().split()) for j in range(0,len(v[i]),2): z[i].append([v[i][j],v[i][j+1]]) d=[float("inf")]*n e=[-1] *n #いったことなければ -1 def dijkstra(x): e[x]=0 #ブクマ d[x]=0 q= [ (d[x],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
30,005
s588849828
p02242
u907647136
1588937026
Python
Python3
py
Accepted
30
6300
843
def V_dijkstra(V,AL,S): INF=float('inf') ans=[INF]*V ans[S]=0 used=[0]*V # 0:未確定 used[S]=1 que=[i for i in range(V)] while que: u=min(que,key=lambda x: ans[x]) que.pop(que.index(u)) used[u]=1 for v,w in AL[u]: if not used[v] and ans[v]>ans[u]+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
30,006
s508888447
p02242
u613396167
1588877841
Python
Python3
py
Accepted
30
5952
1,001
import sys input = sys.stdin.readline def dijkstra_v2(start: int, matrix: list) -> list: """dijkstra法: 始点startから各頂点への最短距離を求める 計算量: O(V^2) """ INF = 10 ** 18 n = len(matrix) used = [False] * n dist = [INF] * n dist[start] = 0 while True: v = -1 for u 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
30,007
s878351103
p02242
u976514673
1588716625
Python
Python3
py
Accepted
40
6552
659
import sys from collections import namedtuple from heapq import heappop, heappush Edge = namedtuple('Edage', 'to cost') P = namedtuple('P', 'cost u') N = int(input()) G = [[] for _ in range(N)] for u in range(N): args = [int(x) for x in input().split()] # 不要な値を捨てる args.pop(0) args.pop(0) while args: ...
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
30,008
s068755976
p02242
u720435112
1588557975
Python
Python3
py
Accepted
30
6116
1,006
# 単一視点最短経路, Dijkstra(ダイクストラ)のアルゴリズム from collections import deque n = int(input()) # グラフの作成 INF = float('inf') M = [[INF]*n for _ in range(n)] d = [INF]*n for _ in range(n): u, k, *v = map(int, input().split()) if k == 0: continue cnt = 0 for _ in range(k): M[u][v[cnt]] = v[cnt+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
30,009
s392094935
p02242
u486183171
1588410659
Python
Python3
py
Accepted
20
5724
650
INF = float('inf') N = int(input()) D = [INF] * N Visited = [False] * N M = [[INF] * N for _ in range(N)] for _ in range(N): u, k, *cv = map(int, input().split()) for i in range(0, len(cv), 2): c, v = cv[i], cv[i + 1] M[u][c] = v D[0] = 0 while True: min_cost = INF u = -1 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
30,010
s902613424
p02242
u815830103
1588303923
Python
Python3
py
Accepted
30
6288
969
class Graph: def __init__(self,V,E): self.V = V self.E = E def WF(self,st): N,INF = len(self.V),10**7+1 dp = [INF for _ in range(N)] #dp[i]:頂点stから頂点iへの最小距離 dp[st] = 0 update = True while update: update = False for i in rang...
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
30,011
s720597154
p02242
u123563150
1588136433
Python
Python3
py
Accepted
20
6208
602
n=int(input()) inf=10**15;d=[inf]*n;d[0]=0 node=[[]for _ in range(n)] for i in range(n): x=list(map(int,input().split())) for j in range(x[1]): node[i].append((x[j*2+2],x[j*2+3])) dis=[[inf]*n for _ in range(n)] for i in range(n): dis[i][i]=0 for i in range(n): for x in node[i]: dis[i][x[0]]=x[1] s=[False]*n wh...
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
30,012
s193822578
p02242
u940492895
1588022393
Python
Python3
py
Accepted
20
5860
834
# 単一始点最短経路 Single source shortest path I INFTY = 2000000000 n = int(input()) M = [[INFTY for i in range(n)] for i in range(n)] for i in range(n): dat = [int(i) for i in input().split()] for j in range(1, dat[1] + 1): M[dat[0]][dat[2 * j]] = dat[2 * j + 1] col = [-1 for i in range(n)] d = [INFTY 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
30,013
s648415938
p02242
u259225866
1587196818
Python
Python3
py
Accepted
20
6184
1,721
import sys input = sys.stdin.buffer.readline import heapq #点の数が10**5のオーダー以下で使える #頂点sからの各頂点への最短距離を出力 def dijkstra(s, n, edge): #s:始点、n:頂点の数、edge:重み付き辺の配列(edge[i]:iから出る[重み、行き先]の配列) INF = 10**20 d = [INF]*n # d[i]: sと点iとの距離 used = [True]*n #Trueは未確定 d[s] = 0 #初期条件 used[s] = False # 初期条件 edge_list...
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
30,014
s800847311
p02242
u836197361
1587015273
Python
Python3
py
Accepted
30
6348
700
from heapq import heappop, heappush if __name__ == '__main__': n = int(input()) graph = [[-1]*n for i in range(n)] for i in range(n): node_data = list(map(int, input().split())) index = node_data[0] edge_num = node_data[1] node_list = node_data[2:] for i in range(edge_num): graph[index][node_list[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
30,015
s887893798
p02242
u557098739
1586973914
Python
Python3
py
Accepted
20
6576
1,097
n = int(input()) ukvc = [ list(map(int,input().split())) for _ in range(n) ] g = [ [] for _ in range(n) ] for i in range(n): ls = ukvc[i] u = ls[0] k = ls[1] vc = ls[2:] for j in range(k): v = vc[2*j] c = vc[2*j+1] g[u].append([c,v]) # print(g) # Dijkstra法(O(ElogV)) # 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
30,016
s543291219
p02242
u258049727
1586690607
Python
Python3
py
Accepted
20
5716
1,318
INF = float("inf") white = 0; gray = 1; black =2 def dijkstra(s): # 頂点sをrootに設定 mindist[s] = 0 while True: #最短経路木に頂点(最短経路木とつながる最小コストの辺を持つ頂点)を追加 mincost = INF u = -1 for i in range(n): if color[i] != black and mindist[i] < mincost: mincost = mind...
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
30,017
s143044511
p02242
u146816547
1586488946
Python
Python3
py
Accepted
20
6204
900
import heapq def dijkstra(start_v, G): n = len(G) dist = [0 if i == start_v else float("inf") for i in range(n)] que = [] heapq.heappush(que, (0, start_v)) while que: cur_d, cur_v = heapq.heappop(que) if dist[cur_v] < cur_d: continue for adj in G[cur_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
30,018
s287342120
p02242
u820842907
1585983639
Python
Python3
py
Accepted
20
5784
1,158
def Single_Source_Shortest_Path(adj_mat, cost, parent): N = len(cost) color = ["W" for n in range(N)] parent[0] = -1 cost[0] = 0 while True: mincost = 1000000 for i in range(N): if color[i] != "B" and cost[i] < mincost: u = i mincost = 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
30,019
s677540166
p02242
u737337423
1585803720
Python
Python3
py
Accepted
20
5744
528
# Single Source Shortest Path 1 INF = 10**10 N = int(input()) W = [[INF]*(N) for _ in [0]*(N)] for _ in [0]*N: v, k, *A = map(int, input().split()) for u, c in zip(*[iter(A)]*2): W[v][u] = c S = set() d = [INF]*N d[0] = 0 while len(S) < N: dmin = INF v = -1 for i in range(N): if 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
30,020
s207451856
p02242
u838900850
1585613792
Python
Python3
py
Accepted
20
6168
705
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((inf[1])): e[inf[0]].append([inf[2+j*2],inf[2+j*2+1]]) dp = [INF]*n dp[0] = 0 pq = [[0,0]] heapq...
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
30,021
s768146456
p02242
u577681189
1585460258
Python
Python3
py
Accepted
40
7196
1,502
import queue INFTY=1<<21 #ダイクストラ法 def dijkstra(n,EdgeMatrix): NodeList=queue.PriorityQueue() #探索対象の頂点 Distance=[INFTY]*n #頂点0からの最短経路 used=[False]*n #頂点の使用情報 Distance[0]=0 #0から0までの距離は0 used[0]=True #0から探索を始める LastNode=0 #最新の頂点 count=1 #つないだ頂点の数 while count<n: 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
30,022
s657113234
p02242
u230072054
1585064837
Python
Python3
py
Accepted
40
7404
1,271
import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush, heappop #------------------------------------------# BIG_NUM = 2000000000 HUGE_NUM = 9999999999999999 MOD = 1000000007 EPS = 0.000000001 #------------------------------------------# class Edge: d...
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
30,023
s163384178
p02242
u217435805
1584588170
Python
Python3
py
Accepted
20
5752
1,184
def createMatrix(): matrix = [[INFTY] * n for i in range(n)] for i in range(n): u, k, *v = map(int, input().split()) for j in range(0, k*2, 2): matrix[i][v[j]] = v[j+1] return matrix def dijkstra(): d[0] = 0 p[0] = -1 while True: mincost = INFTY # 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
30,024
s736416395
p02242
u327242612
1584156042
Python
Python3
py
Accepted
30
6408
1,849
if __name__ == '__main__': from sys import stdin input = stdin.readline import heapq from copy import deepcopy INFTY = 2**21 WHITE = 0 GRAY = 1 BLACK = 2 n = int(input()) M = [[INFTY]*n for _ in range(n)] for _ in range(n): u, k, *vc = 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
30,025
s119356075
p02242
u925219592
1583930195
Python
Python3
py
Accepted
20
5776
1,182
def dijkstra(n, s): inf = float('inf') color = ['white' for _ in range(n)] D = [inf for _ in range(n)] P = [0 for i in range(n)] M = [[inf for _ in range(n)] for _ in range(n)] for i in range(n): weight = list(map(int, input().split()))[2:] for j in ra...
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
30,026
s992635657
p02242
u357050809
1583735603
Python
Python3
py
Accepted
50
6616
878
import sys from heapq import * MAX_INT= 10 ** 10 n = int(input()) adj_list = [] for _ in range(n): commands = sys.stdin.readline().split() lst = [ commands[i:i+2] for i in range(2, len(commands), 2)] adj_list.append(lst) def dijkstra(): # initialization visited = [False] * n dist_arr = [MAX_INT] * n 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
30,027
s375306778
p02242
u357267874
1583021251
Python
Python3
py
Accepted
30
6532
723
from collections import defaultdict n = int(input()) graph = defaultdict(list) for _ in range(n): u, k, *edges = map(int, input().split()) for i in range(0, len(edges), 2): graph[u].append((edges[i], edges[i+1])) # print(graph) s = 0 d = [float('inf')] * (n) fixed = [False] * (n) d[0] = 0 while 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
30,028
s798929233
p02242
u629780968
1582516927
Python
Python3
py
Accepted
20
6884
1,057
n = int(input()) INF = float("inf") edges = [[] for _ in range(n)] visited = [False]*n # edges = [[INF for _ in range(n)] for _ in range(n)] edges = [[] for _ in range(n) for _ in range(n)] d = [INF]*n d[0] = 0 for _ in range(n): ls = list(map(int, input().split())) u = ls[0] degrees = ls[1] data = ls[...
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
30,029
s094670706
p02242
u136916346
1582254575
Python
Python3
py
Accepted
30
6224
1,249
from heapq import heappop, heappush def dijkstra1(g, source): # O(ElogV) n = len(g) inf = float("inf") # 高速化のためにはfloat("inf")ではないほうがいい dist = [inf] * n dist[source] = 0 q = [(0, source)] while q: cost, u = heappop(q) if dist[u] < cost: continue for c, 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
30,030
s006708156
p02242
u078455793
1581756828
Python
Python3
py
Accepted
40
5872
850
# input n = int(input()) A = [[-1] * n for i in range(n)] for _ in range(n): line = list(map(int, input().split())) u = line.pop(0) k = line.pop(0) for i in range(k): v = line.pop(0) c = line.pop(0) A[u][v] = c # 変数定義 inf = 100 * 100000 + 1 M = A.copy() M = [[a if a > -1 els...
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
30,031
s328217003
p02242
u457728280
1581411842
Python
Python3
py
Accepted
20
5724
871
def dijkstra(): d[0] = 0 color[0] = GRAY while True: minv = INF u = -1 for i in range(N): if minv > d[i] and color[i] != BLACK: u = i minv = d[i] if u == -1: break color[u] = BLACK 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
30,032
s322398052
p02242
u647694976
1580869328
Python
Python3
py
Accepted
20
5772
892
def dijkstra(n,s): inf=float("inf") color=["white" for i in range(n)] 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)] for i in range(n): weight=list(map(int,input().split()))[2:] for j in range(len(weight)//2): M[i][wei...
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
30,033
s667878504
p02242
u369455271
1580225695
Python
Python3
py
Accepted
30
6012
1,055
inf = float("inf") class Node(): def __init__(self, _id): self.id = _id self.d = inf self.pi = None self.color = 0 self.adj = {} def input_data(self, data): k = data[0] for i in range(k): self.adj[G[data[2 * i + 1]]] = data[2 * i + 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
30,034
s960844042
p02242
u894062759
1578374212
Python
Python3
py
Accepted
30
6496
998
from collections import deque n = int(input()) g = [] d = [10**10] * n d[0] = 0 for i in range(n): temp = list(map(int, input().split())) k = temp[1] temp = temp[2:] adj = [] for j in range(k): v, c = temp[j*2], temp[j*2+1] adj.append([v, c]) g.append(adj) # 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
30,035
s283160757
p02242
u529459816
1577550369
Python
Python3
py
Accepted
30
5840
1,354
def dijkstra(adj_matrix, n): dist = [float("inf") for _ in range(n)] visited = [False for _ in range(n)] parent = [-1 for _ in range(n)] start = 0 dist[start] = 0 visited[start] = True while True: for end in range(n): # startから出ているノードの距離を計算 if not visited[en...
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
30,036
s701879051
p02242
u794140916
1576028112
Python
Python3
py
Accepted
20
5728
928
# coding: utf-8 # Your code here! WHITE = 0 GRAY = 1 BLACK = 2 INF = 2000000000 def dijkstra(s): while True: u = 0 mincost = INF for i in range(n): if color[i] != BLACK and d[i] < mincost: mincost = d[i] u = i if mincost...
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
30,037
s125822855
p02242
u608189632
1574007688
Python
Python3
py
Accepted
30
5712
1,123
def dijkstra(): global n, color, M, d, p min_value = 1000000 d[0] = 0 color[0] = 'GRAY' while True: min_value = 1000000 u = -1 for i in range(n): if min_value > d[i] and color[i] != 'BLACK': u = i min_value = d[i] if 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
30,038
s288404168
p02242
u137240270
1573433623
Python
Python3
py
Accepted
40
5788
1,087
N = 100 WHITE = 0 GRAY = 1 BLACK = 2 INF = float('inf') M = None d = [INF for _ in range(N)] p = [0 for _ in range(N)] color = [WHITE for _ in range(N)] n = 0 def main(): global n, M n = int(input()) M = [[INF for _ in range(n)] for _ in range(n)] for i in range(n): _, k, *v_s = map(int, inp...
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
30,039
s592057278
p02242
u537758214
1572848713
Python
Python3
py
Accepted
20
6160
931
def main(): N = int(input()) G = [[] for _ in range(N)] for _ in range(N): u, k, *vc = (int(i) for i in input().split()) for i in range(0, len(vc), 2): G[u].append((vc[i], vc[i+1])) d = [[(1 << 63)-1, i] for i in range(N)] from heapq import heapify, heappop, heappush ...
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
30,040
s507934534
p02242
u957523223
1572773585
Python
Python3
py
Accepted
50
7716
1,637
import argparse import sys inf = sys.maxsize import heapq def dijkstra_heap(edge_list, node): distance_list = n_node * [inf] distance_list[node] = 0 heap = [] heapq.heappush(heap, (0, 0)) while(heap): temp_dist, from_node = heapq.heappop(heap) if distance_list[from_node] < temp...
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
30,041
s995233475
p02242
u909811933
1572577516
Python
Python3
py
Accepted
70
6204
823
from heapq import heappush,heappop,heapify n = int(input()) G = [[] for _ in range(n)] info = [] for i in range(n): info = list(map(int,(input().split())))[2:] for j in range(int((len(info))/2)): G[i].append((info[2*j],info[2*j+1])) color = ["white" for _ in range(n)] dist = [(1<<21) for _ in range(...
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
30,042
s671031630
p02242
u639928232
1572537691
Python
Python3
py
Accepted
20
6212
778
#!/usr/bin/env python3 import sys import heapq input = lambda: sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) inf = float('inf') mod = 10**9+7 n=int(input()) G=[[] for i in range(n)] for _ in range(n): inp = list(map(int,input().split())) u,k=inp[:2] for i in range(k): G[u].append((inp[2+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
30,043
s994717771
p02242
u121563294
1571451606
Python
Python3
py
Accepted
20
6140
491
N = int(input()) E = [None] * N for _ in range(N): u, k, *vs = map(int, input().split()) E[u] = [] for i in range(k): v, c = vs[i*2], vs[i*2+1] E[u].append((v, c)) vis = [False] * N inf = 1e9 d = [inf] * N d[0] = 0 for _ in range(N): nv, ni = inf, -1 for i in range(N): if 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
30,044
s330450451
p02242
u778781355
1571141255
Python
Python3
py
Accepted
20
5876
823
INF = 100000 * 100 def dijkstra(s: int) -> None: d[s] = 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 range(n): if color[v] != "BLACK" and M[u][v] != None: if d[u] + M...
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
30,045
s322265896
p02242
u367619546
1570945236
Python
Python3
py
Accepted
30
5832
1,105
# ALDS1_12_V Single Source Shortest Path I import sys n = int(input()) G = [[float('inf')] * n for _ in range(n)] for i in range(n): ukvc = list(map(int, sys.stdin.readline().strip().split())) u = ukvc[0] k = ukvc[1] for j in range(k): G[u][ukvc[2 + 2 * j]] = ukvc[3 + 2 * j] p = [n] * 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
30,046
s552528560
p02242
u153665391
1569892191
Python
Python3
py
Accepted
20
5732
616
N = int(input()) INF = 10**9 M = [[-1 for i in range(N)] for j in range(N)] for i in range(N): u, k, *vs = list(map(int, input().split())) for j in range(k): v, c = vs[2*j], vs[2*j+1] M[u][v] = c d = [INF for i in range(N)] d[0] = 0 p = [-1 for i in range(N)] mst = [False for i in range(N)] while 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
30,047
s072664498
p02242
u134521115
1569753887
Python
Python3
py
Accepted
20
5808
944
import sys input = sys.stdin.readline INF = 100100 def dijkstra(M: list, u: int = 0) -> list: global N d = [INF] * N d[u] = 0 visited = [False] * N while True: mincost = INF for i in range(N): if not visited[i] 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
30,048
s267476098
p02242
u183700122
1569232463
Python
Python3
py
Accepted
30
6636
932
from heapq import heappush, heappop from collections import deque def main(): INF = float('inf') V = int(input()) dist = [INF] * V visited = [False] * V graph = [None] + [deque() for i in range(V-1)] q = [] tmp = list(map(int, input().split())) for i in range(tmp[1]): heappush(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
30,049
s469273376
p02242
u631142478
1566554721
Python
Python3
py
Accepted
20
5744
905
def dijkstra(matrix, s): INF = 200000 n = len(matrix) state, d, p = [False] * n, [INF] * n, [-1] * n d[s] = 0 while True: mincost = INF for i in range(n): if not state[i] and d[i] < mincost: mincost = d[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
30,050
s802544647
p02242
u470586273
1565269821
Python
Python3
py
Accepted
30
5812
474
V=int(input()) inf=10**9 cost=[[inf]*V for _ in range(V)] for i in range(V): l=list(map(int,input().split())) for j in range(l[1]): v,c=l[2*j+2],l[2*j+3] cost[i][v]=c d=[inf]*V d[0]=0 used=[0]*V while True: v=-1 for u in range(V): if (not used[u] and (v==-1 or d[u]<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
30,051
s903659237
p02242
u817810878
1565183122
Python
Python3
py
Accepted
60
7676
966
from heapq import heappush, heappop from typing import List, Tuple import sys if __name__ == "__main__": num_vertices = int(input()) adj_list: List[List[Tuple[int, int]]] = [[] for _ in range(num_vertices)] for _ in range(num_vertices): vertex, adj_num, *adjs = map(lambda x: int(x), 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
30,052
s685869510
p02242
u638043175
1564489612
Python
Python3
py
Accepted
30
5816
814
import sys input = sys.stdin.readline INF = 10**9 WHITE = -100 GRAY = -1000 BLACK = -10000 def main(): m = int(input().strip()) s = [[-1] * m for _ in range(m)] for i in range(m): l = list(map(int, input().strip().split())) for j in range(l[1]): s[i][l[2 + 2 * j]] = l[3 + 2 * j] color = [WHITE] * m 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
30,053
s495061457
p02242
u135880652
1562384290
Python
Python3
py
Accepted
40
5824
873
INF = 1.0e+6 WHITE = 0 BLACK = 1 def dijkstras(M): n = len(M) d = [INF] * n color = [WHITE] * n d[0] = 0 while True: minv = INF u = -1 for i in range(n): if d[i] < minv and color[i] != BLACK: u = i minv = d[i] if u == -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
30,054
s243261875
p02242
u902579831
1561722351
Python
Python3
py
Accepted
20
5748
992
INFINITY = 10 ** 10 WHITE = 0 GRAY = 1 BLACK = 2 n = int(input()) M = [[INFINITY] * n for _ in range(n)] for _ in range(n): u, k, *list_num = map(int, input().split()) for i in range(0, k * 2, 2): M[u][list_num[i]] = list_num[i + 1] d = [INFINITY] * n def dijkstra(): color = [WHITE] * n 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
30,055
s016489979
p02242
u574566605
1561124677
Python
Python3
py
Accepted
20
5728
961
WHITE = 0 GRAY = 1 BLACK = 2 INFTY = 10**13 def dijkstra(s): color = [WHITE for i in range(N)] d = [INFTY for i in range(N)] p = [-1 for i in range(N)] d[s] = 0 while True: mincost = INFTY for i in range(N): if color[i] != BLACK and d[i] < mincost: 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
30,056
s986702422
p02242
u100569186
1560856112
Python
Python3
py
Accepted
20
5828
852
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 = [[-1]*N for _ in range(N)] for i in range(N): input_list = list(map(int, input().split())) ii = input_list.pop(0) k = input_list.pop(0) jj = 0 while jj <= 2*k - 2: M...
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
30,057
s136055748
p02242
u970810709
1559799751
Python
Python3
py
Accepted
20
6132
547
n = int(input()) G = [[] for i in range(n)] for ni in range(n): u, k, *tmp = [int(i) for i in input().split()] for ki in range(k): G[ni].append(tmp[:2]) del tmp[:2] INF = 100*100000 D = [INF for i in range(n)] D[0] = 0 C = [0 for i in range(n)] while 0 in C: U = [INF if C[i] == 1 else 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
30,058
s471883951
p02242
u350698365
1559743127
Python
Python3
py
Accepted
30
6124
1,258
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
30,059
s123937229
p02242
u821080069
1559652156
Python
Python3
py
Accepted
40
5772
926
n = int(input()) global S, Q, l S = [0] Q = [0] l = [1000000 for _ in range(n)] l[0] = 0 graph = [[-1 for _ in range(n)] for _ in range(n)] def input_graph(n): for _ in range(n): node_id, k, *v_list = list(map(int, input().split())) for j in range(k): ad_node, w = v_list[2*j], v_list[2*j+1] graph[...
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
30,060
s093460744
p02242
u597769560
1558533461
Python
Python3
py
Accepted
30
5964
1,314
# -*- coding: utf-8 -*- """ Created on Tue May 21 23:08:18 2019 @author: Yamazaki Kenichi """ n = int(input()) A = [list(map(int,input().split())) for i in range(n)] INFTY = 10**6 M = [[INFTY for i in range(n)] for i in range(n)] for a in A: u, k = a[0], a[1] for i in range(k): M[u][a[i*2+2]] = a[i*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
30,061
s838296791
p02242
u454636644
1558265603
Python
Python3
py
Accepted
20
5816
1,170
def dijkstra(n): distance_list[0] = 0 while True: min_distance = 10**9 u = -1 for i in range(n): distance = distance_list[i] if flag_list[i] < 2 and distance < min_distance: min_distance = distance u = i if u == -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
30,062
s420760216
p02242
u805716376
1556967988
Python
Python3
py
Accepted
20
5824
679
n = int(input()) adj = [[float('inf')]*n for _ in range(n)] for i in range(n): a = list(map(int, input().split())) for j,k in zip(a[2::2], a[3::2]): adj[i][j] = k color = [0]*n d = [float('inf')]*n d[0] = 0 while 1: mincost = float('inf') for i in range(n): if color[i] != 1 and d[i] < m...
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
30,063
s976467881
p02242
u967553879
1555573540
Python
Python3
py
Accepted
30
6124
788
n = int(input()) M = {} for _ in range(n): u, k, *line = map(int, input().split()) tmp = [] for i in range(k): v, w = line[2*i:2*i+2] tmp.append((v, w)) M[u] = tmp INF = 10**10 WHITE = 0 GREY = 1 BLACK = 2 d = [INF] * n color = [WHITE] * n p = [-1] * n def dijkstra(): d[0] = 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
30,064
s349921385
p02242
u697264006
1555144050
Python
Python3
py
Accepted
30
6568
636
from sys import stdin from collections import defaultdict from heapq import heappush, heappop import math n = int(input()) g = defaultdict(list) for i in range(n): l = list(map(int, stdin.readline().split())) s = l[0] k = l[1] t = l[2:] for j in range(0, 2*k, 2): g[s].append((t[j+1], t[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
30,065
s276049584
p02242
u062898953
1554190951
Python
Python3
py
Accepted
30
5764
601
n = int(input()) g = [[2**64]*n for i in range(n)] for i in range(n): u, k, *l, = map(int, input().split()) for j in range(k): v, c = l[j*2], l[j*2+1] g[u][v] = c ''' ダイクストラ法による単一始点最短経路 ''' d = [2**64]*n d[0] = 0 s = [] v = [i for i in range(n)] while len(s) < n: c, u = 2**32, -1 for 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
30,066
s096440941
p02242
u463990569
1550622725
Python
Python3
py
Accepted
30
6612
746
import heapq def dijkstra(graph, weights, s): d = {u: float('inf') for u in graph} d[s] = 0 queue = [] heapq.heappush(queue, (0, s)) while queue: w, u = heapq.heappop(queue) for v in graph[u]: d_temp = d[u] + weights[u, v] if d[v] > d_temp: d[...
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
30,067
s210985638
p02242
u798796508
1548909298
Python
Python3
py
Accepted
20
5928
741
n = int(input()) data = [list(map(int, input().split())) for _ in range(n)] INF = 10000000000000000000 M = [[-1]*n for _ in range(n)] for i in data: for j in range(i[1]): M[i[0]][i[2+j*2]] = i[3+j*2] color = ['White']*n d = [INF]*n p = [None]*n d[0] = 0 p[0] = -1 while True: minct = INF for i in r...
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
30,068
s890097854
p02242
u598814210
1548642923
Python
Python3
py
Accepted
50
6984
2,770
import heapq class Graph(object): class Node: def __init__(self, dist: int, number: int): self.dist = dist self.number = number def __lt__(self, other): return self.dist < other.dist \ or (self.dist == other.dist and 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
30,069
s854364952
p02242
u297183174
1546914957
Python
Python3
py
Accepted
20
6200
953
import sys input = sys.stdin.readline # import heapq import heapq # graph: 隣接リスト (頂点、距離)の順に格納 # start: 始点 (0-index) # n: 頂点数 # memo[t]: startからtまでの最短距離 # return memo def dijkstra(graph, start, n): INF = float('inf') memo = [INF] * n memo[start] = 0 q = [(0, start)] while q: dist, ver = ...
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
30,070
s604744957
p02242
u800534567
1544943316
Python
Python3
py
Accepted
20
6056
841
import sys import math n = int(sys.stdin.readline()) Q = set() out_edge = [set() for _ in range(n)] weight = [[0] * n for _ in range(n)] for _ in range(n): ll = list(map(int, sys.stdin.readline().split())) sn = ll[0] Q.add(sn) for j in range(ll[1]): en = ll[2+2*j] cn = ll[2+2*j+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
30,071
s412784940
p02242
u125481461
1541876681
Python
Python3
py
Accepted
70
6516
1,051
import sys from collections import defaultdict def main(): n = int(input()) lines = sys.stdin.readlines() vertex_weights = defaultdict(list) for i in range(n): u, k, *vtx_wght = map(int, lines[i].split()) for v_i in range(k): vertex_weights[u].append((vtx_wght[2*v_i], vtx_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
30,072
s640200738
p02242
u637322311
1541319599
Python
Python3
py
Accepted
30
6120
1,149
from sys import stdin from collections import deque def read_graph(n): A = [ [-1]*(n+1) for _ in range(n+1) ] for _ in range(n): line = deque(stdin.readline().strip().split()) u = line.popleft() line.popleft() for l, k in enumerate(line): if l % 2 == 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
30,073
s004512582
p02242
u487861672
1540034088
Python
Python3
py
Accepted
20
5884
1,101
from sys import maxsize WHITE = 0 GRAY = 1 BLACK = 2 def read_adj(): n = int(input()) adj_list = [[] for _ in range(n)] for i in range(n): u, _, *rest = [int(x) for x in input().split()] for i in range(0, len(rest) - 1, 2): adj_list[u].append((rest[i], rest[i + 1])) retur...
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
30,074
s649472100
p02242
u697145890
1539784670
Python
Python3
py
Accepted
50
7404
1,270
import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush, heappop #------------------------------------------# BIG_NUM = 2000000000 HUGE_NUM = 9999999999999999 MOD = 1000000007 EPS = 0.000000001 #------------------------------------------# class Edge: d...
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
30,075
s674439565
p02242
u256748051
1534557640
Python
Python
py
Accepted
10
5744
529
import Queue n = int(input()) alist = [[] for i in range(n)] for i in range(n): arr = map(int,raw_input().split()) v,k = arr[0],arr[1] for j in range(k): alist[v].append([arr[2+j*2+1],arr[2+j*2]]) dist = [float("inf") for i in range(n)] dist[0] = 0 q = Queue.PriorityQueue() q.put([dist[0],0]) while not q.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
30,076
s438604834
p02242
u578148790
1534063625
Python
Python3
py
Accepted
20
5712
981
INFTY = 1 << 21 WHITE = 0 GRAY = 1 BLACK = 2 def dijkstra(n, m): d = [INFTY] * n color = [WHITE] * n d[0] = 0 color[0] == GRAY while True: minv = INFTY u = -1 for i in range(n): if minv > d[i] and color[i] != BLACK: u = i minv = ...
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
30,077
s416272056
p02242
u269568674
1533006202
Python
Python3
py
Accepted
20
5732
417
n=int(input()) d=[0]+[1e6]*n c=[1]*n M=[[-1]*n for _ in[0]*n] for _ in[0]*n: data=list(map(int,input().split())) for i in range(data[1]):k=2*-~i;M[data[0]][data[k]]=data[k+1] 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]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
30,078
s421407281
p02242
u940395729
1533006117
Python
Python3
py
Accepted
20
5864
970
def dijkstra(s): color = ["white" for i in range(n)] d = [inf 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] u = 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
30,079
s203019235
p02242
u424720817
1532406373
Python
Python3
py
Accepted
30
5860
600
n = int(input()) a = [] for i in range(n): b = list(map(int, input().split())) c = [-1] * n for j in range(b[1]): c[b[2 + j * 2]] = b[3 + j * 2] a.append(c) m = [float('inf')] * n f = [0] * n m[0] = 0 f[0] = 1 v = 0 for i in range(n-1) : for j in range(n) : if (a[v][j] + m[v] < m[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
30,080
s999997075
p02242
u281836941
1512710495
Python
Python3
py
Accepted
40
7552
772
# coding: utf-8 import queue nodelist={} n=int(input()) dist={} used={} for i in range(n): line=list(map(int,input().split())) nodelist[line[0]]=[] dist[line[0]]=99999999 used[line[0]]=False j=2 while True: try: nodelist[line[0]].append((line[j],line[j+1])) j+=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
30,081