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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s013725681 | p03634 | u533039576 | 1565622291 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1794 | 109856 | 537 | 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
visited = [0] * n
d = [0] * n
def dfs(v, c):
for u, c2 in edges[v]:
if visited[... |
s407195566 | p03634 | u947883560 | 1565350411 | Python | Python (3.4.3) | py | Runtime Error | 1131 | 182208 | 3299 | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(100000)
INF = float("inf")
class Graph(object):
"""グラフを扱うオブジェクト
"""
def __init__(self, N):
self.N = N
self.edges = defaultdict(list)
pass
def add_edges(self, from_, to_, we... |
s463848695 | p03634 | u947883560 | 1565350223 | Python | Python (3.4.3) | py | Runtime Error | 828 | 180360 | 1917 | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
sys.setrecursionlimit(10**6)
INF = float("inf")
class Graph(object):
"""グラフを扱うオブジェクト
"""
def __init__(self, N):
self.N = N
self.edges = defaultdict(list)
pass
def add_edges(self, from_, to_, wei... |
s567522051 | p03634 | u947883560 | 1565350079 | Python | Python (3.4.3) | py | Runtime Error | 802 | 72044 | 1937 | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
INF = float("inf")
class Graph(object):
"""グラフを扱うオブジェクト
"""
def __init__(self, N):
self.N = N
self.edges = defaultdict(list)
pass
def add_edges(self, from_, to_, weight):
"""必ず0インデックスで入力... |
s553139684 | p03634 | u947883560 | 1565347029 | Python | Python (3.4.3) | py | Runtime Error | 1240 | 85988 | 3269 | #!/usr/bin/env python3
import sys
import math
from collections import defaultdict
INF = float("inf")
class Graph(object):
"""グラフを扱うオブジェクト
"""
def __init__(self, N):
self.N = N
self.edges = defaultdict(list)
pass
def add_edges(self, from_, to_, weight):
"""必ず0インデックスで入力... |
s589782326 | p03634 | u525065967 | 1564395277 | Python | Python (3.4.3) | py | Runtime Error | 1591 | 49340 | 538 | ## abc070d: Transit Tree Path
n = int(input())
T = [None]*(n+1)
for _ in range(n-1):
v1,v2,d = map(int, input().split())
if(T[v1] is None): T[v1] = [[v2,d]]
else: T[v1].append([v2,d])
if(T[v2] is None): T[v2] = [[v1,d]]
else: T[v2].append([v1,d])
depth = [0 for _ in range(n+1)]
def dfs(p, c, d)... |
s575184839 | p03634 | u525065967 | 1564394217 | Python | Python (3.4.3) | py | Runtime Error | 1568 | 49404 | 631 | ## abc070d: Transit Tree Path
n = int(input())
T = [None]*(n+1)
for _ in range(n-1):
v1,v2,d = map(int, input().split())
if(T[v1] is None): T[v1] = [[v2,d]] # [child, distance]
else: T[v1].append([v2,d])
if(T[v2] is None): T[v2] = [[v1,d]]
else: T[v2].append([v1,d])
depth = [-1 for _ in range(n+... |
s240460701 | p03634 | u877470159 | 1563732615 | Python | PyPy3 (2.4.0) | py | Runtime Error | 672 | 74912 | 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())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
while len(stack)!=[]:
now=stack.pop()
d=dis[now]
for i in G[now]:
if dis[i[0]]==-1:
... |
s833670384 | p03634 | u796060588 | 1563685646 | Python | Python (3.4.3) | py | Runtime Error | 2107 | 61040 | 1023 | import collections
stack = collections.deque()
N = int(input())
a = [-1] * (N-1)
b = [-1] * (N-1)
c = [-1] * (N-1)
cost = [0] * (N+1)
nodes = [[] for _ in range(N+1)]
yet = [int(ele) for ele in range(1, N+1)]
for i in range(N-1):
a[i], b[i], c[i] = [int(ele) for ele in input().split()] # 無効グラフなので、逆にも
nodes[... |
s316542221 | p03634 | u877470159 | 1563685190 | Python | PyPy3 (2.4.0) | py | Runtime Error | 669 | 67872 | 507 | 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())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
import deque
stack=deque(stack)
while len(stack)>0:
now=stack.pop()
d=dis[now]
for i in G[now... |
s373163678 | p03634 | u745561510 | 1563474702 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 189344 | 1381 | import sys
sys.setrecursionlimit(100000)
N = int(input())
maze = [list(map(int, input().split())) for i in range(N - 1)]
Q, K = map(int, input().split())
query = [list(map(int, input().split())) for i in range(Q)]
visited = [-1] * N
ans = 0
maze_hash = {}
#繋がっている点をハッシュで表現する
for i in maze:
if (i[0] - 1) in maze_... |
s265377556 | p03634 | u745561510 | 1563474109 | Python | Python (3.4.3) | py | Runtime Error | 2114 | 187652 | 1258 | import sys
sys.setrecursionlimit(100000)
N = int(input())
maze = [list(map(int, input().split())) for i in range(N - 1)]
Q, K = map(int, input().split())
query = [list(map(int, input().split())) for i in range(Q)]
visited = [-1] * N
ans = 0
maze_hash = {}
#繋がっている点をハッシュで表現する
for i in maze:
if (i[0] - 1) in maze_... |
s719790829 | p03634 | u073549161 | 1563380972 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1386 | 125728 | 744 | n = int(input())
dat =[]
link = []
for i in range(n+1):
link.append([])
cost = [-1] * (n + 1)
for i in range(n - 1):
a, b, c = map(int, input().split())
dat.append((a, b, c))
link[a].append((b,c))
link[b].append((a,c))
dat_q = []
q, k = map(int, input().split())
for i in range(q):
x, y = map(... |
s959848777 | p03634 | u919633157 | 1562936051 | Python | Python (3.4.3) | py | Runtime Error | 644 | 44564 | 564 | # 2019/07/12
# DFS ver
import sys
input=sys.stdin.readline
n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
u,v,c=map(int,input().split())
u-=1 ; v-=1
edge[u].append((c,v))
edge[v].append((c,u))
q,k=map(int,input().split())
k-=1
d=[0]*n
visited=[False]*n
def dfs(s,p):
visited[s]... |
s808018813 | p03634 | u111497285 | 1562515605 | Python | Python (3.4.3) | py | Runtime Error | 546 | 81208 | 1512 | # http://wakabame.hatenablog.com/entry/2017/09/03/213522
# おまじない
import sys
input = sys.stdin.readline
# ノード数
N = int(input())
# 各要素は(元ノード, 先ノード, コスト)のタプルになっている
edges = [list(map(int, input().split())) for i in range(N)]
# クエリ数と経由ノード
Q, K = map(int, input().split())
# クエリ一覧
xy = [list(map(int, input().split())) for... |
s720701785 | p03634 | u111497285 | 1562515497 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 1509 | # http://wakabame.hatenablog.com/entry/2017/09/03/213522
# おまじない
import sys
input = sys.stdin.readline
# ノード数
N = int(input())
# 各要素は(元ノード, 先ノード, コスト)のタプルになっている
edges = [list(map(int, input().split())) for i in range(N)]
# クエリ数と経由ノード
Q, K = map(int, input().split())
# クエリ一覧
xy = [list(map(int, input().split())) for... |
s361273237 | p03634 | u614314290 | 1562174974 | Python | Python (3.4.3) | py | Runtime Error | 1086 | 106764 | 543 | 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)]
tree = [{} for _ in range(N)]
for a, b, c in ABC:
a, b = a - 1, b - 1
tree[a][b] = c
tree[b][a] = c
costs = {}
def dfs(current, cost):
global cos... |
s657369917 | p03634 | u393512980 | 1562090960 | Python | Python (3.4.3) | py | Runtime Error | 838 | 174264 | 678 | import sys
sys.setrecursionlimit(100001)
def input():
return sys.stdin.readline()[:-1]
from heapq import *
def dfs(s, es):
dist = [None] * len(es)
dist[s] = 0
def ret(v, d):
for u, c in es[v]:
if dist[u] == None:
dist[u] = dist[v] + c
ret(u, dist[u])
... |
s192784184 | p03634 | u280978334 | 1561697860 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2113 | 184608 | 749 | N = int(input())
edge = {}
neighbor = [[] for _ in range(N+1)]
for _ in range(N-1):
a,b,c = map(int,input().split())
neighbor[a].append(b)
neighbor[b].append(a)
edge[(a,b)] = c
edge[(b,a)] = c
Q,K = map(int,input().split())
XY = [list(map(int,input().split())) for _ in range(Q)]
import sys
sys.setr... |
s846935654 | p03634 | u280978334 | 1561697706 | Python | Python (3.4.3) | py | Runtime Error | 967 | 77008 | 710 | N = int(input())
edge = {}
neighbor = [[] for _ in range(N+1)]
for _ in range(N-1):
a,b,c = map(int,input().split())
neighbor[a].append(b)
neighbor[b].append(a)
edge[(a,b)] = c
edge[(b,a)] = c
Q,K = map(int,input().split())
XY = [list(map(int,input().split())) for _ in range(Q)]
def bfs(Q,memo,curr... |
s810954990 | p03634 | u879870653 | 1561690070 | Python | Python (3.4.3) | py | Runtime Error | 566 | 137164 | 540 | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
T = [[] for _ in range(N+1)]
for _ in range(N-1) :
a,b,c = map(int,input().split())
T[a].append([b,c])
T[b].append([a,c])
Q,K = map(int,input().split())
dist = [None]*(N+1)
def dfs(now,d) :
dist[now] = d
for to... |
s659314154 | p03634 | u879870653 | 1561689611 | Python | Python (3.4.3) | py | Runtime Error | 1043 | 56232 | 471 | N = int(input())
T = [[] for i in range(N+1)]
for i in range(N-1) :
a,b,c = map(int,input().split())
T[a].append([b,c])
T[b].append([a,c])
Q,K = map(int,input().split())
dist = [None]*(N+1)
def dfs(now,d) :
dist[now] = d
for to,c in T[now] :
if dist[to] is not None :
continue... |
s651598188 | p03634 | u360116509 | 1561689179 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1654 | 106016 | 507 | N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
D[a].append((b, c))
D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)
def dfs(c, p, d):
DS[c] = d
for r in D[c]:
if r[0] == p:
... |
s971926724 | p03634 | u360116509 | 1561689096 | Python | Python (3.4.3) | py | Runtime Error | 1377 | 43680 | 507 | N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
D[a].append((b, c))
D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 2)
def dfs(c, p, d):
DS[c] = d
for r in D[c]:
if r[0] == p:
... |
s159278847 | p03634 | u360116509 | 1561689001 | Python | Python (3.4.3) | py | Runtime Error | 1362 | 43680 | 507 | N = int(input())
D = [[] for _ in range(N + 1)]
for _ in range(N - 1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
D[a].append((b, c))
D[b].append((a, c))
Q, K = map(int, input().split())
DS = [-1] * (N + 1)
def dfs(c, p, d):
DS[c] = d
for r in D[c]:
if r[0] == p:
... |
s113209839 | p03634 | u350997995 | 1561512058 | Python | Python (3.4.3) | py | Runtime Error | 1526 | 50064 | 450 | N = int(input())
t = [[]for i in range(N+1)]
for i in range(N-1):
a,b,c = map(int,input().split())
t[a].append([b,c])
t[b].append([a,c])
Q,K = map(int,input().split())
#p is parent
#pcd is parent-child distance
d = [0 for i in range(N+1)]
def f(v,p,pcd):
global t,d
d[v] = pcd
for c in t[v]:
... |
s966530784 | p03634 | u350997995 | 1561390185 | Python | Python (3.4.3) | py | Runtime Error | 793 | 65100 | 498 | import sys
N = int(input())
t = [[]for i in range(N+1)]
lines = sys.stdin.readlines()
for i in range(N-1):
a,b,c = map(int,lines[i].split())
t[a].append([b,c])
t[b].append([a,c])
Q,K = map(int,lines[N-1].split())
#p is parent
#pcd is parent-child distance
d = [0 for i in range(N+1)]
def f(v,p,pcd):
glob... |
s544778662 | p03634 | u350997995 | 1561389457 | Python | Python (3.4.3) | py | Runtime Error | 1574 | 50064 | 451 | N = int(input())
t = [[]for i in range(N+1)]
for i in range(N-1):
a,b,c = map(int,input().split())
t[a].append([b,c])
t[b].append([a,c])
Q,K = map(int,input().split())
#p is parent
#pcd is parent-child distance
d = [0 for i in range(N+1)]
def f(v,p,pcd):
global t,d
d[v] = pcd
for c in t[v]:
... |
s318381115 | p03634 | u350997995 | 1561385921 | Python | Python (3.4.3) | py | Runtime Error | 2109 | 102184 | 574 | from collections import defaultdict
N = int(input())
##
v = defaultdict(lambda: [])
d = [defaultdict(lambda: 0) for _ in range(N+1)]
##
for i in range(N-1):
a,b,c = map(int,input().split())
v[a].append(b)
v[b].append(a)
d[a][b] = c
d[b][a] = c
Q,K = map(int,input().split())
##
reached = defaultdict(... |
s931245178 | p03634 | u350997995 | 1561385629 | Python | Python (3.4.3) | py | Runtime Error | 1855 | 107532 | 573 | from collections import defaultdict
N = int(input())
##
v = defaultdict(lambda: [])
d = defaultdict(lambda: defaultdict(lambda: 0))
##
for i in range(N-1):
a,b,c = map(int,input().split())
v[a].append(b)
v[b].append(a)
d[a][b] = c
d[b][a] = c
Q,K = map(int,input().split())
##
reached = defaultdict(l... |
s065708215 | p03634 | u057109575 | 1561244354 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1793 | 126120 | 577 | from collections import defaultdict
N = int(input())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
graph = defaultdict(set)
for v, w, c in edges:
graph[v].add((w, c))
graph[w].add((v, c))
INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
visited = [False] * (N + 1)
de... |
s564475430 | p03634 | u057109575 | 1561244061 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1758 | 125912 | 563 | from collections import defaultdict
N = int(input())
edges = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
graph = defaultdict(set)
for v, w, c in edges:
graph[v].add((w, c))
graph[w].add((v, c))
INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
visited = [False] * (N + 1)
de... |
s132585447 | p03634 | u247554097 | 1560895273 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1724 | 105888 | 561 | # KからDFS -> xからKまでとyからKまで
n = int(input())
graph = [[] for _ in range(n)]
costs = [0 for _ in range(n)]
for _ in range(n-1):
a, b, c = map(int, input().split())
graph[a - 1].append((b-1, c))
graph[b - 1].append((a-1, c))
q, k = map(int, input().split())
def dfs(cur, cost):
for g in graph[cur]:
... |
s183954008 | p03634 | u200785298 | 1560392583 | Python | Python (3.4.3) | py | Runtime Error | 706 | 67596 | 1551 | #!/usr/bin/env python3
import sys
def dfs(idx, visited, conn, d, cur):
visited[idx] = True
for nex in conn[idx]:
if not visited[nex[0]]:
d[nex[0]] = cur + nex[1]
d = dfs(nex[0], visited, conn, d, cur + nex[1])
return d
def solve(N: int, A: "List[int]", B: "List[int]", C: "... |
s081982494 | p03634 | u017810624 | 1560142241 | Python | Python (3.4.3) | py | Runtime Error | 1245 | 74156 | 424 | def dfs(l,d,k):
for i in l[k]:
if d[i[0]]==-1:
d[i[0]]=d[k]+i[1]
dfs(l,d,i[0])
n=int(input())
l=[[] for i in range(n)]
for i in range(n-1):
a,b,c=map(int,input().split())
l[a-1].append([b-1,c])
l[b-1].append([a-1,c])
q,k=map(int,input().split())
d=[-1 for i in range(n)]
d[k-1]=0
dfs(l,d,k-1)
L=... |
s657149959 | p03634 | u895515293 | 1560066680 | Python | Python (3.4.3) | py | Runtime Error | 1103 | 62516 | 497 | N=int(input())
NODES={}
for i in range(N-1):
a,b,c=map(int,input().split())
if not a in NODES:
NODES[a] = []
if not b in NODES:
NODES[b] = []
NODES[a].append((b, c))
NODES[b].append((a, c))
Q,K=map(int,input().split())
MP=[-1]*(N+1)
MP[K]=0
def dfs(k):
for i, c in NODES[k]:
... |
s042680977 | p03634 | u712822150 | 1559776688 | Python | Python (3.4.3) | py | Runtime Error | 1070 | 618228 | 535 | import sys
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
def main():
n = int(input())
graph = np.zeros((n + 1, n + 1))
for i in range(n-1):
a, b, c = [int(x) for x in input().split()]
graph[a, b] = c
graph = csr_matrix(graph)
q, k ... |
s939846541 | p03634 | u367130284 | 1559757988 | Python | Python (3.4.3) | py | Runtime Error | 2249 | 1980956 | 1033 | #from numpy import*
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby... |
s881993496 | p03634 | u365364616 | 1559753292 | Python | Python (3.4.3) | py | Runtime Error | 940 | 75640 | 543 | def dfs(i, V, E):
vi = V[i]
for j, value in E[i].items():
if V[j] > value + vi:
V[j] = value + vi
V = dfs(j, V, E)
return V
INF = 10 ** 14
n = int(input())
V = [INF for _ in range(n + 1)]
E = [{} for _ in range(n + 1)]
for i in range(n - 1):
ai, bi, ci = map(int, input()... |
s719197788 | p03634 | u712822150 | 1559665181 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1738 | 106560 | 524 | def dfs(v, parent):
for tail, weight in adj[v]:
if tail == parent:
continue
dist[tail] = dist[v] + weight
dfs(tail, v)
n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
a, b, c = [int(x) for x in input().split()]
adj[a].append((b, c))
adj[b].a... |
s759795483 | p03634 | u712822150 | 1559664413 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1681 | 101808 | 526 | def dfs(v, parent):
for edge in adj[v]:
if edge[0] == parent:
continue
dist[edge[0]] = dist[v] + edge[1]
dfs(edge[0], v)
n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
a, b, c = [int(x) for x in input().split()]
adj[a].append((b, c))
adj[b]... |
s056338800 | p03634 | u310678820 | 1559484492 | Python | Python (3.4.3) | py | Runtime Error | 2247 | 1999760 | 413 | from scipy.sparse.csgraph import shortest_path
n = int(input())
mat=[[0]*n for i in range(n)]
for i in range(n-1):
a, b, c = map(int, input().split())
mat[a-1][b-1]=c
mat[b-1][a-1]=c
q, k = map(int, input().split())
distance = shortest_path(mat, directed = False, indices = [k-1], method = 'D')
for i in ran... |
s801190968 | p03634 | u389910364 | 1559354753 | Python | Python (3.4.3) | py | Runtime Error | 888 | 188836 | 720 | import sys
sys.setrecursionlimit(100000)
INF = float('inf')
N = int(sys.stdin.readline())
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]
Q, K = list(map(int, sys.stdin.readline().split()))
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(Q)]))
def dfs(v, a, graph, ... |
s890614882 | p03634 | u389910364 | 1559354670 | Python | Python (3.4.3) | py | Runtime Error | 880 | 85844 | 719 | import sys
sys.setrecursionlimit(10000)
INF = float('inf')
N = int(sys.stdin.readline())
ABC = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]
Q, K = list(map(int, sys.stdin.readline().split()))
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(Q)]))
def dfs(v, a, graph, r... |
s415941428 | p03634 | u509368316 | 1559046430 | Python | Python (3.4.3) | py | Runtime Error | 1189 | 88428 | 478 | N=int(input())
edge=[list(map(int,input().split())) for i in range(N-1)]
inf=10**15
c=[[] for i in range(N)]
for i,j,w in edge:
c[i-1].append((j-1,w))
c[j-1].append((i-1,w))
Q,K=map(int, input().split())
d=[inf]*N
d[K-1]=0
v=[0]*N
def dfs(p,v,d):
for n,w in c[p]:
if v[n]==0:
d[n]=min(d[n... |
s212980588 | p03634 | u923279197 | 1558982432 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1752 | 117152 | 506 | n = int(input())
data = [[] for i in range(n)]
for i in range(n-1):
a,b,c = map(int,input().split())
a -= 1
b -= 1
data[a].append([b,c])
data[b].append([a,c])
dist = [-1 for i in range(n)]
q,k = map(int,input().split())
k -= 1
dist[k] = 0
def dfs(now,pre,d):
dist[now] = d
for p,q in data[n... |
s758375384 | p03634 | u912862653 | 1558590217 | Python | Python (3.4.3) | py | Runtime Error | 1492 | 49920 | 385 | def dfs(v, d):
global D
D[v] = d
for u,dd in G[v]:
if D[u] is not None:
continue
dfs(u, d+dd)
N = int(input())
G = [[] for _ in range(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())
D = [None]*(N+1)
dfs(K, 0)
for _ in... |
s424705621 | p03634 | u912862653 | 1558589235 | Python | Python (3.4.3) | py | Runtime Error | 1585 | 50752 | 444 | def dfs(v, p, d):
global D
global S
D[v-1] = d
for g in G[v-1]:
if S[g[0]-1]==0:
continue
S[g[0]-1] = 0
dfs(g[0], v, d+g[1])
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b, c = map(int, input().split())
G[a-1].append([b, c])
G[b-1].append([a, c])
S = [-1]*N
Q, K = map(int, input... |
s132166965 | p03634 | u912862653 | 1558588680 | Python | Python (3.4.3) | py | Runtime Error | 1477 | 46476 | 421 | def dfs(v, p, d):
global D
global G
D[v-1] = d
while G[v-1]!=[]:
g = G[v-1].pop()
if g[0]==p:
continue
dfs(g[0], v, d+g[1])
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b, c = map(int, input().split())
G[a-1].append([b, c])
G[b-1].append([a, c])
Q, K = map(int, input().split())
... |
s725407557 | p03634 | u102461423 | 1558491658 | Python | Python (3.4.3) | py | Runtime Error | 631 | 43748 | 462 | import sys
input = sys.stdin.readline
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())
dist = [None]*(N+1)
def set_dist(x,d):
dist[x] = d
for y,dd in edge[x]:
if dist[y] i... |
s999425583 | p03634 | u102461423 | 1558490634 | Python | Python (3.4.3) | py | Runtime Error | 171 | 13676 | 443 | from scipy.sparse import lil_matrix
import sys
input = sys.stdin.readline
print(scipy.__version__())
N = int(input())
edge = lil_matrix((N+1,N+1))
for _ in range(N-1):
a,b,c = map(int,input().split())
edge[a,b] = c
Q,K = map(int,input().split())
from scipy.sparse.csgraph import dijkstra
dist = dijkstra(edge,... |
s737454329 | p03634 | u606045429 | 1558329467 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1461 | 124448 | 493 | N = int(input())
E = [[] for _ in range(N + 1)]
for a, b, c in [[int(i) for i in input().split()] for _ in range(N - 1)]:
E[a].append((b, c))
E[b].append((a, c))
Q, K = [int(i) for i in input().split()]
dist = [0] * (N + 1)
def dfs(cur, parent, d):
dist[cur] = d
for to, cost in E[cur]:
if to ... |
s656699334 | p03634 | u067729694 | 1558306058 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3192 | 1093 | N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
a,b,c = map(int, input().split())
ABC.append((a,b,c))
edges = ABC[:]
def warshall_floyd(d, n):
# d: グラフ二次元リスト
# n: 頂点数 (0始まり)
#d[i][j]: iからjへの最短距離
for k in range(n):
for i in range... |
s709255099 | p03634 | u129836004 | 1558186274 | Python | Python (3.4.3) | py | Runtime Error | 1393 | 131020 | 498 | import sys
sys.setrecursionlimit(10**5)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
a, b, c = map(int,input().split())
G[a] += (b,c),
G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
d[v] = u
for t, c in G[v]:
... |
s064909144 | p03634 | u129836004 | 1558185977 | Python | Python (3.4.3) | py | Runtime Error | 459 | 26156 | 496 | import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
a, b, c = map(int,input().split())
G[a] += (b,c)
G[b] += (a,c)
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
d[v] = u
for t, c in G[v]:
... |
s742705862 | p03634 | u622523700 | 1557852965 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1531 | 125660 | 685 | n = int(input())
edge = [[[] for i in range(2)] for j in range(n)]
dp = [-1] * n
for i in range(n - 1):
a, b, c = map(int, input().split())
edge[a - 1][0].append(b - 1)
edge[a - 1][1].append(c)
edge[b - 1][0].append(a - 1)
edge[b - 1][1].append(c)
def distance(x, prev, d):
dp[x] = d
for i,... |
s998874938 | p03634 | u938812966 | 1557723178 | Python | Python (3.4.3) | py | Runtime Error | 1557 | 105428 | 416 | import sys
sys.setrecursionlimit(65536)
N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
a,b,c=map(int,input().split())
e[a].append([b, c])
e[b].append([a, c])
Q,K=map(int,input().split())
def bfs(now, dis):
if d[now] != -1:
return
d[now] = dis
for nxt, cos in e[now]:
... |
s358153619 | p03634 | u938812966 | 1557723019 | Python | Python (3.4.3) | py | Runtime Error | 1546 | 49892 | 375 | N=int(input())
d=[-1 for _ in range(N+1)]
e=[[] for _ in range(N+1)]
for _ in range(N-1):
a,b,c=map(int,input().split())
e[a].append([b, c])
e[b].append([a, c])
Q,K=map(int,input().split())
def bfs(now, dis):
if d[now] != -1:
return
d[now] = dis
for nxt, cos in e[now]:
bfs(nxt, dis+cos)
bfs(K, 0)
for _ in ran... |
s140106315 | p03634 | u620480037 | 1557540569 | Python | Python (3.4.3) | py | Runtime Error | 1543 | 50000 | 422 | N=int(input())
n=[[]for i in range(N+1)]
for i in range(N-1):
a,b,c=map(int,input().split())
n[a].append([b,c])
n[b].append([a,c])
L=[-1 for i in range(N+1)]
Q,K=map(int,input().split())
L[K]=0
def dfs(x):
for i in n[x]:
if L[i[0]]==-1:
L[i[0]]=L[x]+i[1]
dfs(i[0]... |
s411966932 | p03634 | u899975427 | 1556930973 | Python | Python (3.4.3) | py | Runtime Error | 620 | 43780 | 465 | import sys
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]
for i in range(n-1):
a,b,dist = map(int,input().split())
li[a-1].append((b-1,dist))
li[b-1].append((a-1,dist))
q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0
def dfs(x):
for node in li[x]:
if tdp[node[0]] == -1:
... |
s053952890 | p03634 | u052499405 | 1555110828 | Python | Python (3.4.3) | py | Runtime Error | 1221 | 79280 | 661 | n = int(input())
abc = [[int(item) for item in input().split()] for _ in range(n-1)]
q, k = [int(item) for item in input().split()]
xy = [[int(item) for item in input().split()] for _ in range(q)]
distance = [0] * n
e = [[] for _ in range(n)]
w = [[] for _ in range(n)]
for a, b, c in abc:
e[a-1].append(b-1)
e[... |
s287143624 | p03634 | u123756661 | 1554777860 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 738 | from collections import deque
def main()
n=int(input())
l=[0]*n
d={}
for i in range(n-1):
a,b,c=map(int,input().split())
a-=1
b-=1
if a in d:
d[a].add((b,c))
else:
d[a]={(b,c)}
if b in d:
d[b].add((a,c))
else:
... |
s756435033 | p03634 | u123756661 | 1554777738 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 707 | def main()
n=int(input())
l=[0]*n
d={}
for i in range(n-1):
a,b,c=map(int,input().split())
a-=1
b-=1
if a in d:
d[a].add((b,c))
else:
d[a]={(b,c)}
if b in d:
d[b].add((a,c))
else:
d[b]={(a,c)}
q,k... |
s820440675 | p03634 | u123756661 | 1554775455 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1661 | 108804 | 603 | from collections import deque
n=int(input())
l=[0]*n
d={}
for i in range(n-1):
a,b,c=map(int,input().split())
a-=1
b-=1
if a in d:
d[a].add((b,c))
else:
d[a]={(b,c)}
if b in d:
d[b].add((a,c))
else:
d[b]={(a,c)}
q,k=map(int,input().split())
k-=1
p=deque([k])
w... |
s230025986 | p03634 | u824327681 | 1554677439 | Python | Python (3.4.3) | py | Runtime Error | 1304 | 90580 | 785 | from collections import deque
def solve1(rs, p, v, cost, costs):
costs[v] = cost
for e in rs[v]:
if p == e[0]:
continue
solve1(rs, v, e[0], cost+e[1], costs)
return costs
n = int(input())
rs = []
for i in range(n - 1):
abc = input().split(' ')
rs.append([int(x) for x in... |
s030639406 | p03634 | u619819312 | 1554048997 | Python | Python (3.4.3) | py | Runtime Error | 1507 | 50720 | 396 | n=int(input())
s=[[]for i in range(n+1)]
g=[0]*(n+1)
h=[True]*(n+1)
for i in range(n-1):
a,b,c=map(int,input().split())
s[a].append([b,c])
s[b].append([a,c])
def dfs(x):
h[x]=False
for i in s[x]:
if h[i[0]]:
g[i[0]]=g[x]+i[1]
dfs(i[0])
q,k=map(int,input().split())
dfs... |
s553698664 | p03634 | u319818856 | 1553945237 | Python | Python (3.4.3) | py | Runtime Error | 930 | 76568 | 928 | def distances(tree: list, treeSize: int, root: int)->list:
dists = [0] * treeSize
def dfs(v: int, prev: int, dist: int):
dists[v] = dist
for u, c in tree[v]:
if u == prev:
continue
dfs(u, v, dist+c)
dfs(root, -1, 0)
return dists
def transit_t... |
s918837947 | p03634 | u669696235 | 1553571202 | Python | Python (3.4.3) | py | Runtime Error | 1809 | 65044 | 630 | import heapq
class edge:
def __init__(self,to,cost):
self.to=to
self.cost=cost
N=int(input())
G=[list() for i in range(N)]
P=[False for i in range(N)]
A=[-100 for i in range(N)]
for i in range(N-1):
a,b,c=map(int,input().split())
G[a-1].append(edge(b-1,c))
G[b-1].append(edge(a-1,c)) #無向... |
s589647984 | p03634 | u543954314 | 1553311307 | Python | Python (3.4.3) | py | Runtime Error | 1378 | 53088 | 428 | n = int(input())
inf = float("inf")
road = [dict() for _ in range(n+1)]
for _ in range(n-1):
a,b,c = map(int, input().split())
road[a][b] = c
road[b][a] = c
q,k = map(int, input().split())
dfs = [inf]*(n+1)
dfs[k] = 0
def dodfs(x):
for i in road[x]:
if dfs[i] == inf:
dfs[i] = dfs[x] + road[x][i]
... |
s050324504 | p03634 | u543954314 | 1553310292 | Python | Python (3.4.3) | py | Runtime Error | 1239 | 51020 | 447 | n = int(input())
inf = float("inf")
road = [dict() for _ in range(n)]
for _ in range(n-1):
a,b,c = map(int, input().split())
road[a-1][b-1] = c
road[b-1][a-1] = c
q,k = map(int, input().split())
dfs = [inf]*n
dfs[k-1] = 0
def dodfs(x):
for i in road[x-1]:
if dfs[i] == inf:
dfs[i] = dfs[x-1] + road[x-... |
s058012626 | p03634 | u077337864 | 1551826491 | Python | Python (3.4.3) | py | Runtime Error | 1415 | 43748 | 451 | n = int(input())
ablist = [[] for _ in range(n)]
for _ in range(n-1):
a, b, c = map(int, input().split())
ablist[a-1].append((b-1, c))
ablist[b-1].append((a-1, c))
q, k = map(int, input().split())
depth = [0 for _ in range(n)]
def dfs(v, p, d):
depth[v] = d
for to, c in ablist[v]:
if to == p:
cont... |
s223641949 | p03634 | u367130284 | 1551801735 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2111 | 127192 | 704 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
def DFS(point,d,cost,TFlist): #入力と同じindex系
for s in d[point]:
try:
p=s[0]
c=s[1]+cost[point]
if TFlist[p-... |
s539980857 | p03634 | u367130284 | 1551801629 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1917 | 127192 | 698 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
def DFS(point,d,cost,TFlist): #入力と同じindex系
for s in d[point]:
try:
p=s[0]
c=s[1]+cost[point]
if TFlist[p-... |
s058289852 | p03634 | u367130284 | 1551801300 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2111 | 127192 | 700 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
def DFS(point,d,cost,TFlist): #入力と同じindex系
for s in d[point]:
try:
p=s[0]
c=s[1]+cost[point]
if TFlist[p-... |
s319706412 | p03634 | u367130284 | 1551801054 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1934 | 126296 | 611 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
def DFS(point,d,cost,TFlist): #入力と同じindex系
for s in d[point]:
p=s[0]
c=s[1]+cost[point]
if TFlist[p-1]:
continue
... |
s379779645 | p03634 | u367130284 | 1551800266 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1927 | 126296 | 631 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
def DFS(point,d,cost,TFlist): #入力と同じindex系
for s in d[point]:
p=s[0]
c=s[1]+cost[point]
if TFlist[p-1]:
continue
... |
s838195390 | p03634 | u367130284 | 1551797484 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 56460 | 713 | import collections as c
d=c.defaultdict(list)
n=int(input())
for s in range(n-1):
a,b,c=map(int,input().split())
d[a].append([b,c])
d[b].append([a,c])
#print(d)
def DFS(point,d,cost,TFlist): #入力と同じindex系
if all(TFlist):
return cost
for s in d[point]:
p=s[0]
c=s[1]+cost... |
s414479330 | p03634 | u281303342 | 1551584735 | Python | Python (3.4.3) | py | Runtime Error | 1071 | 58024 | 505 | def dfs(n,p,d):
visited[n] = True
dist[n] = d
for (i,c) in A[n]:
if i != p and not visited[i]:
dfs(i,n,d+c)
N = int(input())
A = [[] for _ in range(N)]
for _ in range(N-1):
a,b,c = map(int,input().split())
A[a-1].append((b-1,c))
A[b-1].append((a-1,c))
Q,K = map(int,input().s... |
s964901506 | p03634 | u690536347 | 1550851764 | Python | Python (3.4.3) | py | Runtime Error | 1436 | 50144 | 531 | from collections import defaultdict
d=defaultdict(list)
N=int(input())
for _ in range(N-1):
a,b,c=map(int,input().split())
d[a].append((b,c))
d[b].append((a,c))
Q,K=map(int,input().split())
# Kを中心とした距離を求める
dists=[None]*(N+1)
isused=[False]*(N+1)
dists[K]=0
isused[K]=True
def dfs(n):
for i,j in d[n]... |
s820657278 | p03634 | u001024152 | 1550786357 | Python | Python (3.4.3) | py | Runtime Error | 493 | 37040 | 661 | # D
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
ai,bi,ci = map(int, input().split())
edge[ai-1].append((bi-1, ci))
edge[bi-1].append((ai-1, ci))
Q,K = map(int, input().split())
K = K-1
x,y = [],[]
for _ in range(Q):
xi,yi = map(int, input().split())
x.append(xi-1)
y.append(... |
s681598338 | p03634 | u099566485 | 1550741388 | Python | Python (3.4.3) | py | Runtime Error | 1832 | 52316 | 566 | def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
nl=[[] for i in range(n)]
used=[False for i in range(n)]
for i in range(n-1):
a,b,c=IL()
nl[a-1].append([b-1,c])
nl[b-1].append([a-1,c])
d=[None for i in range(n)]
def... |
s134253573 | p03634 | u214617707 | 1550334822 | Python | Python (3.4.3) | py | Runtime Error | 1461 | 43640 | 487 | 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())
dist = [-1] * N
def dfs(u, par, d):
dist[u] = d
for w, cost in G[u]:
if w == par:
con... |
s064769811 | p03634 | u634208461 | 1549909919 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 981 | import sys
sys.setrecursionlimit(10 ** 10)
class Solve():
def __init__(self):
self.N = int(input())
self.route = [dict() for _ in range(self.N)]
for _ in range(self.N - 1):
a, b, c = map(int, input().split())
self.route[a - 1][b - 1] = c
self.route[b - 1... |
s239458121 | p03634 | u634208461 | 1549909066 | Python | Python (3.4.3) | py | Runtime Error | 985 | 68672 | 961 | class Solve():
def __init__(self):
self.N = int(input())
self.route = [dict() for _ in range(self.N)]
for _ in range(self.N - 1):
a, b, c = map(int, input().split())
self.route[a - 1][b - 1] = c
self.route[b - 1][a - 1] = c
self.Q, self.K = map(int... |
s357507798 | p03634 | u766684188 | 1549855279 | Python | Python (3.4.3) | py | Runtime Error | 1622 | 50688 | 479 | 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,input().split())
k-=1
cost=[0]*n
visited=[False]*n
def DFS(s,d):
cost[s]=d
visited[s]=True
for i in TREE[s]:
if not vi... |
s777555675 | p03634 | u766684188 | 1549854617 | Python | Python (3.4.3) | py | Runtime Error | 1753 | 50740 | 499 | 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,input().split())
k-=1
depth=[0]*n
visited=[False for _ in range(n)]
def DFS(s,d):
depth[s]=d
visited[s]=True
for i in TREE[s]:... |
s839044618 | p03634 | u766684188 | 1549854139 | Python | Python (3.4.3) | py | Runtime Error | 1664 | 50752 | 500 | 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,input().split())
k-=1
depth=[0]*n
visited=[False for i in range(n)]
def DFS(s,d):
depth[s]=d
visited[s]=True
for i in TREE[s]:... |
s608333933 | p03634 | u785578220 | 1549670346 | Python | Python (3.4.3) | py | Runtime Error | 1449 | 43940 | 507 |
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, input().split())
K -= 1
depth = [0 for _ in range(N)]
def dfs(v, p = -1, d = 0):
depth[v] = d
for i, j in t... |
s258025961 | p03634 | u273201018 | 1548449189 | Python | Python (3.4.3) | py | Runtime Error | 1459 | 56704 | 715 | # N 個の頂点、N-1 個の辺なので K を根にした木構造に変換する
N = int(input())
T = {}
D = [None] * N
F = [True] * N
for n in range(N):
T[n] = []
for n in range(N-1):
a, b, c = map(int, input().split())
a -= 1
b -= 1
T[a].append([b, c])
T[b].append([b, c])
Q, K = map(int, input().split())
K -= 1
D[K] = 0
F[K] = Fals... |
s396959613 | p03634 | u309977459 | 1548301013 | Python | Python (3.4.3) | py | Runtime Error | 1421 | 43612 | 402 | N = int(input())
G = [[] for _ in range(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())
d = [-1]*(N+1)
def dfs(v, c):
d[v] = c
for nv, cost in G[v]:
if d[nv] == -1:
dfs(nv, cost+c)
dfs(K,... |
s862185300 | p03634 | u557437077 | 1548202571 | Python | Python (3.4.3) | py | Runtime Error | 1678 | 49904 | 689 | n = int(input())
# [[[ノード1, 距離3],[ノード3, 距離5]],[],...]
tree = [[] for _ in range(n+10)]
visited = [-1 for _ in range(n+10)]
# abc = [[0, 0, 0] for _ in range(n)]
for i in range(n-1):
a, b, c = [int(j) for j in input().split()]
tree[a - 1].append([b - 1, c])
tree[b - 1].append([a - 1, c])
def depth(now, cost)... |
s026290218 | p03634 | u557437077 | 1548197913 | Python | Python (3.4.3) | py | Runtime Error | 1757 | 49928 | 679 | n = int(input())
# [[[ノード1, 距離3],[ノード3, 距離5]],[],...]
tree = [[] for _ in range(n)]
visited = [-1 for _ in range(n)]
# abc = [[0, 0, 0] for _ in range(n)]
for i in range(n-1):
a, b, c = [int(j) for j in input().split()]
tree[a - 1].append([b-1, c])
tree[b - 1].append([a - 1, c])
def depth(now, cost):
vi... |
s970890434 | p03634 | u375616706 | 1548110832 | Python | Python (3.4.3) | py | Runtime Error | 1594 | 82544 | 859 | N = (int)(input())
edges = []
for _ in range(N-1):
edges.append((list)(map(int, input().split())))
Q, K = (list)(map(int, input().split()))
querys = []
for _ in range(Q):
querys.append((list)(map(int, input().split())))
'''
N:num of nodes
Q: num of query
K: node must passed in query
'''
dist = [-1]*(N+1)
... |
s948496574 | p03634 | u375616706 | 1548110597 | Python | Python (3.4.3) | py | Runtime Error | 1453 | 82608 | 806 | N = (int)(input())
edges = []
for _ in range(N-1):
edges.append((list)(map(int, input().split())))
Q, K = (list)(map(int, input().split()))
querys = []
for _ in range(Q):
querys.append((list)(map(int, input().split())))
'''
N:num of nodes
Q: num of query
K: node must passed in query
'''
dist = [-1]*(N+1)
... |
s268199892 | p03634 | u075012704 | 1547132957 | Python | Python (3.4.3) | py | Runtime Error | 1680 | 51352 | 479 | N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
a, b, c = map(int, input().split())
a, b = a - 1, b - 1
G[a].append([b, c])
G[b].append([a, c])
Q, K = map(int, input().split())
K -= 1
dist = [-1] * N
dist[K] = 0
def dfs(n):
for v, c in G[n]:
if dist[v] < 0:
... |
s886893432 | p03634 | u427344224 | 1546036431 | Python | Python (3.4.3) | py | Runtime Error | 1138 | 163932 | 718 | n = int(input())
graph = [dict() for _ 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(int, input().split())
xy = []
for i in range(q):
x, y = map(int, input().split())
xy.append([x - 1, y - 1])
depth = [0 for _ in ... |
s020547160 | p03634 | u427344224 | 1546036383 | Python | Python (3.4.3) | py | Runtime Error | 998 | 69004 | 676 | n = int(input())
graph = [dict() for _ 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(int, input().split())
xy = []
for i in range(q):
x, y = map(int, input().split())
xy.append([x - 1, y - 1])
depth = [0 for _ in ... |
s411187553 | p03634 | u199295501 | 1545332243 | Python | Python (3.4.3) | py | Runtime Error | 2123 | 849952 | 683 | # -*- coding: utf-8 -*-
from pprint import pprint as pp
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from collections import defaultdict
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 rang... |
s816102650 | p03634 | u064408584 | 1544062616 | Python | Python (3.4.3) | py | Runtime Error | 1735 | 49848 | 456 | import sys
sys.setrecursionlimit(3000)
n=int(input())
m=[[] for i in range(n)]
for i in range(n-1):
a,b,c=map(int, input().split())
m[a-1].append([b-1,c])
m[b-1].append([a-1,c])
q,k=map(int, input().split())
def reach(m,d,k):
for i in m[k]:
if d[i[0]]==-1:
d[i[0]]=d[k]+i[1]
... |
s997907207 | p03634 | u064408584 | 1544062418 | Python | Python (3.4.3) | py | Runtime Error | 1640 | 49912 | 416 | n=int(input())
m=[[] for i in range(n)]
for i in range(n-1):
a,b,c=map(int, input().split())
m[a-1].append([b-1,c])
m[b-1].append([a-1,c])
q,k=map(int, input().split())
def reach(m,d,k):
for i in m[k]:
if d[i[0]]==-1:
d[i[0]]=d[k]+i[1]
reach(m,d,i[0])
d=[-1]*n
d[k-1]... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.