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
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s694708048
p03634
u407160848
1580783820
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38384
1179
import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def s(generator, splitter, mapper): return [ mapper(s) for s in generator().split(splitter) ] # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")] # 改行区切りの入...
s509129951
p03634
u600402037
1579920064
Python
Python (3.4.3)
py
Runtime Error
2110
1829056
502
import sys import numpy as np from scipy.sparse.csgraph import shortest_path sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() graph = np.zeros((N, N)) #0-indexed for _ in range(N-1): a, b, c = lr() graph[a-1, b-...
s755187220
p03634
u600402037
1579920009
Python
Python (3.4.3)
py
Runtime Error
2111
1829180
493
import sys import numpy as np from scipy.sparse.csgraph import shortest_path sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() graph = np.zeros((N, N)) #0-indexed for _ in range(N-1): a, b, c = lr() graph[a-1, b-...
s046536792
p03634
u600402037
1579919629
Python
Python (3.4.3)
py
Runtime Error
2111
1829056
479
import sys import numpy as np from scipy.sparse.csgraph import shortest_path sys.setrecursionlimit(10 ** 7) sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() graph = np.zeros((N, N)) #0-indexed for _ in range(N-1): a, b, c = lr() graph[a-1, b-...
s720845760
p03634
u600402037
1579919567
Python
Python (3.4.3)
py
Runtime Error
2111
1827160
448
import sys import numpy as np from scipy.sparse.csgraph import shortest_path sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() graph = np.zeros((N, N)) #0-indexed for _ in range(N-1): a, b, c = lr() graph[a-1, b-1] = c dist = shortest_path(gr...
s693210220
p03634
u318127926
1579907506
Python
Python (3.4.3)
py
Runtime Error
819
50736
584
import sys n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k -= 1 xy = [] for _ in range(q): x, y = map(int, input().split()) x-=1 y-=1 ...
s769081422
p03634
u318127926
1579906804
Python
PyPy3 (2.4.0)
py
Runtime Error
1346
112288
556
import sys n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k -= 1 xy = [] for _ in range(q): x, y = map(int, input().split()) x-=1 y-=1 ...
s024397869
p03634
u721316601
1579742094
Python
Python (3.4.3)
py
Runtime Error
598
43976
656
import sys from heapq import heappush, heappop, heapify input = sys.stdin.readline def dfs(v, c, p=-1): dist[v] = c for u, d in g[v]: if u == p: continue dfs(u, c+d, v) def main(): for i in range(N-1): a, b, c = map(int, input().split()) a -= 1; b -= 1 g[a]....
s997380005
p03634
u318127926
1579373695
Python
Python (3.4.3)
py
Runtime Error
970
57392
541
import sys n = int(input()) graph = [[] for _ in range(n+1)] for _ in range(n-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x, y)) l = [0]*(n+1) def DFS(node, p_no...
s189792409
p03634
u318127926
1579373231
Python
Python (3.4.3)
py
Runtime Error
932
57392
523
import sys n = int(input()) graph = [[] for _ in range(n+1)] for _ in range(n-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x, y)) l = [0]*(n+1) def DFS(node, p_no...
s782001988
p03634
u318127926
1579372412
Python
Python (3.4.3)
py
Runtime Error
892
56756
468
n = int(input()) graph = [[] for _ in range(n+1)] for _ in range(n-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x, y)) l = [0]*(n+1) def DFS(node, p_node, length)...
s321915272
p03634
u318127926
1579372032
Python
Python (3.4.3)
py
Runtime Error
935
57280
476
n = int(input()) graph = [[] for _ in range(n+1)] for _ in range(n-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x, y)) l = [0]*(n+1) def DFS(node, p_node, length)...
s093846266
p03634
u318127926
1579371756
Python
Python (3.4.3)
py
Runtime Error
994
57284
497
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k-=1 xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x-1, y-1)) l = [0]*(n+1) def DFS(...
s539125207
p03634
u318127926
1579371591
Python
Python (3.4.3)
py
Runtime Error
1010
57268
493
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k-=1 xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x-1, y-1)) l = [0]*n def DFS(node...
s406482048
p03634
u318127926
1579371303
Python
Python (3.4.3)
py
Runtime Error
1019
60108
510
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) xy = [] for _ in range(q): x, y = map(int, input().split()) xy.append((x-1, y-1)) k-=1 seen = [False]*n l = [...
s606833787
p03634
u318127926
1579368956
Python
Python (3.4.3)
py
Runtime Error
1419
44508
466
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k-=1 seen = [False]*n l = [0]*n def DFS(node, length): l[node] = length seen[node] = True for i, j in graph[...
s047033317
p03634
u318127926
1579330507
Python
Python (3.4.3)
py
Runtime Error
1388
44516
467
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k-=1 seen = [False]*n l = [0]*n def DFS(node, length): seen[node] = True for i, j in graph[node]: if seen[...
s229596263
p03634
u318127926
1579328686
Python
Python (3.4.3)
py
Runtime Error
1457
44516
481
n = int(input()) graph = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) a-=1 b-=1 graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) k-=1 seen = [False]*n l = [0]*n seen[k] = True def DFS(node, length): for i, j in graph[node]: if seen[i]: ...
s119014857
p03634
u554954744
1578790500
Python
PyPy3 (2.4.0)
py
Runtime Error
1944
125216
858
N = int(input()) edge = [[] for i in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) edge[a-1].append((c, b-1)) edge[b-1].append((c, a-1)) Q, K = map(int, input().split()) query = [tuple(map(int, input().split())) for _ in range(Q)] import heapq def dijkstra_heap(s): d = [10**12] * ...
s398803775
p03634
u474423089
1578426900
Python
Python (3.4.3)
py
Runtime Error
1036
68688
524
import sys sys.setrecursionlimit(10000) def dfs(v,d): k_shortest[v] = d visit[v] = 1 for i,j in tree[v]: if not visit[i]: dfs(i,d+j) N=int(input()) tree=[[] for i in range(N+1)] visit = [0]*(N+1) k_shortest = [0]*(N+1) for i in range(N-1): a,b,c=map(int,input().split(' ')) tree...
s294875567
p03634
u474423089
1578426477
Python
Python (3.4.3)
py
Runtime Error
1020
68684
483
def dfs(v,d): k_shortest[v] = d visit[v] = 1 for i,j in tree[v]: if not visit[i]: dfs(i,d+j) N=int(input()) tree=[[] for i in range(N+1)] visit = [0]*(N+1) k_shortest = [0]*(N+1) for i in range(N-1): a,b,c=map(int,input().split(' ')) tree[a].append((b,c)) tree[b].append((a,c...
s030683459
p03634
u474423089
1578426374
Python
Python (3.4.3)
py
Runtime Error
43
11060
503
import math def dfs(v,d): k_shortest[v] = d visit[v] = 1 for i,j in tree[v]: if not visit[i]: dfs(i,d+j) N=int(input()) tree=[[] for i in range(N+1)] visit = [0]*(N+1) k_shortest = [math.inf]*(N+1) for i in range(N-1): a,b,c=map(int,input().split(' ')) tree[a].append((b,c)) ...
s793437625
p03634
u474423089
1578348471
Python
Python (3.4.3)
py
Runtime Error
233
17192
474
import numpy as np from scipy.sparse.csgraph import shortest_path from scipy.sparse import csr_matrix import math N=int(input()) tree=[[math.inf]*N for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split(' ')) tree[a-1][b-1] = c tree[b-1][a-1] = c tree = np.array(tree) Q,K=map(int,input().split(...
s961995851
p03634
u408620326
1577989613
Python
Python (3.4.3)
py
Runtime Error
939
196340
764
import sys from collections import deque sys.setrecursionlimit(10 ** 5) input = sys.stdin.readline n = int(input()) m = {} np = [deque([]) for _ in range(n)] for _ in range(n-1): a, b, c = [int(x) for x in input().strip().split()] m[(a, b)] = c m[(b, a)] = c np[a-1].append(b) np[b-1].append(a) q, k...
s601179141
p03634
u408620326
1577989518
Python
Python (3.4.3)
py
Runtime Error
826
107484
733
import sys from collections import deque input = sys.stdin.readline n = int(input()) m = {} np = [deque([]) for _ in range(n)] for _ in range(n-1): a, b, c = [int(x) for x in input().strip().split()] m[(a, b)] = c m[(b, a)] = c np[a-1].append(b) np[b-1].append(a) q, k = [int(x) for x in input().str...
s292658407
p03634
u898967808
1577755973
Python
Python (3.4.3)
py
Runtime Error
1118
163892
607
import sys sys.setrecursionlimit(10**5) def search_unseen(fr,to,cost): cost_from_k[to] += cost_from_k[fr] + cost for n_to,n_cost in es[to]: if cost_from_k[n_to] == 0 and k!=n_to: search_unseen(to, n_to, n_cost) n = int(input()) es = {i:[] for i in range(n)} for i in range(n-1): a,b,c = map(int,inpu...
s898059162
p03634
u898967808
1577755182
Python
Python (3.4.3)
py
Runtime Error
1112
76724
579
INF = float('inf') def search_unseen(fr,to,cost): cost_from_k[to] += cost_from_k[fr]+cost for n_to,n_cost in es[to]: if cost_from_k[n_to] == 0 and k!=n_to: search_unseen(to,n_to,n_cost) n = int(input()) es = {i:[] for i in range(n)} for i in range(n-1): a,b,c = map(int,input().split()) es[a-1].app...
s951021870
p03634
u948524308
1577465357
Python
Python (3.4.3)
py
Runtime Error
2106
48404
675
N=int(input()) R=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) R[a-1].append([b-1,c]) R[b-1].append([a-1,c]) Q,K=map(int,input().split()) def dfs(s,g,d): chk[s]=1 for j,c in R[s]: if j==g: return d+c else: if chk[j]: ...
s775345846
p03634
u919025034
1576707314
Python
PyPy3 (2.4.0)
py
Runtime Error
1896
125728
588
N=int(input()) Branch=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) Branch[a-1].append([b-1,c]) Branch[b-1].append([a-1,c]) Q,K=map(int,input().split()) DistK=[float("Inf") for i in range(N)] flag = [0 for i in range(N)] def dfs(s,dist,flag,Branch,DistK): DistK[s]=dist flag[s]=1 ...
s346308676
p03634
u919025034
1576665192
Python
PyPy3 (2.4.0)
py
Runtime Error
1894
125816
523
N=int(input()) Branch=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) Branch[a-1].append([b-1,c]) Branch[b-1].append([a-1,c]) Q,K=map(int,input().split()) DistK=[float("Inf") for i in range(N)] flag = [0 for i in range(N)] def dfs(s,dist): DistK[s]=dist flag[s]=1 for i in rang...
s016992871
p03634
u919025034
1576663771
Python
PyPy3 (2.4.0)
py
Runtime Error
1741
119968
498
N=int(input()) Branch=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) Branch[a-1].append([b-1,c]) Branch[b-1].append([a-1,c]) Q,K=map(int,input().split()) DistK=[float("Inf") for i in range(N)] flag = [0 for i in range(N)] def dfs(s,dist): DistK[s]=dist flag[s]=1 for branch in...
s181805146
p03634
u607075479
1576534754
Python
Python (3.4.3)
py
Runtime Error
1158
156500
857
from collections import deque import sys sys.setrecursionlimit(100000) N = int(input()) graph = [[] for _ in range(N+1)] for i in range(1, N): tmpa, tmpb, tmpc = map(int, input().split()) graph[tmpa].append((tmpb, tmpc)) graph[tmpb].append((tmpa, tmpc)) Q, K = map(int, input().split()) question = [[] for _...
s999907586
p03634
u607075479
1576534625
Python
Python (3.4.3)
py
Runtime Error
1073
70076
816
from collections import deque N = int(input()) graph = [[] for _ in range(N+1)] for i in range(1, N): tmpa, tmpb, tmpc = map(int, input().split()) graph[tmpa].append((tmpb, tmpc)) graph[tmpb].append((tmpa, tmpc)) Q, K = map(int, input().split()) question = [[] for _ in range(Q+1)] for i in range(1, Q+1): ...
s054889433
p03634
u445624660
1575765652
Python
PyPy3 (2.4.0)
py
Runtime Error
1937
127756
723
# disjoint setかと思いきやDFS n = int(input()) graph = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append([b, c]) graph[b].append([a, c]) q, k = map(int, input().split()) k = k - 1 # kからスタートしてぜんぶたどる ans_list = [0 for _ in range(n)] def dfs...
s544289990
p03634
u445624660
1575765220
Python
Python (3.4.3)
py
Runtime Error
2107
52636
723
# disjoint setかと思いきやDFS n = int(input()) graph = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append([b, c]) graph[b].append([a, c]) q, k = map(int, input().split()) k = k - 1 # kからスタートしてぜんぶたどる ans_list = [0 for _ in range(n)] def dfs...
s354103111
p03634
u886747123
1575442322
Python
Python (3.4.3)
py
Runtime Error
596
149724
678
import sys sys.setrecursionlimit(100000) N = int(sys.stdin.buffer.readline()) graph = [[]*N for _ in range(N)] for _ in range(N-1): a, b, c = map(int, sys.stdin.buffer.readline().split()) graph[a-1].append((b-1, c)) graph[b-1].append((a-1, c)) Q, K = map(int, sys.stdin.buffer.readline().split()) dist_K ...
s902227446
p03634
u886747123
1575439074
Python
Python (3.4.3)
py
Runtime Error
2113
854932
533
import sys import numpy as np from scipy.sparse.csgraph import dijkstra N = int(sys.stdin.buffer.readline()) graph = np.zeros((N,N)) for _ in range(N-1): a, b, c = map(int, sys.stdin.buffer.readline().split()) graph[a-1][b-1] = c graph[b-1][a-1] = c Q, K = map(int, sys.stdin.buffer.readline().split()) d...
s294477262
p03634
u886747123
1575438804
Python
Python (3.4.3)
py
Runtime Error
2113
854984
541
import sys import numpy as np from scipy.sparse.csgraph import dijkstra N = int(sys.stdin.buffer.readline()) graph = np.zeros((N,N)) for _ in range(N-1): a, b, c = map(int, sys.stdin.buffer.readline().split()) graph[a-1][b-1] = c graph[b-1][a-1] = c Q, K = map(int, sys.stdin.buffer.readline().split()) d...
s998995340
p03634
u266874640
1575168228
Python
Python (3.4.3)
py
Runtime Error
950
48372
501
N = int(input()) edge = [[] for _ in range(N+1)] for _ in range(N-1): a,b,c = map(int,input().split()) edge[a].append((b,c)) edge[b].append((a,c)) Q,K = map(int,input().split()) distance = [None] * (N+1) def dfs(v1,d): distance[v1] = d for v2,dd in edge[v1]: if distance[v2] is not None: ...
s405979062
p03634
u266874640
1575168131
Python
Python (3.4.3)
py
Runtime Error
970
48352
497
N = int(input()) edge = [[] for _ in range(N+1)] for _ in range(N-1): a,b,c = map(int,input().split()) edge[a].append((b,c)) edge[b].append((a,c)) Q,K = map(int,input().split()) distance = [-1] * (N+1) def dfs(v1,d): distance[v1] = d for v2,dd in edge[v1]: if distance[v2] is not -1: ...
s785279221
p03634
u266874640
1575168108
Python
Python (3.4.3)
py
Runtime Error
960
49732
512
N = int(input()) edge = [[] for _ in range(N+1)] for _ in range(N-1): a,b,c = map(int,input().split()) edge[a].append((b,c)) edge[b].append((a,c)) Q,K = map(int,input().split()) distance = [-1] * (N+1) def dfs(v1,d): distance[v1] = d for v2,dd in edge[v1]: if distance[v2] is not -1: ...
s504717445
p03634
u266874640
1575167668
Python
Python (3.4.3)
py
Runtime Error
990
48356
510
N = int(input()) edge = [[] for _ in range(N+1)] for _ in range(N-1): a,b,c = map(int,input().split()) edge[a].append((b,c)) edge[b].append((a,c)) Q,K = map(int,input().split()) distance = [-1] * (N+1) def dfs(v1,d): distance[v1] = d for v2,dd in edge[v1]: if distance[v2] != -1: ...
s583622723
p03634
u814986259
1575090266
Python
Python (3.4.3)
py
Runtime Error
550
63468
457
N=int(input()) abc=[tuple(map(int,input().split())) for i in range(N-1)] g=[set() for i in range(N)] for a,b,c in abc: g[a-1].add((b-1,c)) g[b-1].add((a-1,c)) memo=[0]*N memo[K-1]=0 Q,K=map(int,input().split()) import collections q=collections.deque([(K-1,0)]) while(q): x,w = q.popleft() for a,b in g[x]: if...
s790980368
p03634
u470542271
1575082214
Python
Python (3.4.3)
py
Runtime Error
2213
1716464
667
n = int(input()) abc = [list(map(int, input().split())) for _ in range(n - 1)] Q, K = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(Q)] from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra def main(): cost = [[0] * n for _ in range(n)] for i in range(...
s626221995
p03634
u682985065
1574571086
Python
Python (3.4.3)
py
Runtime Error
491
38704
888
def dijkstra(n, edges, s): min_dist = [float('inf')] * n min_dist[s] = 0 next_v = [] heapq.heappush(next_v, (0, s)) path = [-1] * n while True: if len(next_v) == 0: break d, v = heapq.heappop(next_v) for u, d in edges[v]: if min_dist[u] > min_dis...
s433903448
p03634
u936985471
1574523207
Python
Python (3.4.3)
py
Runtime Error
2110
617920
725
n=int(input()) import numpy as np dist=np.full((n,n),-1,dtype=int) for i in range(n-1): dist[i][i]=0 a,b,c=map(int,input().split()) dist[a-1][b-1]=c dist[b-1][a-1]=c Q,K=map(int,input().split()) distFromK=np.full(n,-1,dtype=int) # start from K stack=[] stack.append([K-1,0,-1]) while stack: node=stack.pop()...
s564271361
p03634
u936985471
1574523135
Python
Python (3.4.3)
py
Runtime Error
2110
617924
732
n=int(input()) import numpy as np dist=np.full((n,n),-1,dtype=int) for i in range(n-1): dist[i][i]=0 a,b,c=map(int,input().split()) dist[a-1][b-1]=c dist[b-1][a-1]=c Q,K=map(int,input().split()) distFromK=np.full(n,-1,dtype=int) # start from K stack=[] stack.append([K-1,0,-1]) while stack: node=stack.pop()...
s965190628
p03634
u195608881
1573949124
Python
Python (3.4.3)
py
Runtime Error
1653
54784
1054
n = int(input()) # 値の初期化 path = [None]*(n + 1) adjacent_list = [[] for i in range(n+1)] for i in range(n - 1): a, b, c = list(map(int, input().split())) adjacent_list[a].append([b, c]) adjacent_list[b].append([a, c]) # ノード番号、そこまでの距離,検索済みの要素を受け取る。 def dfs(node_n, distance, finished): # 検索済みに追加 fin...
s194925882
p03634
u195608881
1573949078
Python
Python (3.4.3)
py
Runtime Error
17
3064
1039
n = int(input()) #値の初期化 path = [None]*(n + 1) adjacent_list = [[] for i in range(n+1)] for i in range(n - 1): a, b, c = list(map(int,input().split())) adjacent_list[a].append([b,c]) adjacent_list[b].append([a,c]) #ノード番号、そこまでの距離,検索済みの要素を受け取る。 def dfs(node_n ,distance,finished): #検索済みに追加 finished.add...
s186436347
p03634
u691896522
1573939003
Python
PyPy3 (2.4.0)
py
Runtime Error
1931
125216
981
n = int(input()) #値の初期化 path = [None]*(n + 1) adjacent_list = [[] for i in range(n+1)] for i in range(n - 1): a, b, c = list(map(int,input().split())) adjacent_list[a].append([b,c]) adjacent_list[b].append([a,c]) #ノード番号、そこまでの距離,検索済みの要素を受け取る。 def dfs(node_n ,distance,finished): #検索済みに追加 finished.add...
s415695660
p03634
u691896522
1573938579
Python
Python (3.4.3)
py
Runtime Error
1653
54784
666
n = int(input()) path = [None]*(n + 1) adjacent_list = [[] for i in range(n+1)] for i in range(n - 1): a, b, c = list(map(int,input().split())) adjacent_list[a].append([b,c]) adjacent_list[b].append([a,c]) #ノード番号、そこまでの距離,検索済みの要素を受け取る。 def dfs(node_n ,distance,finished): finished.add(node_n) path[nod...
s652087552
p03634
u556799364
1573843643
Python
PyPy3 (2.4.0)
py
Runtime Error
1904
123864
568
import collections graph = collections.defaultdict(list) N = int(input()) for i in range(N-1): # print(i) a, b, c = map(int, input().split(' ')) a -= 1 b -= 1 graph[a].append([b, c]) graph[b].append([a, c]) Q, K = map(int, input().split(' ')) dist = [-1 for _ in range(N)] dist[K-1] = 0 def...
s769623703
p03634
u223904637
1573258902
Python
Python (3.4.3)
py
Runtime Error
17
2940
503
fron collections import deque n=int(input()) g=[[] for i in range(n)] for i in range(n-1): a,b,c=map(int,input().split()) g[a-1].append([b-1,c]) g[b-1].append([a-1,c]) q,k=map(int,input().split()) qu=deque([[k-1,0]]) v=[0]*n d=[0]*n while len(qu)>0: s=qu.popleft() v[s[0]]=1 for j in g[s[0]]: ...
s663113719
p03634
u780962115
1573100680
Python
Python (3.4.3)
py
Runtime Error
1061
133424
932
import sys sys.setrecursionlimit(100000) n=int(input()) visitedlist=[-1 for i in range(n)] kilist=[[] for i in range(n)] anslist=[0 for i in range(n)] searchedlist=[-1 for i in range(n)] for i in range(n-1): a,b,c=map(int,input().split()) kilist[a-1].append((b,c)) kilist[b-1].append((a,c)) def ...
s495739977
p03634
u945181840
1572676395
Python
Python (3.4.3)
py
Runtime Error
2247
2000216
637
import sys from scipy.sparse.csgraph import dijkstra, csgraph_from_dense, shortest_path read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines N = int(readline()) INF = float('inf') graph = [[INF] * (N + 1) for _ in range(N + 1)] for i in range(N + 1): graph[i][i] = 0 for _ in range(N...
s891073552
p03634
u366959492
1572674064
Python
Python (3.4.3)
py
Runtime Error
2239
2014676
512
import sys, scipy import numpy as np from scipy.sparse import csr_matrix, isspmatrix_csr, isspmatrix_csc, isspmatrix from scipy.sparse.csgraph._shortest_path import shortest_path n=int(input()) g=[[0]*n for _ in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) a,b=a-1,b-1 g[a][b]=c g[b][a]...
s549592042
p03634
u366959492
1572674036
Python
PyPy3 (2.4.0)
py
Runtime Error
168
38384
512
import sys, scipy import numpy as np from scipy.sparse import csr_matrix, isspmatrix_csr, isspmatrix_csc, isspmatrix from scipy.sparse.csgraph._shortest_path import shortest_path n=int(input()) g=[[0]*n for _ in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) a,b=a-1,b-1 g[a][b]=c g[b][a]...
s127798936
p03634
u223904637
1571978368
Python
PyPy3 (2.4.0)
py
Runtime Error
688
80160
477
n=int(input()) g=[[] for i in range(n)] for i in range(n-1): a,b,c=map(int,input().split()) g[a-1].append([b-1,c]) g[b-1].append([a-1,c]) q,k=map(int,input().split()) qu=[[k-1,0]] v=[0]*n d=[0]*n while len(qu)>0: s0,s1=qu[0] qu=qu[1:] v[s0]=1 for j in g[s0]: j0,j1=j if not v[...
s417453037
p03634
u223904637
1571977480
Python
PyPy3 (2.4.0)
py
Runtime Error
670
80032
465
n=int(input()) g=[[] for i in range(n)] for i in range(n-1): a,b,c=map(int,input().split()) g[a-1].append([b-1,c]) g[b-1].append([a-1,c]) q,k=map(int,input().split()) qu=[[k-1,0]] v=[0]*n d=[0]*n while len(qu)>0: s=qu.pop(0) v[s[0]]=1 for j in g[s]: if not v[j[0]]: v[j[0]]=1 ...
s477911796
p03634
u598229387
1571071650
Python
Python (3.4.3)
py
Runtime Error
2106
48052
1017
from heapq import heappush, heappop class Dijk: def __init__(self, n): self.table = [[] for i in range(n+1)] self.n = n+1 def add(self, x, y, f): self.table[x].append((y, f)) def di(self, s): inf = float('inf') self.val = [inf] * self.n self.val[s] = 0...
s678036570
p03634
u814781830
1571008287
Python
Python (3.4.3)
py
Runtime Error
1220
75204
471
N = int(input()) to = [[] for _ in range(N)] for _ in range(N-1): a, b, c = map(int, input().split()) a, b = a-1, b-1 to[a].append([b, c]) to[b].append([a, c]) Q, K = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(Q)] dist = [0] * N def dfs(v, pv, dis): for i in to...
s954700264
p03634
u033606236
1570337896
Python
Python (3.4.3)
py
Runtime Error
1243
74396
443
def dfs(v,d): memo[v] = d for i in graph[v]: if memo[i[0]] != -1:continue dfs(i[0],d+i[1]) n = int(input()) graph = [[] for _ in range(n)] memo = [-1]*n for i in range(n-1): x,y,z = map(int,input().split()) graph[x-1].append([y-1,z]) graph[y-1].append([x-1,z]) q,k = map(int,input()....
s648896184
p03634
u978178314
1570335384
Python
Python (3.4.3)
py
Runtime Error
1510
49952
430
def dfs(prev, now, fromK, t, d): d[now] = fromK for nl in (t[now]): if nl[0] != prev: dfs(now, nl[0], fromK+nl[1], t, d) N = int(input()) T = [[] for _ in range(N+1)] for _ in range(N-1): a, b, l = map(int, input().split()) T[a].append([b,l]) T[b].append([a, l]) Q, K = map(int, input().split()) D ...
s810309042
p03634
u033606236
1570229059
Python
Python (3.4.3)
py
Runtime Error
2131
435048
928
def dfs(v,d,p): memo[v] = d flag = False for i in graph[v]: if memo[i[0]] != -1:continue dfs(i[0],d+i[1],v) sub_tree[v].append(v) for j in graph[v]: if j[0] == p:continue sub_tree[v] += sub_tree[j[0]] if p == k-1:arr.append(sub_tree[v]) n = int(input()) graph = [[...
s436377280
p03634
u921773161
1569845456
Python
Python (3.4.3)
py
Runtime Error
768
48052
704
#%% n = int(input()) a, b, c = [0] * n, [0] * n, [0] * n for i in range(n-1): a[i], b[i], c[i] = map(int, input().split()) q, k = map(int, input().split()) x, y = [0] * q, [0] * q for i in range(q): x[i], y[i] = map(int, input().split()) l = [[] for _ in range(n+1)] for i in range(n-1): l[a[i]].append((b[...
s177319149
p03634
u921773161
1569845404
Python
Python (3.4.3)
py
Runtime Error
784
48052
701
#%% n = int(input()) a, b, c = [0] * n, [0] * n, [0] * n for i in range(n-1): a[i], b[i], c[i] = map(int, input().split()) q, k = map(int, input().split()) x, y = [0] * q, [0] * q for i in range(q): x[i], y[i] = map(int, input().split()) l = [[] for _ in range(n+1)] for i in range(n-1): l[a[i]].append((b[...
s026744045
p03634
u167681750
1569542710
Python
Python (3.4.3)
py
Runtime Error
859
46508
523
n = int(input()) graph = [list() for i in range(n+1)] for i in range(n-1): a, b, c = map(int, (input().split())) graph[a].append([b, c]) graph[b].append([a, c]) len_list = [float("inf")] * (n + 1) q, k = map(int, input().split()) def dfs(pre, now, c): len_list[now] = min(len_list[now], len_list[pre] + c...
s517299541
p03634
u551909378
1569538315
Python
PyPy3 (2.4.0)
py
Runtime Error
2110
102532
587
N = int(input()) T = [{} for i in range(N+1)] for _ in range(N-1): a, b, c = map(int, input().split()) T[a][b] = c T[b][a] = c Q, K = map(int, input().split()) shortest_path = [0 for _ in range(N+1)] queue = [[v, T[K][v], K] for v in T[K].keys()] for _ in range(Q): x, y = map(int, input().split()) ...
s350538167
p03634
u118642796
1569473504
Python
PyPy3 (2.4.0)
py
Runtime Error
739
79392
502
import heapq N = int(input()) node = [[] for _ in range(N)] for _ in range(N-1): a,b,c = map(int,input().split()) node[a-1].append([c,b-1]) node[b-1].append([c,a-1]) Q,K = map(int,input().split()) flag = [True]*N ques = [[0,K-1]] D = [0]*N while ques: d1,l1 = heapq.heappop(ques) if flag[l1]: flag[l1]=Fal...
s339235748
p03634
u432551953
1569293286
Python
PyPy3 (2.4.0)
py
Runtime Error
864
103968
854
import sys input = sys.stdin.readline from operator import itemgetter tmp = [] tree = [] def dfs(node, depth, fr): global tmp, tree tree[node] = (fr, depth) for i, c in tmp[node]: if i != fr: dfs(i, depth+c, node) def main(): global tmp, tree n = int(input().strip()) tmp =...
s304173409
p03634
u477977638
1569210019
Python
PyPy3 (2.4.0)
py
Runtime Error
1901
126936
425
from collections import defaultdict n=int(input()) dct=defaultdict(list) for i in range(n-1): a,b,c=map(int,input().split()) dct[a]+=[[b,c]] dct[b]+=[[a,c]] q,k=map(int,input().split()) lk=[0]*(n) def dfs(v,p,d): lk[v-1]=d for l in dct[v]: if l[0]==p: continue dfs(l[0],v,d+l[1]) return df...
s713764290
p03634
u477977638
1569209771
Python
PyPy3 (2.4.0)
py
Runtime Error
1868
124888
439
from collections import defaultdict n=int(input()) dct=defaultdict(list) for i in range(n-1): a,b,c=map(int,input().split()) dct[a]+=[[b,c]] dct[b]+=[[a,c]] q,k=map(int,input().split()) lk=[0]*(n) def dfs(v,p,d): lk[v-1]=d for l in dct[v]: if l[0]==p or lk[l[0]-1]!=0: continue else: ...
s861408404
p03634
u477977638
1569209047
Python
Python (3.4.3)
py
Runtime Error
1610
57004
438
from collections import defaultdict n=int(input()) dct=defaultdict(list) for i in range(n-1): a,b,c=map(int,input().split()) dct[a]+=[[b,c]] dct[b]+=[[a,c]] q,k=map(int,input().split()) lk=[0]*(n) def dfs(v,p,d): lk[v-1]=d for l in dct[v]: if l[0]==p or lk[l[0]-1]!=0: continue else: ...
s610684424
p03634
u477977638
1569208893
Python
Python (3.4.3)
py
Runtime Error
1547
55596
439
from collections import defaultdict n=int(input()) dct=defaultdict(list) for i in range(n-1): a,b,c=map(int,input().split()) dct[a]+=[[b,c]] dct[b]+=[[a,c]] q,k=map(int,input().split()) lk=[0]*(n) def dfs(v,p,d): lk[v-1]=d for l in dct[v]: if l[0]==p: continue else: dfs(l[0],v,d+l[1]...
s958896386
p03634
u477977638
1569208869
Python
Python (3.4.3)
py
Runtime Error
2107
138884
477
from collections import defaultdict n=int(input()) dct=defaultdict(list) for i in range(n-1): a,b,c=map(int,input().split()) dct[a]+=[[b,c]] dct[b]+=[[a,c]] print(dct) q,k=map(int,input().split()) lk=[0]*(n) def dfs(v,p,d): lk[v-1]=d print(k,v,p,d,lk) for l in dct[v]: if l[0]==p: continue ...
s470489978
p03634
u891635666
1569106103
Python
Python (3.4.3)
py
Runtime Error
842
81636
511
import sys input = sys.stdin.readline n = int(input()) ls = [list(map(int, input().split())) for _ in range(n - 1)] es = [[] for _ in range(n + 1)] for a, b, c in ls: es[a].append((b, c)) es[b].append((a, c)) ds = [0] * (n + 1) def dfs(cur, prev, c): ds[cur] = ds[prev] + c for e, c in es[cur]: ...
s302678842
p03634
u828766688
1568940282
Python
Python (3.4.3)
py
Runtime Error
2107
57140
690
from collections import deque N = int(input()) abc = [] dic = {} for i in range(N-1): a,b,c = map(int,input().split()) if a not in dic: dic[a-1] = [] if b not in dic: dic[b-1] = [] dic[a-1].append([b-1,c]) dic[b-1].append([a-1,c]) Q,K = map(int,input().split()) K -= 1 lis =...
s860089589
p03634
u009348313
1568579719
Python
PyPy3 (2.4.0)
py
Runtime Error
1631
135200
585
N = int(input()) E = [set() for _ in range(N)] C = {} for i in range(N-1): a,b,c = map(int,input().split()) E[a-1].add(b-1) E[b-1].add(a-1) C[min(a-1,b-1)*N+max(a-1,b-1)] = c Q,K = map(int,input().split()) K -= 1 Query = [] for i in range(Q): x,y = map(int,input().split()) Query.append([x-1,y-1]) #print(...
s698748170
p03634
u548684908
1568573601
Python
Python (3.4.3)
py
Runtime Error
1498
47716
457
N=int(input()) M=1000000007 dp = [0]*N E = [] for i in range(N): E.append([]) def dfs(cur,pre): for r,d in E[cur]: if r != pre: dp[r] = dp[cur] + d dfs(r,cur) for i in range(N-1): x,y,d= list(map(int,input().split())) E[x-1].append((y-1,d)) E[y-1].append((x-1,d)) ...
s367199977
p03634
u623687794
1568571525
Python
Python (3.4.3)
py
Runtime Error
1373
51808
520
n=int(input()) graph=[{} for i in range(n)] visited=[False]*n for i in range(n-1): a,b,c=map(int,input().split()) a-=1;b-=1 graph[a][b]=c graph[b][a]=c q,k=map(int,input().split()) dist=[0]*n def dfs(chi,par,cost): dist[chi]=cost for i in graph[chi].keys(): if visited[i]:continue ...
s961042620
p03634
u223646582
1568557076
Python
Python (3.4.3)
py
Runtime Error
1429
56888
597
N = int(input()) G = [set() for i in range(N)] for _ in range(N-1): a, b, c = map(int, input().split()) G[a-1].add((b, c)) G[b-1].add((a, c)) Q, K = map(int, input().split()) visited = [False] * N visited[K-1] = True distance = [-1]*N def dfs(v, p, d): # 現在の頂点v, vの親p, 現在の距離d distance[v-1] = d ...
s657763088
p03634
u598229387
1568344475
Python
Python (3.4.3)
py
Runtime Error
1363
43612
437
n=int(input()) graph=[[] for i in range(n+1)] for i in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) graph[b].append((a,c)) q,k=map(int,input().split()) dis=[None]*(n+1) def set_dis(x,d): dis[x]=d for yy,dd in graph[x] : if dis[yy] is not None: continue...
s075441839
p03634
u598229387
1568344423
Python
Python (3.4.3)
py
Runtime Error
1415
45576
447
n=int(input()) graph=[[] for i in range(n+1)] for i in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) graph[b].append((a,c)) q,k=map(int,input().split()) dis=[float('inf')]*(n+1) def set_dis(x,d): dis[x]=d for yy,dd in graph[x] : if dis[yy]!=float('inf'): ...
s599245790
p03634
u598229387
1568344320
Python
Python (3.4.3)
py
Runtime Error
1457
43628
465
n=int(input()) graph=[[] for i in range(n+1)] for i in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) graph[b].append((a,c)) q,k=map(int,input().split()) dis=[float('inf')]*(n+1) def set_dis(x,d): dis[x]=d for yy,dd in graph[x] : if dis[yy]!=float('inf'): ...
s162828031
p03634
u990987804
1567879119
Python
PyPy3 (2.4.0)
py
Runtime Error
186
38256
678
import sys sys.setrecursionlimit(10**15) N = int(input()) ds = [[0]*N for i in range(N)] for i in range(N-1): a, b, c = list(map(int, input().split(" "))) ds[a-1][b-1] = c ds[b-1][a-1] = c q, k = list(map(int, input().split(" "))) def dfs(path, dist, c): if c==g: return dist dists = [] for i in range...
s051785597
p03634
u990987804
1567878962
Python
PyPy3 (2.4.0)
py
Runtime Error
3210
641672
636
N = int(input()) ds = [[0]*N for i in range(N)] for i in range(N-1): a, b, c = list(map(int, input().split(" "))) ds[a-1][b-1] = c ds[b-1][a-1] = c q, k = list(map(int, input().split(" "))) def dfs(path, dist, c): if c==g: return dist dists = [] for i in range(N): if ds[i][c]>0 and i not in path: ...
s121771752
p03634
u761529120
1567822476
Python
PyPy3 (2.4.0)
py
Runtime Error
1703
105248
485
def dfs(v,p,d): for i, j in tree[v]: if i != p: depth[i] = d + j dfs(i,v,d+j) N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) a -= 1 b -= 1 tree[a].append((b,c)) tree[b].append((a,c)) Q, K = map(int, inpu...
s851340336
p03634
u498620941
1567649653
Python
Python (3.4.3)
py
Runtime Error
1868
67008
572
N = int(input()) class Edge: def __init__(self,to,cost): self.to = to self.cost = cost graph = [[] for i in range(N)] for i in range(N-1): a,b,c = map(int,input().split()) graph[a-1].append(Edge(b-1,c)) graph[b-1].append(Edge(a-1,c)) dp = [0 for i in range(N)] def dfs(s,pare): for...
s602107921
p03634
u714378447
1567635842
Python
Python (3.4.3)
py
Runtime Error
1331
77664
422
N=int(input()) G=[[] for i in range(N)] for i in range(N-1): a,b,c=map(lambda x:int(x)-1,input().split()) G[a].append([b,c+1]) G[b].append([a,c+1]) Q,K=map(int,input().split()) A=[list(map(int,input().split())) for i in range(Q)] depth=[0 for i in range(N)] depth[K-1]=0 def dfs(cur,p,d): for i,j in G[cur]: i...
s314765952
p03634
u360515075
1566825955
Python
Python (3.4.3)
py
Runtime Error
2113
855020
381
from scipy.sparse.csgraph import shortest_path, dijkstra import numpy as np N = int(input()) L = np.zeros((N,N)) for i in range(N-1): a, b, c = map(int, input().split()) L[a-1][b-1] = c L[b-1][a-1] = c Q, K = map(int, input().split()) K -= 1 L1 = dijkstra(L, indices = K) for i in range(Q): x, y = map(int, inp...
s296157798
p03634
u360515075
1566823960
Python
Python (3.4.3)
py
Runtime Error
2114
1830356
440
import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix N = int(input()) L = np.full((N, N), np.inf) for i in range(N-1): a, b, c = map(int, input().split()) L[a-1][b-1] = c L[b-1][a-1] = c L = csr_matrix(L) L = floyd_warshall(L, 0) print (L) Q, K = map(int, input()....
s475932035
p03634
u360515075
1566823364
Python
Python (3.4.3)
py
Runtime Error
2114
856424
391
import numpy as np from scipy.sparse.csgraph import shortest_path, floyd_warshall N = int(input()) L = np.full((N, N), np.inf) for i in range(N-1): a, b, c = map(int, input().split()) L[a-1][b-1] = c L[b-1][a-1] = c L = floyd_warshall(L, 0) Q, K = map(int, input().split()) K -= 1 for i in range(Q): x, y = map(i...
s706887643
p03634
u360515075
1566823060
Python
Python (3.4.3)
py
Runtime Error
2111
1830344
371
import numpy as np from scipy.sparse.csgraph import shortest_path N = int(input()) L = np.full((N, N), np.inf) for i in range(N-1): a, b, c = map(int, input().split()) L[a-1][b-1] = c L[b-1][a-1] = c L = shortest_path(L) Q, K = map(int, input().split()) K -= 1 for i in range(Q): x, y = map(int, input().split())...
s769663422
p03634
u800258529
1566786810
Python
Python (3.4.3)
py
Runtime Error
1057
170608
593
import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) n=int(input()) l=[list(map(int,input().split())) for _ in [0]*(n-1)] q,k=map(int,input().split()) L=[list(map(int,input().split())) for _ in [0]*q] neighbor=[[] for _ in range(n+1)] for i in range(n-1): neighbor[l[i][0]].append([l[i][1],l[i][2]]) ...
s512455646
p03634
u800258529
1566786738
Python
Python (3.4.3)
py
Runtime Error
1072
83120
564
import sys input = sys.stdin.readline n=int(input()) l=[list(map(int,input().split())) for _ in [0]*(n-1)] q,k=map(int,input().split()) L=[list(map(int,input().split())) for _ in [0]*q] neighbor=[[] for _ in range(n+1)] for i in range(n-1): neighbor[l[i][0]].append([l[i][1],l[i][2]]) neighbor[l[i][1]].append(...
s126391009
p03634
u800258529
1566770092
Python
Python (3.4.3)
py
Runtime Error
1070
83120
548
import sys input = sys.stdin.readline n=int(input()) l=[list(map(int,input().split())) for _ in [0]*(n-1)] q,k=map(int,input().split()) L=[list(map(int,input().split())) for _ in [0]*q] neighbor=[[] for _ in range(n+1)] for i in range(n-1): neighbor[l[i][0]].append([l[i][1],l[i][2]]) neighbor[l[i][1]].append(...
s527448067
p03634
u077291787
1566439111
Python
Python (3.4.3)
py
Runtime Error
674
71408
865
# ABC070D - Transit Tree Path import sys input = sys.stdin.readline def dfs(v: int, p: int) -> None: d = dist[v] for u, c in G[v]: # search vertices available from v recursively if u != p: # p: parent dist[u] += d + c # dist(K, v) + dist(v, u) == d + c dfs(u, v) def main():...
s950678668
p03634
u927534107
1566254208
Python
Python (3.4.3)
py
Runtime Error
2134
429636
467
from scipy.sparse.csgraph import csgraph_from_dense,floyd_warshall n=int(input()) edge = [[10**9 for i in range(n)] for i in range(n)] for i in range(n-1): x,y,z = map(int,input().split()) edge[x-1][y-1] = z edge[y-1][x-1] = z for i in range(n): edge[i][i] = 0 G = csgraph_from_dense(edge, null_value=10...
s651220034
p03634
u472065247
1565796109
Python
Python (3.4.3)
py
Runtime Error
1167
87964
439
N = int(input()) ABC = [list(map(int, input().split())) for _ in range(N - 1)] Q, K = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(Q)] G = [[] * N for _ in range(N)] for a, b, c in ABC: G[a - 1].append((b - 1, c)) G[b - 1].append((a - 1, c)) D = [-1] * N def dfs(v, d): D[v] = ...
s919240246
p03634
u472065247
1565795545
Python
Python (3.4.3)
py
Runtime Error
1112
87868
483
N = int(input()) ABC = [list(map(int, input().split())) for _ in range(N - 1)] Q, K = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(Q)] G = [[] * N for _ in range(N)] for a, b, c in ABC: G[a - 1].append((b - 1, c)) G[b - 1].append((a - 1, c)) D = [-1] * N def dfs(v, p, d): D[v]...