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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s923715176 | p03634 | u685983477 | 1590798941 | Python | Python (3.4.3) | py | Runtime Error | 948 | 55472 | 816 | n = int(input())
visited = [0]*n
def dfs(edge, dist, k):
visited[k]=1
for i in edge[k]:
if visited[i[0]]==0:
dist[i[0]]=i[1]+dist[k]
dfs(edge, dist, i[0])
return dist
def main():
edge = [[] for _ in range(n)]
for i in range(n-1):
a,b,c=map(int, input().split... |
s030427272 | p03634 | u784022244 | 1590627778 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 555 |
from collections import deque
N=int(input())
T=[[] for _ in range(N)]
for i in range(N-1):
a,b,c=map(int, input().split())
T[a-1].append((b-1,c))
T[b-1].append((a-1,c))
Q,K=map(int, input().split())
que=[(K-1,0)
done=[-1]*N
while que:
t=que.pop(0)
now,nowd=t
done[now]=nowd
for nex in T[now... |
s793666435 | p03634 | u189479417 | 1590603805 | Python | Python (3.4.3) | py | Runtime Error | 1448 | 43600 | 467 | N = int(input())
INF = 10 ** 14
edges = [[] for _ in range(N)]
for _ in range(N-1):
a, b, c = map(int,input().split())
edges[a-1].append((b-1, c))
edges[b-1].append((a-1, c))
Q, K = map(int,input().split())
d = [INF] * N
d[K-1] = 0
def dfs(x):
for u, cost in edges[x]:
if d[u] == INF:
... |
s053805062 | p03634 | u156815136 | 1590581350 | Python | Python (3.4.3) | py | Runtime Error | 1615 | 49964 | 608 | n = int(input())
def D(now,pre,SUM):
dist[now] = SUM
for BC in G[now]:
if BC[0] == pre:
continue
D(BC[0],now,SUM+BC[1])
G = [[] for _ in range(n)]
for i in range(n-1):
a,b,c = map(int,input().split())
a -= 1
b -= 1
G[a].append([b,c])
G[b].append([a,c])
q,k = m... |
s030589023 | p03634 | u338824669 | 1590559000 | Python | Python (3.4.3) | py | Runtime Error | 1584 | 49964 | 440 | N=int(input())
graph=[[] for _ in range(N)]
for i 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])
def dfs(start):
for x,cost in graph[start]:
if d[x]==-1:
d[x]=d[start]+cost
dfs(x)
Q,K=map(int,input().split()... |
s741040585 | p03634 | u565791439 | 1590467069 | Python | Python (3.4.3) | py | Runtime Error | 2109 | 112600 | 1651 | import sys
from collections import defaultdict
def ep(*s):
print(*s,file=sys.stderr)
def search(x,y):
c = 0
ox = nodes[x]
oy = nodes[y]
while ox.level != oy.level:
if ox.level > oy.level:
c += cost[(ox.parent,ox.n)]
ox = nodes[ox.parent]
if ox.level < oy.leve... |
s206823780 | p03634 | u565791439 | 1590466920 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1557 | import sys
from collections import defaultdict
def ep(*s):
print(*s,file=sys.stderr)
def search(x,y):
c = 0
ox = nodes[x]
oy = nodes[y]
while ox.level != oy.level:
if ox.level > oy.level:
c += cost[(ox.parent,ox.n)]
ox = nodes[ox.parent]
if ox.level < oy.leve... |
s708032590 | p03634 | u679520304 | 1590040557 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 623700 | 547 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
N = int(input())
indices = []
indptr = []
data = []
for _ in range(N-1):
a,b,c = map(int,input().split())
indices.append(a)
indptr.append(b)
data.append... |
s885215484 | p03634 | u679520304 | 1590040229 | Python | PyPy3 (2.4.0) | py | Runtime Error | 166 | 38256 | 547 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
N = int(input())
indices = []
indptr = []
data = []
for _ in range(N-1):
a,b,c = map(int,input().split())
indices.append(a)
indptr.append(b)
data.append... |
s823068924 | p03634 | u679520304 | 1590040098 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 623704 | 547 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
N = int(input())
indices = []
indptr = []
data = []
for _ in range(N-1):
a,b,c = map(int,input().split())
indices.append(a)
indptr.append(b)
data.append... |
s839904817 | p03634 | u189487046 | 1589660257 | Python | Python (3.4.3) | py | Runtime Error | 2229 | 814832 | 840 | import sys
sys.setrecursionlimit(10 ** 6)
def input():
return sys.stdin.readline()[:-1]
def dfs(now, point):
if K in tree[now-1]:
point += tree_c[now-1][K]
return point
else:
for next_node in tree[now-1]:
if zumi[next_node-1] == -1:
tmp_p = point+tree_... |
s863105775 | p03634 | u935558307 | 1589513063 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1690 | 112672 | 423 | N = int(input())
edges = [{}for _ in range(N+1)]
for _ in range(N-1):
a,b,c = map(int,input().split())
edges[a][b] = c
edges[b][a] = c
costDic = [0]*(N+1)
def f(cost,now,p):
costDic[now] = cost
for nx,c in edges[now].items():
if nx != p:
f(cost+c,nx,now)
Q,K = map(int,input().s... |
s934797388 | p03634 | u588794534 | 1589237699 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1575 | 131104 | 635 | n=int(input())
c={}
tree=[[] for _ in range(n)]
for _ in range(n-1):
i,j,k=map(int,input().split())
i-=1
j-=1
tree[i].append(j)
tree[j].append(i)
c[(i,j)]=k
c[(j,i)]=k
result=[]
q,k=map(int,input().split())
#初期値が0の辞書
from collections import defaultdict
memo = defaultdict(lambda: -1)
de... |
s513342885 | p03634 | u588794534 | 1589237637 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1597 | 131856 | 635 | n=int(input())
c={}
tree=[[] for _ in range(n)]
for _ in range(n-1):
i,j,k=map(int,input().split())
i-=1
j-=1
tree[i].append(j)
tree[j].append(i)
c[(i,j)]=k
c[(j,i)]=k
result=[]
q,k=map(int,input().split())
#初期値が0の辞書
from collections import defaultdict
memo = defaultdict(lambda: -1)
de... |
s168128932 | p03634 | u747602774 | 1589086489 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1736 | 116000 | 481 | N = int(input())
vertex = [{} for _ in range(N)]
for i in range(N-1):
a,b,c = map(int,input().split())
vertex[a-1][b-1] = c
vertex[b-1][a-1] = c
Q,K = map(int,input().split())
d = [0 for i in range(N)]
def dfs(v1,v2):
d[v2] = d[v1] + vertex[v1][v2]
for v in vertex[v2]:
if v == v1:
... |
s790370305 | p03634 | u373047809 | 1588907520 | Python | Python (3.4.3) | py | Runtime Error | 693 | 44104 | 346 | import sys
sys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input());s=[0for _ in[0]*n];j=[[]for _ in[0]*n]
for _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])
def f(v,p,d):
s[v]=d
for i,c in j[v]:
if i==p:
continue
f(i,v,d+c)
q,k=l()
dfs(k-1,-1,0)
for _ in [0]*q:x,... |
s372820946 | p03634 | u373047809 | 1588907491 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 346 | import sys
sys.setrecursionlimit(10**6);l=lambda:map(int, input().split());n=int(input()):s=[0for _ in[0]*n];j=[[]for _ in[0]*n]
for _ in range(n-1):a,b,c=l();j[a-1].append([b-1,c]);j[b-1].append([a-1,c])
def f(v,p,d):
s[v]=d
for i,c in j[v]:
if i==p:
continue
f(i,v,d+c)
q,k=l()
dfs(k-1,-1,0)
for _ in [0]*q:x,... |
s538488235 | p03634 | u666476759 | 1588641466 | Python | Python (3.4.3) | py | Runtime Error | 1417 | 138760 | 765 | import sys
sys.setrecursionlimit(100000)
N = int(input())
Nodes = [{} for i in range(N)]
def search(index, dist):
neighbors = Nodes[index]
for key in neighbors:
if distances[key] is not None:
continue
distances[key] = dist + neighbors[key]
search(key, distances[key])
#... |
s897078152 | p03634 | u666476759 | 1588641317 | Python | Python (3.4.3) | py | Runtime Error | 1340 | 51040 | 722 | N = int(input())
Nodes = [{} for i in range(N)]
def search(index, dist):
neighbors = Nodes[index]
for key in neighbors:
if distances[key] is not None:
continue
distances[key] = dist + neighbors[key]
search(key, distances[key])
# 木を作る
for _ in range(N-1):
a, b, c = ma... |
s198186541 | p03634 | u089142196 | 1588542554 | Python | Python (3.4.3) | py | Runtime Error | 1495 | 54068 | 654 | from collections import deque
N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
a[i],b[i],c[i]= map(int,input().split())
L[a[i]-1].append((b[i]-1,c[i]))
L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
#Lの中のitemの0は接続先、1は距離
d=[ -1 for i in ra... |
s541434450 | p03634 | u089142196 | 1588542156 | Python | Python (3.4.3) | py | Runtime Error | 1586 | 60308 | 654 | from collections import deque
N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
a[i],b[i],c[i]= map(int,input().split())
L[a[i]-1].append((b[i]-1,c[i]))
L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
#Lの中のitemの0は接続先、1は距離
d=[ -1 for i in ra... |
s029640465 | p03634 | u711238850 | 1588226100 | Python | PyPy3 (2.4.0) | py | Runtime Error | 622 | 62872 | 3861 | import heapq
class Graph:
def __init__(self,v,edgelist,w_v = None,directed = False):
super().__init__()
self.v = v
self.w_e = [{} for _ in [0]*self.v]
self.neighbor = [[] for _ in [0]*self.v]
self.w_v = w_v
self.directed = directed
for i,j,w in edgelist:
... |
s657859042 | p03634 | u497952650 | 1588211704 | Python | Python (3.4.3) | py | Runtime Error | 2134 | 425380 | 481 | from scipy.sparse.csgraph import shortest_path
import sys
import numpy as np
def input():
return sys.stdin.readline().strip()
N = int(input())
graph = [[0 for i in range(N)] for j in range(N)]
for i in range(N-1):
a,b,c = map(int,input().split())
graph[a-1][b-1] = c
graph[b-1][a-1] = c
Q,K = map(... |
s989424013 | p03634 | u992910889 | 1588198687 | Python | PyPy3 (2.4.0) | py | Runtime Error | 181 | 38384 | 950 | import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
# Python3で出すことに注意!
# floyd_warshall
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.floyd_warshall.html
# ↑を見ながら細部を埋める
from scipy.sparse import csr_matrix
... |
s143840600 | p03634 | u246217175 | 1588198680 | Python | PyPy3 (2.4.0) | py | Runtime Error | 675 | 68000 | 546 | from collections import deque
import sys
INF = 11414191981036436433-4
n = int(input())
g = [[] for i in range(n)]
for v 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())
k -= 1
r = [INF]*n
que = deque([k])
r[k] = 0
while que:
... |
s894224363 | p03634 | u992910889 | 1588198343 | Python | PyPy3 (2.4.0) | py | Runtime Error | 174 | 38384 | 962 | import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
# Python3で出すことに注意!
# floyd_warshall
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.floyd_warshall.html
# ↑を見ながら細部を埋める
from scipy.sparse import csr_matrix
... |
s439399961 | p03634 | u246217175 | 1588198055 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2110 | 120980 | 1496 | from collections import deque
import sys
N = int(input())
prv = [None]*N
G = [[] for i in range(N)]
for v in range(N-1):
a,b,c = map(int,input().split())
aa = min(a,b)-1
bb = max(a,b)-1
G[aa].append((bb,c))
prv[bb] = aa
depth = [0]*N
r = [0]*N
que = deque([0])
while que:
v = que.popleft()
... |
s175020214 | p03634 | u867320886 | 1588175903 | Python | Python (3.4.3) | py | Runtime Error | 2118 | 1448684 | 362 | from scipy.sparse.csgraph import dijkstra
import numpy as np
n = int(input())
L = np.zeros((n,n),int)
for _ in range(n-1):
a,b,c = map(int,input().split())
L[a-1,b-1] = c
q,k = map(int,input().split())
dist = dijkstra(L,directed = False, indices= k-1).astype(int)
for _ in range(q):
x,y = map(int,input()... |
s264660682 | p03634 | u755363325 | 1588143235 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1587 | 132768 | 1153 | n = int(input())
adjacency = [[] for i in range(n+1)] #adjacency[i]は頂点iと隣接する頂点のリスト
distance = {} # distance[(i,j)](i,jは隣接した頂点)は頂点i,jを結ぶ辺の長さ
for i in range(n-1):
line = list(map(int, input().split()))
adjacency[line[0]].append(line[1])
adjacency[line[1]].append(line[0])
distance[(line[0], line[1])] = lin... |
s266508516 | p03634 | u935558307 | 1588047176 | Python | PyPy3 (2.4.0) | py | Runtime Error | 373 | 80560 | 904 | """
--- アルゴリズム概要 ---
前計算で頂点Kから各ノードへの最短路を記録しておき、
各クエリに対しては、dp[a]+dp[b]を返せばよい。
頂点Kから各ノードへの最短ルートはdfsとかで記録していけばよい。
"""
def main():
import sys
sys.setrecursionlimit(2000000)
input = sys.stdin.readline
N = int(input())
AB = [{}for _ in range(N+1)]
for i in range(N-1):
a,b,c = map(int,input().... |
s950099113 | p03634 | u935558307 | 1588047134 | Python | PyPy3 (2.4.0) | py | Runtime Error | 402 | 80560 | 905 | """
--- アルゴリズム概要 ---
前計算で頂点Kから各ノードへの最短路を記録しておき、
各クエリに対しては、dp[a]+dp[b]を返せばよい。
頂点Kから各ノードへの最短ルートはdfsとかで記録していけばよい。
"""
def main():
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
N = int(input())
AB = [{}for _ in range(N+1)]
for i in range(N-1):
a,b,c = map(int,input()... |
s943742184 | p03634 | u280552586 | 1588046592 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 520 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
edges[a].append(b)
edges[b].append(a)
count = [0]*n
for i in range(q):
p, x = map(int, input()... |
s684634937 | p03634 | u935558307 | 1588046311 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1877 | 123808 | 687 | """
--- アルゴリズム概要 ---
前計算で頂点Kから各ノードへの最短路を記録しておき、
各クエリに対しては、dp[a]+dp[b]を返せばよい。
頂点Kから各ノードへの最短ルートはdfsとかで記録していけばよい。
"""
N = int(input())
AB = [{}for _ in range(N+1)]
for i in range(N-1):
a,b,c = map(int,input().split())
AB[a][b] = c
AB[b][a] = c
Q,K = map(int,input().split())
path = {K:""}
dp = [0]*(N+1)
def... |
s488889328 | p03634 | u935558307 | 1587946292 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1865 | 126240 | 1185 | """
---アルゴリズム概要---
閉路のないグラフなので、シンプルにxからKまでまっすぐに進んでから、Kからyにまっすぐ進むことを考えればよい。
クエリの数Qが10**5個あるので、ノードaからノードbにまっすぐ進む場合のコストをメモしていくのがよさそう。
次に、どうやってノードaからノードbへの「まっすぐ進む道」=「まっすぐ進むための次のノード」を判断するかだが、
これは、ノードaが直接つながっているノードのうち、
ノードbへのコストが最も少ないものがまっすぐ進むための次のノードとなる。
"""
N = int(input())
edges = [{} for _ in range(N)]
#dpでiからjへの最短コストを... |
s728512517 | p03634 | u405256066 | 1587699728 | Python | Python (3.4.3) | py | Runtime Error | 912 | 62640 | 617 | from sys import stdin
from collections import defaultdict
N = int(stdin.readline().rstrip())
adj = defaultdict(set)
for i in range(N-1):
a,b,c = [int(x) for x in stdin.readline().rstrip().split()]
adj[a].add((b,c))
adj[b].add((a,c))
Q,K = [int(x) for x in stdin.readline().rstrip().split()]
visited = ... |
s775118870 | p03634 | u201802797 | 1587486946 | Python | Python (3.4.3) | py | Runtime Error | 376 | 42828 | 586 | import sys
input = sys.stdin.readline
data = int(input())
E = [[] for _ in range(data)]
for _ in range(data-1):
a, b, c = list(map(int, input().split()))
E[a-1].append((b-1,c))
E[b-1].append((a-1,c))
nim, mike = list(map(int, input().split()))
queue = [mike-1]
dist = [None]*data
dist[K-1] = 0
while queue:
qu... |
s429179247 | p03634 | u511379665 | 1587441812 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 336 | #tempt
n=int(input())
a=[]
b=[]
c=[]
tree=[[] for j in range(n)]
for i in range(n-1):
d,e,f=map(int,input().split())
tree[d-1].append([e-1,f])
tree[e-1].append([d-1,f])
x=[]
y=[]
q,k=map(int,input().split())
for i in range(q):
a,b=map(int,input().split())
x.append(a)
y.append(b)
ans=[0]*n
d... |
s724545137 | p03634 | u114920558 | 1587173467 | Python | Python (3.4.3) | py | Runtime Error | 1717 | 64096 | 478 | N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
L[a].append([b, c])
L[b].append([a, c])
def dfs(n, np):
for nc in L[n]:
if nc[0] == np:
continue
else... |
s657823208 | p03634 | u114920558 | 1587173265 | Python | Python (3.4.3) | py | Runtime Error | 1589 | 49968 | 567 | N = int(input())
graph = [[] for _ in range(N+1)] #木構造を入れておく
long = [0] * (N+1) #Kから任意のノードまでの距離
for i in range(N-1):
x, y, z = map(int, input().split())
graph[x].append([y, z])
graph[y].append([x, z])
Q, K = map(int, input().split())
def dfs(n, num):
for t in graph[n]:
if t[0] == num:
... |
s317570279 | p03634 | u114920558 | 1587172505 | Python | Python (3.4.3) | py | Runtime Error | 1191 | 58132 | 655 | N = int(input())
graph = [[] for _ in range(N+1)] #木構造を入れておく
long = [0] * (N+1) #Kから任意のノードまでの距離
for i in range(N-1):
x, y, z = map(int, input().split())
graph[x].append([y, z])
graph[y].append([x, z])
Q, K = map(int, input().split())
x = list()
y = list()
for i in range(Q):
x_i, y_i = map(int, input().spli... |
s575394596 | p03634 | u011062360 | 1586830103 | Python | Python (3.4.3) | py | Runtime Error | 1343 | 83116 | 515 | n = int(input())
list_ABC = [list(map(int, input().split())) for i in range(n - 1)]
q, k = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for i in range(q)]
D = [0] * (n + 1)
L = [[] for i in range(n + 1)]
for a, b, c in list_ABC:
L[a].append([b, c])
L[b].append([a, c])
def dfs(n, np):... |
s601898907 | p03634 | u011062360 | 1586810311 | Python | Python (3.4.3) | py | Runtime Error | 2207 | 1632940 | 557 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
n = int(input())
list_ABC = [ list(map(int,input().split(" "))) for i in range(n-1)]
q, k = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for ... |
s910355845 | p03634 | u011062360 | 1586810133 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 775416 | 560 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
n = int(input())
list_ABC = [ list(map(int,input().split(" "))) for i in range(n-1)]
q, k = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for ... |
s029712847 | p03634 | u011062360 | 1586809971 | Python | Python (3.4.3) | py | Runtime Error | 2123 | 1229916 | 544 | import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
n = int(input())
list_ABC = [ list(map(int,input().split(" "))) for i in range(n-1)]
q, k = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for ... |
s612164022 | p03634 | u652057333 | 1586669467 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1430 | 125528 | 748 | from collections import defaultdict
n = int(input())
abc = []
edges = defaultdict(lambda: [])
for _ in range(n-1):
a, b, c = map(int, input().split())
edges[a].append([b, c])
edges[b].append([a, c])
q, k = map(int, input().split())
# k からの距離を求める
dist = [-1 for _ in range(n+1)]
is_checked = [False for _ i... |
s268158289 | p03634 | u426572476 | 1586535052 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 3013 | import sys
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)
class UnionFin... |
s418426794 | p03634 | u047102107 | 1586474132 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1760 | 106144 | 543 | from heapq import heapify, heappush, heappop
n = int(input())
G = [[] for _ in range(n + 1)]
for _ in range(n - 1):
ai, bi, ci = map(int, input().split())
G[ai].append((bi, ci))
G[bi].append((ai, ci))
Q, K = map(int, input().split())
# 頂点KからDFSする
d = [None for _ in range(n + 1)]
def dfs(v, dist):
f... |
s094104014 | p03634 | u151005508 | 1586199594 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1394 | 130776 | 612 | N = int(input())
abc=[]
for _ in range(N-1):
abc.append(tuple(map(int, input().split())))
Q, K = map(int, input().split())
xy=[]
for _ in range(Q):
xy.append(tuple(map(int, input().split())))
#print(abc)
#print(xy)
G = [[] for _ in range(N+1)]
for el in abc:
a,b,c = el
G[a].append((b,c))
G[b].appen... |
s339634956 | p03634 | u007550226 | 1586100701 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 50728 | 557 | n= int(input())
branchdict = {}
for i in range(n-1):
a,b,c= map(int,input().split())
branchdict[a-1] = branchdict.get(a-1,[]) + [(b-1,c)]
branchdict[b-1] = branchdict.get(b-1,[]) + [(a-1,c)]
q,k= map(int,input().split())
cost = [0] * n
def dfs(curnode,pre,addcost):
cost[curnode]=addcost
if curnode i... |
s583981719 | p03634 | u007550226 | 1586100617 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 44948 | 583 | n= int(input())
branchdict = {}
for i in range(n-1):
a,b,c= map(int,input().split())
branchdict[a-1] = branchdict.get(a-1,[]) + [(b-1,c)]
branchdict[b-1] = branchdict.get(b-1,[]) + [(a-1,c)]
q,k= map(int,input().split())
cost = [0] * n
def dfs(curnode,pre,addcost):
cost[curnode]=addcost
passedf[curn... |
s250318008 | p03634 | u007550226 | 1586094492 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 51500 | 581 | n= int(input())
branchdict = {}
for i in range(n-1):
a,b,c= map(int,input().split())
branchdict[a-1] = branchdict.get(a-1,[]) + [(b-1,c)]
branchdict[b-1] = branchdict.get(b-1,[]) + [(a-1,c)]
q,k= map(int,input().split())
passedf = [False] * n
cost = [0] * n
def dfs(curnode,addcost):
cost[curnode]=addcos... |
s102148269 | p03634 | u007550226 | 1586094192 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 57636 | 528 | n= int(input())
branchdict = {}
for i in range(n-1):
a,b,c= map(int,input().split())
branchdict[a-1] = branchdict.get(a-1,[]) + [(b-1,c)]
branchdict[b-1] = branchdict.get(b-1,[]) + [(a-1,c)]
q,k= map(int,input().split())
passed = set()
cost = [0] * n
def dfs(curnode,addcost):
cost[curnode]=addcost
p... |
s199208670 | p03634 | u225388820 | 1585798796 | Python | Python (3.4.3) | py | Runtime Error | 1433 | 44540 | 537 | n = int(input())
es=[[] for _ in range(n)] # es[i] = (頂点iの(隣接する頂点,コスト)の組)
d = [0]*n # 頂点sからの最短距離
used=[True]*n
# 入力
for i in range(n-1):
a,b,c = map(int,input().split())
a,b = a-1, b-1
es[a].append((b,c))
es[b].append((a,c))
def dfs(s,dist):
used[s]=False
for v,x in es[s]:
if used[v]:... |
s450798519 | p03634 | u225388820 | 1585798767 | Python | Python (3.4.3) | py | Runtime Error | 1500 | 47212 | 546 | n = int(input())
es=[[] for _ in range(n)] # es[i] = (頂点iの(隣接する頂点,コスト)の組)
d = [0]*n # 頂点sからの最短距離
used=[True]*n
# 入力
for i in range(n-1):
a,b,c = map(int,input().split())
a,b = a-1, b-1
es[a].append((b,c))
es[b].append((a,c))
def dfs(s,dist):
used[s]=False
for v,x in es[s]:
if used[v]:... |
s568780982 | p03634 | u332906195 | 1585540288 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1722 | 114364 | 435 | N = int(input())
T, D = {i: [] for i in range(N)}, [-1] * N
for _ in range(N - 1):
a, b, c = map(int, input().split())
T[a - 1].append((b - 1, c))
T[b - 1].append((a - 1, c))
def dfs(p, c, d):
D[c] = d
for c2, d2 in T[c]:
if c2 != p:
dfs(c, c2, d + d2)
Q, K = map(int, input()... |
s410923320 | p03634 | u935984175 | 1584809930 | Python | Python (3.4.3) | py | Runtime Error | 842 | 50020 | 637 | import sys
rline = sys.stdin.readline
N = int(rline())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
a, b, c = map(int, rline().split())
a -= 1
b -= 1
graph[a].append([b, c])
graph[b].append([a, c])
to_k = [0] * N
def dfs(node, parent, dist):
to_k[node] = dist
for child, d in... |
s003371227 | p03634 | u970197315 | 1584751983 | Python | Python (3.4.3) | py | Runtime Error | 1569 | 49960 | 428 | def dfs(cur,par,d):
dist[cur]=d
for nx,nx_dist in G[cur]:
if nx==par:continue
dfs(nx,cur,d+nx_dist)
n=int(input())
G=[[] for i in range(n)]
dist=[0]*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())
k-=1
... |
s332974670 | p03634 | u577170763 | 1584721564 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 503 | sys.setrecursionlimit(10**5 + 5)
N = int(input())
g = {i: [] for i in range(1, N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
g[a].append((b, c))
g[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split())))
d = [-1 for _... |
s850589283 | p03634 | u577170763 | 1584656702 | Python | Python (3.4.3) | py | Runtime Error | 1106 | 153028 | 515 | import sys
sys.setrecursionlimit(100000)
N = int(input())
edges = {n: [] for n in range(N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
edges[a].append((b, c))
edges[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split()... |
s159622825 | p03634 | u577170763 | 1584656359 | Python | Python (3.4.3) | py | Runtime Error | 1045 | 80492 | 514 | import sys
sys.setrecursionlimit(20000)
N = int(input())
edges = {n: [] for n in range(N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
edges[a].append((b, c))
edges[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split())... |
s589190427 | p03634 | u577170763 | 1584656249 | Python | Python (3.4.3) | py | Runtime Error | 1009 | 69472 | 515 | import sys
sys.setrecursionlimit(10000)
N = int(input())
edges = {n: [] for n in range(N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
edges[a].append((b, c))
edges[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split())... |
s529325913 | p03634 | u577170763 | 1584656173 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 504 | sys.setrecursionlimit(10000)
N = int(input())
edges = {n: [] for n in range(N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
edges[a].append((b, c))
edges[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split())))
d = [-... |
s808782373 | p03634 | u577170763 | 1584656036 | Python | Python (3.4.3) | py | Runtime Error | 1131 | 67632 | 473 | N = int(input())
edges = {n: [] for n in range(N+1)}
for _ in range(N-1):
a, b, c = map(int, input().split())
edges[a].append((b, c))
edges[b].append((a, c))
Q, K = map(int, input().split())
xy = []
for _ in range(Q):
xy.append(tuple(map(int, input().split())))
d = [-1] * (N+1)
d[K] = 0
def dfs(... |
s326365287 | p03634 | u577170763 | 1584656021 | Python | Python (3.4.3) | py | Runtime Error | 19 | 2940 | 147 | 10
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
6 7 1000000000
7 8 1000000000
8 9 1000000000
9 10 1000000000
1 1
9 10 |
s351365791 | p03634 | u704284486 | 1584410885 | Python | Python (3.4.3) | py | Runtime Error | 1522 | 56040 | 692 | from collections import defaultdict
def main():
N = int(input())
depth = [0 for _ in range(N)]
tree = defaultdict(list)
for _ in range(N-1):
a,b,c = map(int,input().split())
a -= 1
b -= 1
tree[a] += [[b,c]]
tree[b] += [[a,c]]
def dfs(v,p,d):
depth[v]... |
s343625629 | p03634 | u704284486 | 1584410495 | Python | Python (3.4.3) | py | Runtime Error | 1548 | 56040 | 690 | from collections import defaultdict
def main():
N = int(input())
depth = [0 for _ in range(N)]
def dfs(v,p,d):
depth[v] = d
if tree[v]:
for u in tree[v]:
if u[0] == p:continue
dfs(u[0],v,d+u[1])
tree = defaultdict(list)
for _ in range(N-1):... |
s541113980 | p03634 | u704284486 | 1584410066 | Python | Python (3.4.3) | py | Runtime Error | 1548 | 56040 | 658 | from collections import defaultdict
def main():
N = int(input())
depth = [0 for _ in range(N)]
def dfs(v,p,d):
depth[v] = d
for u in tree[v]:
if u[0] == p:continue
dfs(u[0],v,d+u[1])
tree = defaultdict(list)
for _ in range(N-1):
a,b,c = map(int,input()... |
s181482044 | p03634 | u704284486 | 1584409966 | Python | Python (3.4.3) | py | Runtime Error | 1124 | 60336 | 694 | from collections import defaultdict
depth = [0 for _ in range(10**5+10)]
tree = defaultdict(list)
def dfs(v,p,d):
depth[v] = d
for u in tree[v]:
if u[0] == p:continue
dfs(u[0],v,d+u[1])
def main():
N = int(input())
for _ in range(N-1):
a,b,c = map(int,input().split())
a -... |
s706527067 | p03634 | u704284486 | 1584409666 | Python | Python (3.4.3) | py | Runtime Error | 1088 | 60772 | 715 | from collections import defaultdict
def main():
N = int(input())
depth = [0 for _ in range(N)]
def dfs(v,p,d):
depth[v] = d
for u in tree[v]:
if u[0] == p:continue
dfs(u[0],v,d+u[1])
tree = defaultdict(list)
for _ in range(N-1):
a,b,c = map(int,input()... |
s564502635 | p03634 | u952491523 | 1584286593 | Python | Python (3.4.3) | py | Runtime Error | 1140 | 136436 | 695 | import sys
sys.setrecursionlimit(10**5)
def d(tree, array, v):
next_v = tree.get(v)
for nv, nd in next_v:
if array[nv] == -1:
array[nv] = array[v] + nd
d(tree, array, nv)
n = int(input())
tree = {}
for i in range(n-1):
a,b,c = map(int, input().split())
a -= 1
b -= 1
array = tree.... |
s176799599 | p03634 | u952491523 | 1584285664 | Python | Python (3.4.3) | py | Runtime Error | 1182 | 53756 | 654 | def d(tree, array, v):
next_v = tree.get(v)
for nv, nd in next_v:
if array[nv] == -1:
array[nv] = array[v] + nd
d(tree, array, nv)
n = int(input())
tree = {}
for i in range(n-1):
a,b,c = map(int, input().split())
a -= 1
b -= 1
array = tree.get(a, [])
array.append((b,c))
tree[a... |
s446767035 | p03634 | u375542418 | 1584068307 | Python | Python (3.4.3) | py | Runtime Error | 2107 | 68000 | 740 | N = int(input())
tree = {i:{} for i in range(1,1+N)}
for i in range(N-1):
a,b,c = map(int, input().split())
tree[a][b] = c
tree[b][a] = c
#print(tree)
Q, K = map(int, input().split())
#Kから各点までの距離を求めていく
k_dst = {K:0}
def p_dist(node, dist):
if len(tree[node]) == 0:
k_dst[node] = dist
#p... |
s192160863 | p03634 | u375542418 | 1584067779 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 68000 | 732 | N = int(input())
tree = {i:{} for i in range(1,1+N)}
for i in range(N-1):
a,b,c = map(int, input().split())
tree[a][b] = c
tree[b][a] = c
#print(tree)
Q, K = map(int, input().split())
#Kから各点までの距離を求めていく
k_dst = {K:0}
def p_dist(node, dist):
if len(tree[node]) == 0:
k_dst[node] = dist
#p... |
s683559023 | p03634 | u375542418 | 1584067023 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 68128 | 729 | N = int(input())
tree = {i:{} for i in range(1,1+N)}
for i in range(N-1):
a,b,c = map(int, input().split())
tree[a][b] = c
tree[b][a] = c
#print(tree)
Q, K = map(int, input().split())
#Kから各点までの距離を求めていく
k_dst = {}
def p_dist(node, dist):
if len(tree[node]) == 0:
k_dst[node] = dist
#prin... |
s995251923 | p03634 | u375542418 | 1584066247 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 84624 | 827 | N = int(input())
tree = {i:{} for i in range(1,1+N)}
for i in range(N-1):
a,b,c = map(int, input().split())
tree[a][b] = c
tree[b][a] = c
#print(tree)
Q, K = map(int, input().split())
Q_list = []
for i in range(Q):
x,y = map(int, input().split())
Q_list.append([x,y])
#Kから各点までの距離を求めていく
k_dst = {}
d... |
s563313837 | p03634 | u210440747 | 1583857366 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 87972 | 879 | #!/usr/bin/python3
# -*- coding:utf-8 -*-
from collections import defaultdict
def main():
n = int(input())
tree = defaultdict(lambda : {'parent':-1, 'score':0, 'children':[]})
weights = dict()
for _ in range(n-1):
a, b, c = map(int, input().split())
tree[a]['children'].append(b)
tree[b]['children'... |
s863384236 | p03634 | u921168761 | 1583851723 | Python | Python (3.4.3) | py | Runtime Error | 1589 | 51660 | 484 | n = int(input())
G = [[] for _ in range(n)]
for i in range(n - 1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
G[a].append([b, c])
G[b].append([a, c])
vis = [False] * n
d = [-1] * n
def dfs(k, depth):
vis[k] = True
d[k] = depth
for i in G[k]: # i: [to, cost]
if not vis[i[... |
s858232394 | p03634 | u318029285 | 1583810211 | Python | Python (3.4.3) | py | Runtime Error | 1196 | 58096 | 611 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(1, N):
a, b, c = map(int, input().split())
a, b = a - 1, b - 1
edges[a].append([b, c])
edges[b].append([a, c])
Q, K = map(int, input().split())
K -= 1
dist = [10**9 + 1] * N
dist[K] = 0
def dfs(s, before=-1):
for edge in edges[s]:
... |
s365053092 | p03634 | u318029285 | 1583810141 | Python | Python (3.4.3) | py | Runtime Error | 1129 | 57956 | 616 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(1, N):
a, b, c = map(int, input().split())
a, b = a - 1, b - 1
edges[a].append([b, c])
edges[b].append([a, c])
Q, K = map(int, input().split())
K -= 1
dist = [pow(10, 9) + 1] * N
dist[K] = 0
def dfs(s, before=-1):
for edge in edges[s]... |
s139338916 | p03634 | u318029285 | 1583733357 | Python | Python (3.4.3) | py | Runtime Error | 1583 | 50104 | 560 | N = int(input())
edges = [[] for _ in range(N)]
for i in range(1, N):
a, b, c = map(int, input().split())
a, b = a - 1, b - 1
edges[a].append([b, c])
edges[b].append([a, c])
Q, K = map(int, input().split())
K -= 1
dist = [pow(10, 9) + 1] * N
dist[K] = 0
def dfs(s, before=-1):
for edge in edges[s... |
s890933834 | p03634 | u391667116 | 1583642683 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 1820 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) {
return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) {
return *(char*)a -... |
s623492703 | p03634 | u291766461 | 1583090195 | Python | Python (3.4.3) | py | Runtime Error | 1400 | 44752 | 505 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
edges[a].append((b, c))
edges[b].append((a, c))
depth = [0] * N
def dfs(v, p, d):
depth[v] = d
for e in edges[v]:
if e[0] == p:
continue
dfs(e[... |
s911450698 | p03634 | u431981421 | 1583001200 | Python | Python (3.4.3) | py | Runtime Error | 1382 | 89444 | 540 | def rec(p, sum, prev):
global dist
global G
if dist[p] != 0:
return
dist[p] = sum
for g in G[p]:
if g[0] == prev:
continue
rec(g[0], g[1]+sum, p)
N = int(input())
li = [list(map(int, input().split())) for n in range(N-1)]
Q, K = map(int, input().split())
Ques = [list(map(int, input().split... |
s400209713 | p03634 | u431981421 | 1582995325 | Python | Python (3.4.3) | py | Runtime Error | 1368 | 89444 | 510 | def rec(p, sum, prev):
global dist
global G
dist[p] = sum
for g in G[p]:
if g[0] == prev:
continue
rec(g[0], g[1]+sum, p)
N = int(input())
li = [list(map(int, input().split())) for n in range(N-1)]
Q, K = map(int, input().split())
Ques = [list(map(int, input().split())) for q in range(Q)]
dist =... |
s489814934 | p03634 | u561231954 | 1582657305 | Python | Python (3.4.3) | py | Runtime Error | 839 | 50212 | 709 | def main():
import sys
input=sys.stdin.readline
n=int(input())
edges=[[] for _ in range(n)]
for i in range(n-1):
a,b,c=map(int,input().split())
a-=1
b-=1
edges[a].append([b,c])
edges[b].append([a,c])
q,k=map(int,input().split())
k-=1
dist=[10*... |
s486714891 | p03634 | u798818115 | 1582558631 | Python | Python (3.4.3) | py | Runtime Error | 1562 | 51348 | 491 | # coding: utf-8
# Your code here!
def dfs(num,cost):
visited[num]=cost
for item in way[num]:
if visited[item[0]]==-1:
dfs(item[0],cost+item[1])
return
N=int(input())
way=[[] for i in range(N)]
visited=[-1]*N
for _ in range(N-1):
a,b,c=map(int,input().split())
way[a-1].appen... |
s608139605 | p03634 | u970308980 | 1582258808 | Python | Python (3.4.3) | py | Runtime Error | 1570 | 59324 | 553 | from collections import defaultdict
def dfs(v, parent, d):
depth[v] = d
for to, cost in tree[v]:
if to == parent:
continue
dfs(to, v, d + cost)
depth = defaultdict(int)
tree = defaultdict(list)
n = int(input())
for i in range(n-1):
a, b, c = map(int, input().split())
a -=... |
s390455174 | p03634 | u358254559 | 1582249125 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1027 | 82008 | 603 | n = int(input())
abc=[]
for i in range(n-1):
tmp = list(map(int,input().split()))
abc.append(tmp)
q,k = map(int, input().split())
que = []
for i in range(q):
tmp = list(map(int,input().split()))
que.append(tmp)
from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, john... |
s362921218 | p03634 | u797994565 | 1582240233 | Python | Python (3.4.3) | py | Runtime Error | 1408 | 46076 | 441 | N = int(input())
Edges = [[] for i in range(N)]
for i in range(N-1):
a,b,c = map(int,input().split())
a,b = a-1,b-1
Edges[a].append((b,c))
Edges[b].append((a,c))
D = [float('inf') for i in range(N)]
def dfs(v,p,d):
D[v] = d
for e1,e2 in Edges[v]:
if e1 != p:
dfs(e1,v,d+e2)
Q,... |
s129696060 | p03634 | u408620326 | 1581832159 | Python | Python (3.4.3) | py | Runtime Error | 841 | 188780 | 664 | import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
N = int(input())
p = [deque([]) for _ in range(N)]
for i in range(N-1):
a, b, c = [int(x) for x in input().strip().split()]
p[a-1].append((b, c))
p[b-1].append((a, c))
Q, K = [int(x) for x in input().strip()... |
s783461722 | p03634 | u408620326 | 1581832064 | Python | PyPy3 (2.4.0) | py | Runtime Error | 933 | 136968 | 633 | import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
p = [deque([]) for _ in range(N)]
for i in range(N-1):
a, b, c = [int(x) for x in input().strip().split()]
p[a-1].append((b, c))
p[b-1].append((a, c))
Q, K = [int(x) for x in input().strip().split()]
c = [-1] * N
f = [Fa... |
s908805347 | p03634 | u577138895 | 1581796123 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1446 | 126368 | 782 | N = int(input())
# 頂点 -> 隣接している頂点と距離のリスト
V = [[] for _ in range(N)]
for _ in range(N - 1):
a, b, c = map(int, input().split())
V[a - 1].append([b - 1, c])
V[b - 1].append([a - 1, c])
Q, K = map(int, input().split())
# クエリをリストに格納
query = []
for _ in range(Q):
x, y = map(int, input().split())
query.append([x - 1... |
s171644899 | p03634 | u577138895 | 1581795593 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1490 | 126240 | 689 | N = int(input())
# 頂点 -> 隣接している頂点と距離のリスト
V = [[] for _ in range(N)]
for _ in range(N - 1):
a, b, c = map(int, input().split())
V[a - 1].append([b - 1, c])
V[b - 1].append([a - 1, c])
Q, K = map(int, input().split())
query = []
for _ in range(Q):
x, y = map(int, input().split())
query.append([x - 1, y - 1])
#... |
s528338299 | p03634 | u098012509 | 1581248178 | Python | Python (3.4.3) | py | Runtime Error | 815 | 137260 | 726 | import sys
input = sys.stdin.readline
d = []
ABC = []
sys.setrecursionlimit(10 ** 5 + 1)
def solve(i, dis):
global d
global ABC
d[i] = dis
for n, c in ABC[i]:
if d[n] == -1:
solve(n, dis + c)
def main():
N = int(input())
global ABC
ABC = [[] for _ in range(N + 1)]
... |
s620395927 | p03634 | u098012509 | 1581247768 | Python | Python (3.4.3) | py | Runtime Error | 797 | 50048 | 691 | import sys
input = sys.stdin.readline
d = []
ABC = []
def solve(i, dis):
global d
global ABC
d[i] = dis
for n, c in ABC[i]:
if d[n] == -1:
solve(n, dis + c)
def main():
N = int(input())
global ABC
ABC = [[] for _ in range(N + 1)]
global d
d = [-1] * (N + 2)... |
s553811292 | p03634 | u098012509 | 1581247376 | Python | Python (3.4.3) | py | Runtime Error | 835 | 50048 | 681 | import sys
input = sys.stdin.readline
d = []
ABC = []
def solve(i, dis):
global d
global ABC
d[i] = dis
for n, c in ABC[i]:
if d[n] == -1:
solve(n, dis + c)
def main():
N = int(input())
global ABC
ABC = [[] for j in range(N)]
global d
d = [-1] * N
for _... |
s400085057 | p03634 | u098012509 | 1581247252 | Python | Python (3.4.3) | py | Runtime Error | 648 | 43800 | 681 | import sys
input = sys.stdin.readline
d = []
ABC = []
def solve(i, dis):
global d
global ABC
d[i] = dis
for n, c in ABC[i]:
if d[n] == -1:
solve(n, dis + c)
def main():
N = int(input())
global ABC
ABC = [[] for j in range(N)]
global d
d = [-1] * N
for _... |
s861323319 | p03634 | u098012509 | 1581246341 | Python | Python (3.4.3) | py | Runtime Error | 2232 | 1958592 | 655 | import sys
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
input = sys.stdin.readline
def main():
N = int(input())
edge = [[0] * N for j in range(N)]
for _ in range(N - 1):
a, b, c = [int(x) for x in input().split()]
edge... |
s560857005 | p03634 | u098012509 | 1581245979 | Python | PyPy3 (2.4.0) | py | Runtime Error | 180 | 40240 | 656 | import sys
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, csgraph_from_dense
input = sys.stdin.readline
def main():
N = int(input())
edge = [[0] * N for j in range(N)]
for _ in range(N - 1):
a, b, c = [int(x) for x in input().split()]
edge... |
s296074321 | p03634 | u984264252 | 1580859921 | Python | Python (3.4.3) | py | Runtime Error | 1076 | 57924 | 459 | N = int(input())
g = [[] for x in range(N+1)]
for i in range(N - 1):
(a, b, c) = map(int, input().split())
g[a].append([b, c])
g[b].append([a, c])
(Q, K) = map(int, input().split())
d = [-1] * (N+1)
d[K] = 0
def fill(i):
for v in g[i]:
if(d[v[0]] == -1):
d[v[0]] = d[i] + v[1]
fill(v[0])
retu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.