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
s249736845
p03634
u054106284
1544055694
Python
PyPy3 (2.4.0)
py
Runtime Error
1005
100256
1193
import sys input = sys.stdin.readline def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける graph = [ [] for i in range(N)] for edge in edges: a, b, c = edge graph[a].append((b,c)) graph[b].append((a,c)) return graph def BFS(N, graph, start): Q = [] V = [] prev = [None] * N d...
s501202824
p03634
u054106284
1544054968
Python
PyPy3 (2.4.0)
py
Runtime Error
808
100256
1155
import sys input = sys.stdin.readline def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける graph = [ [] for i in range(N)] for edge in edges: a, b, c = edge graph[a].append((b,c)) graph[b].append((a,c)) return graph def BFS(N, graph, start): Q = [] V = [] prev = [None] * N d...
s935425439
p03634
u054106284
1544054639
Python
PyPy3 (2.4.0)
py
Runtime Error
843
101792
1161
import sys input = sys.stdin.readline def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける graph = [ [] for i in range(N)] for edge in edges: a, b, c = edge graph[a].append((b,c)) graph[b].append((a,c)) return graph def BFS(N, graph, start): Q = [] V = [] prev = [None] * N d...
s371342853
p03634
u054106284
1544054069
Python
PyPy3 (2.4.0)
py
Runtime Error
806
101536
1144
import sys input = sys.stdin.readline def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける graph = [ [] for i in range(N)] for edge in edges: a, b, c = edge graph[a].append((b,c)) graph[b].append((a,c)) return graph def BFS(N, graph, start): Q = [] V = [] prev = [None] * N d...
s436233707
p03634
u054106284
1544049769
Python
PyPy3 (2.4.0)
py
Runtime Error
703
68512
863
def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける graph = [ [] for i in range(N)] for edge in edges: a, b, c = edge graph[a].append((b,c)) graph[b].append((a,c)) return graph def BFS(N, graph, start): Q = [] V = [] d = [float("inf")] * N Q.append(start) d[start] = 0 ...
s541307482
p03634
u200030766
1542577240
Python
Python (3.4.3)
py
Runtime Error
1179
138044
796
import sys #limit=sys.getrecursionlimit() sys.setrecursionlimit(100000) #sys.setrecursionlimit(1000000000) V=int(input().strip()) E=V-1 inf=3*10**15 G=[] dist=[inf]*V for i in range(V): G.append([]) for i in range(E): at,bt,ct=map(int,input().strip().split(' ')) G[at-1].append([ct,bt-1]) G[bt-1].appen...
s521156381
p03634
u200030766
1542577174
Python
Python (3.4.3)
py
Runtime Error
17
3064
934
import sys #limit=sys.getrecursionlimit() sys.setrecursionlimit(100000) #sys.setrecursionlimit(1000000000) fileobj=open('subtask_1_28.txt','rt') V=int(fileobj.readline().strip()) E=V-1 inf=3*10**15 G=[] dist=[inf]*V visited=[False]*V for i in range(V): G.append([]) for i in range(E): at,bt,ct=map(int,fileobj...
s150965141
p03634
u200030766
1542574712
Python
Python (3.4.3)
py
Runtime Error
1155
58624
687
V=int(input().strip()) E=V-1 inf=3*10**15 G=[] dist=[inf]*V for i in range(V): G.append([]) for i in range(E): at,bt,ct=map(int,input().strip().split(' ')) G[at-1].append([ct,bt-1]) G[bt-1].append([ct,at-1]) visited=[False]*V def dfs(v,p,d): #global d dist[v]=d for q in G[v]: if q[...
s274810577
p03634
u179169725
1541980236
Python
Python (3.4.3)
py
Runtime Error
1379
68968
1047
N = int(input()) X, Y = [], [] tree = {key+1: [] for key in range(N)} # 木構造はノードをキーにする辞書にしておく # 必要なのは、あるノードを指定したときに、隣り合うノードと、コスト #[(隣のノード, コスト)]の順で格納する for n in range(N - 1): a, b, c = list(map(int, input().split())) tree[a].append((b, c)) tree[b].append((a, c)) # 方向に依存しない格納 for n in tree.keys(): tr...
s165779691
p03634
u179169725
1541979935
Python
Python (3.4.3)
py
Runtime Error
1528
65236
950
N = int(input()) X, Y = [], [] tree = {key+1: [] for key in range(N)} # 木構造はノードをキーにする辞書にしておく # 必要なのは、あるノードを指定したときに、隣り合うノードと、コスト #[(隣のノード, コスト)]の順で格納する for n in range(N - 1): a, b, c = list(map(int, input().split())) tree[a].append((b, c)) tree[b].append((a, c)) # 方向に依存しない格納 Q, K = list(map(int, input()...
s482405648
p03634
u179169725
1541979807
Python
Python (3.4.3)
py
Runtime Error
1121
65496
991
N = int(input()) X, Y = [], [] tree = {key+1: [] for key in range(N)} # 木構造はノードをキーにする辞書にしておく # 必要なのは、あるノードを指定したときに、隣り合うノードと、コスト #[(隣のノード, コスト)]の順で格納する for n in range(N - 1): a, b, c = list(map(int, input().split())) tree[a].append((b, c)) tree[b].append((a, c)) # 方向に依存しない格納 Q, K = list(map(int, input()...
s953304894
p03634
u179169725
1541979308
Python
Python (3.4.3)
py
Runtime Error
1093
65504
992
N = int(input()) X, Y = [], [] tree = {key+1: [] for key in range(N)} # 木構造はノードをキーにする辞書にしておく # 必要なのは、あるノードを指定したときに、隣り合うノードと、コスト #[(隣のノード, コスト)]の順で格納する for n in range(N - 1): a, b, c = list(map(int, input().split())) tree[a].append((b, c)) tree[b].append((a, c)) # 方向に依存しない格納 Q, K = list(map(int, input()...
s042263291
p03634
u434329006
1541870930
Python
Python (3.4.3)
py
Runtime Error
2137
493360
1407
def get_path(start, goal, prev): path = [] now = goal path.append(now) while True: path.append(prev[now]) if prev[now] == start: break now = prev[now] path.reverse() return path def search(glaph, start, goal): MAX_VAL = 0x10000000 g_size = len(glaph) visited ...
s431082612
p03634
u824237520
1541797858
Python
Python (3.4.3)
py
Runtime Error
17
3064
1026
#include <bits/stdc++.h> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--)...
s796438769
p03634
u368780724
1541162200
Python
Python (3.4.3)
py
Runtime Error
610
43544
603
from collections import defaultdict def inpl(): return [int(i) for i in input().split()] path = defaultdict(lambda: []) N = int(input()) for _ in range(N-1): a, b, c = inpl() path[a].append((b,c)) path[b].append((a,c)) ctr = 1 Q, K = inpl() now = [K] dist = [0 for _ in range(N+1)] while True: for na i...
s511284789
p03634
u944209426
1540526665
Python
PyPy3 (2.4.0)
py
Runtime Error
1397
132312
466
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)] z=[[] for _ in range(n)] for a,b,c in abc: z[a-1].append([b-1,c]) z[b-1].append([a-1,c]) depth=[0 for _ in range(100010)] def dfs(v,p,d): depth[v]=d ...
s720184004
p03634
u944209426
1540526515
Python
PyPy3 (2.4.0)
py
Runtime Error
1423
132312
461
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)] z=[[] for _ in range(n)] for a,b,c in abc: z[a-1].append([b-1,c]) z[b-1].append([a-1,c]) depth=[0 for _ in range(n)] def dfs(v,p,d): depth[v]=d for...
s120786510
p03634
u248967559
1537050234
Python
Python (3.4.3)
py
Runtime Error
1857
80040
1263
import copy import sys class Node: def __init__(self, id): self.id = id self.path = {} def __str__(self): return "id: " + str(self.id) + " path: " + str(self.path) N = int(input()) nodes = [] for i in range(N): nodes.append(Node(i)) for i in range(N-1): from_id, to_id, weight ...
s969775390
p03634
u248967559
1537049693
Python
Python (3.4.3)
py
Runtime Error
1677
72384
1184
import copy import sys class Node: def __init__(self, id): self.id = id self.path = {} def __str__(self): return "id: " + str(self.id) + " path: " + str(self.path) N = int(input()) nodes = [] for i in range(N): nodes.append(Node(i)) for i in range(N-1): from_id, to_id, weight ...
s213052367
p03634
u248967559
1537048059
Python
Python (3.4.3)
py
Runtime Error
2107
71292
1348
import copy import sys class Node: def __init__(self, id): self.id = id self.path = {} def __str__(self): return "id: " + str(self.id) + " path: " + str(self.path) N = int(input()) nodes = [] for i in range(N): nodes.append(Node(i)) for i in range(N-1): from_id, to_id, weight ...
s323838321
p03634
u476958115
1537045010
Python
Python (3.4.3)
py
Runtime Error
2132
302264
1268
# coding:utf-8 # https://beta.atcoder.jp/contests/abc075/tasks/abc075_c from collections import defaultdict import sys # import numpy as np # importするだけで200msくらいかかる!!!!!!!!!!!!11 N = [int(i) for i in sys.stdin.readline().strip().split()] N = N[0] edges = defaultdict(int) hopable = defaultdict(list) for _ in range(N-...
s367119372
p03634
u476958115
1537043919
Python
Python (3.4.3)
py
Runtime Error
2110
618772
1177
# coding:utf-8 # https://beta.atcoder.jp/contests/abc075/tasks/abc075_c import sys import itertools import numpy as np N = [int(i) for i in sys.stdin.readline().split()] N = N[0] edges = [[] for _ in range(N)] edge_mat = np.zeros((N, N)) def flatten(l): return list(itertools.chain.from_iterable(l)) for _ in range(...
s138667161
p03634
u476958115
1537043696
Python
Python (3.4.3)
py
Runtime Error
2110
618640
1178
# coding:utf-8 # https://beta.atcoder.jp/contests/abc075/tasks/abc075_c import sys import itertools import numpy as np N = [int(i) for i in sys.stdin.readline().split()] N = N[0] edges = [[] for _ in range(N)] edge_mat = np.zeros((N, N)) def flatten(l): return list(itertools.chain.from_iterable(l)) for _ in rang...
s185225912
p03634
u476958115
1537043403
Python
Python (3.4.3)
py
Runtime Error
2110
616852
1184
# coding:utf-8 # https://beta.atcoder.jp/contests/abc075/tasks/abc075_c import sys import itertools import numpy as np N = [int(i) for i in sys.stdin.readline().split()] N = N[0] edges = [[] for _ in range(N)] edge_mat = np.zeros((N, N)) def flatten(l): return list(itertools.chain.from_iterable(l)) for _ in range...
s432636708
p03634
u111508936
1537037030
Python
Python (3.4.3)
py
Runtime Error
2110
53748
851
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N = int(input()) E = dict() cost = dict() for n in range(N-1): s, t, c = map(int, input().split()) s = s-1 t = t-1 if s not in E: E[s] = [] if t not in E: E...
s501079864
p03634
u111508936
1537036611
Python
Python (3.4.3)
py
Runtime Error
2113
52904
877
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N = int(input()) E = dict() cost = dict() for n in range(N-1): s, t, c = map(int, input().split()) s = s-1 t = t-1 if s not in E: E[s] = [] if t not in E: E...
s229653604
p03634
u111508936
1537036122
Python
Python (3.4.3)
py
Runtime Error
2113
618088
625
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N = int(input()) E = np.full((N, N), -1, dtype='q') for n in range(N-1): s, t, c = map(int, input().split()) s = s-1 t = t-1 E[s][t] = c E[t][s] = c Q, K = map(int, input()...
s182033199
p03634
u828847847
1534812954
Python
Python (2.7.6)
py
Runtime Error
850
41988
472
n = int(input()) edges = [[] for _ in xrange(n)] distance = [-1 for _ in xrange(n)] for _ in xrange(n-1): f,t,c = map(int,raw_input().split()) f -= 1 t -= 1 edges[f].append((t,c)) edges[t].append((f,c)) q,k = map(int,raw_input().split()) k -= 1 def dfs(v,c): if distance[v] == -1: distance[v] = c for to,...
s909682068
p03634
u828847847
1534812155
Python
Python (2.7.6)
py
Runtime Error
1046
51452
468
n = int(input()) edges = [[] for i in range(n)] distance = [-1 for i in range(n)] for i in range(n-1): f,t,c = map(int,raw_input().split()) f -= 1 t -= 1 edges[f].append([t,c]) edges[t].append([f,c]) q,k = map(int,raw_input().split()) k -= 1 def dfs(v,c): if distance[v] == -1: distance[v] = c for to,cos...
s037756698
p03634
u828847847
1534812114
Python
Python (2.7.6)
py
Runtime Error
1150
54652
485
n = int(input()) edges = [[] for i in range(n)] distance = [-1 for i in range(n)] for i in range(n-1): f,t,c = map(int,raw_input().split()) f -= 1 t -= 1 edges[f].append([t,c]) edges[t].append([f,c]) q,k = map(int,raw_input().split()) k -= 1 def dfs(v,c): if distance[v] == -1: distance[v] = c for to,cos...
s584428553
p03634
u227020436
1534375589
Python
Python (3.4.3)
py
Runtime Error
1396
43700
615
#!/usr/bin/env python3 # -*- coding: utf-8 -*- N = int(input()) edge = [[] for i in range(N + 1)] for i in range(N - 1): a, b, c = [int(t) for t in input().split()] edge[a].append((b, c)) edge[b].append((a, c)) Q, K = [int(t) for t in input().split()] def dfs(s): '''深さ優先探索でKからの距離を計算''' global dis...
s448623096
p03634
u731427834
1530222520
Python
Python (3.4.3)
py
Runtime Error
1378
43624
539
N = int(input()) adj_list = [[] for _ in range(N)] depth = [float('inf')] * 100010 def dfs(v, p, d): depth[v] = d for adj in adj_list[v]: if adj[0] == p: continue dfs(adj[0], v, d + adj[1]) for _ in range(N - 1): a, b, c = map(int, input().split()) a -= 1 b -= 1 a...
s542754755
p03634
u281303342
1529800252
Python
Python (3.4.3)
py
Runtime Error
1356
44684
573
N = int(input()) X = [[] for _ in range(N)] for i in range(N-1): a,b,c = map(int,input().split()) X[a-1].append((b-1,c)) X[b-1].append((a-1,c)) cost = [-1]*(N+2) def calc(i,c): # 指定の頂点までのコストを代入 cost[i] = c # 頂点から移動できる頂点があれば for ni,nc in X[i]: # 初期状態のままなら計算 if cost[ni] == -1:...
s214526443
p03634
u467736898
1529297267
Python
Python (3.4.3)
py
Runtime Error
1638
151672
515
import sys sys.setrecursionlimit(100000) 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] ...
s729722790
p03634
u467736898
1529297039
Python
Python (3.4.3)
py
Runtime Error
1656
64204
473
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: ...
s175246736
p03634
u957084285
1527192415
Python
Python (3.4.3)
py
Runtime Error
1582
49932
529
n = int(input()) tree = [[] for _ in range(n+1)] for _ 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 d = [0] * (n+1) def dfs(x, c, p): global tree d[x] = c for leaf in tree[x]: ...
s156667603
p03634
u957084285
1527192206
Python
Python (3.4.3)
py
Runtime Error
1562
50056
479
n = int(input()) tree = [[] for _ in range(n+1)] for _ in range(n-1): a, b, c = map(int,input().split()) tree[a].append([b, c]) tree[b].append([a, c]) q, k = map(int, input().split()) d = [0] * (n+1) def dfs(x, c, p): global tree d[x] = c for leaf in tree[x]: if leaf[0] == p: ...
s313910247
p03634
u480847874
1526578170
Python
Python (3.4.3)
py
Runtime Error
1327
152068
593
import sys sys.setrecursionlimit(100000) def ans(): def dfs(v, p, d): depth[v] = d for e, cost in tree[v]: if e == p: continue dfs(e, v, d + cost) n = int(input()) tree = [[] for _ in range(n + 1)] depth = [0] * (n * 2) for _ in range(1, n)...
s708800794
p03634
u480847874
1526578086
Python
Python (3.4.3)
py
Runtime Error
1292
50240
587
import sys sys.setrecursionlimit(10000) def ans(): def dfs(v, p, d): depth[v] = d for e, cost in tree[v]: if e == p: continue dfs(e, v, d + cost) n = int(input()) tree = [[] for _ in range(n + 1)] depth = [0] * (n * 2) for _ in range(1, n): ...
s761359060
p03634
u480847874
1526572309
Python
Python (3.4.3)
py
Runtime Error
1322
46312
539
def ans(): def dfs(v, p, d): depth[v] = d for e, cost in tree[v]: if e == p: continue dfs(e, v, d + cost) n = int(input()) tree = [[] for _ in range(n+1)] depth = [0] * (n * 2) for _ in range(1,n): a, b, c = map(int, input().split()) ...
s729749608
p03634
u480847874
1526572136
Python
Python (3.4.3)
py
Runtime Error
1304
44008
538
def ans(): def dfs(v, p, d): depth[v] = d for e, cost in tree[v]: if e == p: continue dfs(e, v, d + cost) n = int(input()) tree = [[] for _ in range(n+1)] depth = [0] * 100001 for _ in range(1,n): a, b, c = map(int, input().split()) ...
s026148374
p03634
u562016607
1525381336
Python
PyPy3 (2.4.0)
py
Runtime Error
1304
113696
680
N=int(input()) a=[0 for i in range(N-1)] b=[0 for i in range(N-1)] c=[0 for i in range(N-1)] VL=[dict() for i in range(N)] for i in range(N-1): a[i],b[i],c[i]=map(int,input().split()) a[i]-=1 b[i]-=1 VL[a[i]][b[i]]=c[i] VL[b[i]][a[i]]=c[i] Q,K=map(int,input().split()) K-=1 x=[0 for i in range(Q)] y=...
s232997130
p03634
u562016607
1525381004
Python
Python (3.4.3)
py
Runtime Error
1035
62348
680
N=int(input()) a=[0 for i in range(N-1)] b=[0 for i in range(N-1)] c=[0 for i in range(N-1)] VL=[dict() for i in range(N)] for i in range(N-1): a[i],b[i],c[i]=map(int,input().split()) a[i]-=1 b[i]-=1 VL[a[i]][b[i]]=c[i] VL[b[i]][a[i]]=c[i] Q,K=map(int,input().split()) K-=1 x=[0 for i in range(Q)] y=...
s710137775
p03634
u682985065
1525376593
Python
Python (3.4.3)
py
Runtime Error
2127
357452
918
import heapq n = int(input()) cost = [[float('inf') for _ in range(n+1)] for _ in range(n+1)] for _ in range(n-1): From, To, d = map(int, input().split()) cost[From][To] = d cost[To][From] = d q, k = map(int, input().split()) dist = [[float('inf') for _ in range(n+1)] for _ in range(n+1)] used = [False]*(n...
s611877562
p03634
u682985065
1525376495
Python
Python (3.4.3)
py
Runtime Error
18
3188
933
import heapq n = int(f.readline()) cost = [[float('inf') for _ in range(n+1)] for _ in range(n+1)] for _ in range(n-1): From, To, d = map(int, f.readline().split()) cost[From][To] = d cost[To][From] = d q, k = map(int, f.readline().split()) dist = [[float('inf') for _ in range(n+1)] for _ in range(n+1)] us...
s450774085
p03634
u429843511
1522421700
Python
Python (3.4.3)
py
Runtime Error
1737
150640
614
import sys sys.setrecursionlimit(100000) N = int(input()) edges = [] connected = [[] for i in range(100010)] for i in range(N-1): x=list(map(int, input().split())) x[0] -= 1 x[1] -= 1 edges.append(x) connected[x[0]].append([x[1], x[2]]) connected[x[1]].append([x[0], x[2]]) Q,K = map(int, input...
s057503418
p03634
u429843511
1522420503
Python
Python (3.4.3)
py
Runtime Error
1765
63644
578
N = int(input()) edges = [] connected = [[] for i in range(100010)] for i in range(N-1): x=list(map(int, input().split())) x[0] -= 1 x[1] -= 1 edges.append(x) connected[x[0]].append([x[1], x[2]]) connected[x[1]].append([x[0], x[2]]) Q,K = map(int, input().split()) K -= 1 depth = [0]*100010 def ...
s540540350
p03634
u429843511
1522419625
Python
Python (3.4.3)
py
Runtime Error
1748
63668
570
N = int(input()) edges = [] connected = [[] for i in range(N+1)] for i in range(N-1): x=list(map(int, input().split())) x[0] -= 1 x[1] -= 1 edges.append(x) connected[x[0]].append([x[1], x[2]]) connected[x[1]].append([x[0], x[2]]) Q,K = map(int, input().split()) K -= 1 depth = [0]*N def DFS(v, p...
s382949222
p03634
u429843511
1522419542
Python
Python (3.4.3)
py
Runtime Error
1727
63656
563
N = int(input()) edges = [] connected = [[] for i in range(N+1)] for i in range(N-1): x=list(map(int, input().split())) x[0] -= 1 x[1] -= 1 edges.append(x) connected[x[0]].append([x[1], x[2]]) connected[x[1]].append([x[0], x[2]]) Q,K = map(int, input().split()) depth = [0]*N def DFS(v, p, d): ...
s965268311
p03634
u429843511
1522418576
Python
Python (3.4.3)
py
Runtime Error
1751
63632
535
N = int(input()) edges = [] connected = [[] for i in range(N+1)] for i in range(N-1): x=list(map(int, input().split())) edges.append(x) connected[x[0]].append([x[1], x[2]]) connected[x[1]].append([x[0], x[2]]) Q,K = map(int, input().split()) depth = [0]*(N+1) def DFS(v, p, d): depth[v] = d for ...
s853622696
p03634
u429843511
1522417823
Python
Python (3.4.3)
py
Runtime Error
1687
63620
859
N = int(input()) edges = [[] for i in range(N-1)] connected = [[] for i in range(N+1)] for i in range(N-1): edges[i]=list(map(int, input().split())) connected[edges[i][0]].append([edges[i][1], edges[i][2]]) connected[edges[i][1]].append([edges[i][0], edges[i][2]]) ##print('edges=',edges) '''def connected(v...
s981846262
p03634
u620868411
1515504881
Python
Python (3.4.3)
py
Runtime Error
1378
43792
603
# coding=utf-8 N = int(input()) tree = [[]for x in range(N)] depth = [0 for x in range(N)] for _ in range(N-1): line = input().split(" ") a = int(line[0])-1 b = int(line[1])-1 c = int(line[2]) tree[a].append((b, c)) tree[b].append((a, c)) line = input().split(" ") Q = int(line[0]) K = int(line...
s706487462
p03634
u367393577
1508013554
Python
Python (3.4.3)
py
Runtime Error
19
3448
5438
import networkx class Node: def __init__(self): pass class Edge: def __init__(self,edge,cost=1): self.node_from=edge[0] self.node_to=edge[1] self.cost=cost def add_node(self,node): self.nodes.append(node) class myGraph: def __init__(self): self.adj...
s545976702
p03634
u341855122
1506903048
Python
Python (2.7.6)
py
Runtime Error
949
149996
555
import sys sys.setrecursionlimit(100000) N = int(raw_input()) dict = {} for i in range(1,N+1): dict[i]={} for i in range(1,N): a = map(int,raw_input().split()) dict[a[0]].update({a[1]:a[2]}) dict[a[1]].update({a[0]:a[2]}) leng = {} q,K = map(int,raw_input().split()) def rec(bef,now): leng[now]=leng[...
s778822149
p03634
u341855122
1506902992
Python
Python (2.7.6)
py
Runtime Error
1052
66596
555
import sys sys.setrecursionlimit(10000) N = int(raw_input()) dict = {} for i in range(1,N+1): dict[i]={} for i in range(1,N): a = map(int,raw_input().split()) dict[a[0]].update({a[1]:a[2]}) dict[a[1]].update({a[0]:a[2]}) leng = {} q,K = map(int,raw_input().split()) def rec(bef,now): leng[now]=leng[b...
s677212485
p03634
u594377052
1504810171
Python
Python (2.7.6)
py
Runtime Error
1734
59848
1529
import sys import Queue graph = {} def get_all(K, N): answer = {} stack = [] stack.append((K, 0, [])) while len(answer) < N: start, start_dist, path = stack.pop() answer[start] = start_dist for target, target_dist in graph[start]: if target in path: ...
s740122099
p03634
u594377052
1504643344
Python
Python (3.4.3)
py
Runtime Error
17
3064
1554
import sys import Queue q = Queue.Queue() graph = {} def solve(x, y): q.put((x, 0, [])) while not q.empty(): start, dist, path = q.get() for neighbor, next_dist in graph[start]: if neighbor == y: return dist + next_dist if neighbor in path: ...
s476885866
p03634
u667084803
1504581453
Python
Python (3.4.3)
py
Runtime Error
917
82044
601
def BFS(K,edges,N): roots=[ [] for i in range(N)] for a,b,c in edges: roots[a-1]+=[(b-1,c)] roots[b-1]+=[(a-1,c)] dist=[-1]*N stack=[] stack.append(K) dist[K]=0 while stack: label=stack.pop(-1) for i,c in edges[label]: if dist[i]==-1: dist[i]=dist[label]+c stack+=[i] ...
s158397401
p03634
u297574184
1504147548
Python
Python (3.4.3)
py
Runtime Error
986
57292
526
N = int(input()) adj = [[] for i in range(N)] for i in range(N - 1): a, b, c = map(int, input().split()) adj[-a].append((b, c)) adj[-b].append((a, c)) Q, K = map(int, input().split()) query = [tuple(map(int, input().split())) for i in range(Q)] # dist[-i]:頂点Kから頂点iまでの距離 dist = [0 for i in range(N)] def d...
s040747947
p03634
u297574184
1504146542
Python
Python (3.4.3)
py
Runtime Error
1028
68404
523
N = int(input()) adj = [set() for i in range(N)] for i in range(N - 1): a, b, c = map(int, input().split()) adj[-a].add((b, c)) adj[-b].add((a, c)) Q, K = map(int, input().split()) query = [tuple(map(int, input().split())) for i in range(Q)] # dist[-i]:頂点Kから頂点iまでの距離 dist = [0 for i in range(N)] def dfs(...
s486643797
p03634
u075012704
1504016398
Python
Python (3.4.3)
py
Runtime Error
988
65208
536
N = int(input()) ABC = [tuple(map(int, input().split())) for i in range(N-1)] Q, K = map(int, input().split()) XY = [tuple(map(int, input().split())) for i in range(Q)] tree = [[] for i in range(N+1)] depth = [None] * (N+1) for abc in ABC: tree[abc[0]].append((abc[1],abc[2])) tree[abc[1]].append((abc[0],ab...
s853272962
p03634
u075012704
1504016292
Python
Python (3.4.3)
py
Runtime Error
989
65204
523
N = int(input()) ABC = [tuple(map(int, input().split())) for i in range(N-1)] Q, K = map(int, input().split()) XY = [tuple(map(int, input().split())) for i in range(Q)] tree = [[] for i in range(N+1)] depth = [None] * (N+1) for abc in ABC: tree[abc[0]].append((abc[1],abc[2])) tree[abc[1]].append((abc[0],ab...
s543789155
p03634
u075012704
1504016096
Python
Python (3.4.3)
py
Runtime Error
981
65172
525
N = int(input()) ABC = [tuple(map(int, input().split())) for i in range(N-1)] Q, K = map(int, input().split()) XY = [tuple(map(int, input().split())) for i in range(Q)] tree = [[] for i in range(N+1)] depth = [None] * (N+1) for abc in ABC: tree[abc[0]].append((abc[1],abc[2])) tree[abc[1]].append((abc[0],ab...
s161616000
p03634
u075012704
1504015759
Python
Python (3.4.3)
py
Runtime Error
968
65204
526
N = int(input()) ABC = [tuple(map(int, input().split())) for i in range(N-1)] Q, K = map(int, input().split()) XY = [tuple(map(int, input().split())) for i in range(Q)] tree = [[] for i in range(N+1)] depth = [None] * (N+1) for abc in ABC: tree[abc[0]].append((abc[1],abc[2])) tree[abc[1]].append((abc[0],ab...
s648974200
p03634
u425351967
1503959285
Python
Python (3.4.3)
py
Runtime Error
1402
43704
448
N = int(input()) adj = [[] for n in range(N+1)] costs = [-1] * (N+1) for i in range(N-1): a, b, c = [int(n) for n in input().split()] adj[a].append((b, c)) adj[b].append((a, c)) Q, K = [int (n) for n in input().split()] def DFS(now, cost): costs[now] = cost for nx, cs in adj[now]: if costs[nx] == -1: ...
s779530897
p03634
u124762318
1503895105
Python
Python (3.4.3)
py
Runtime Error
18
3064
955
N = int(input()) abc = [[int(n) for n in input().split()] for i in range(N-1)] a,b,c = list(zip(*abc)) Q,K = map(int,input().split()) xy = [[int(l) for l in input().split()] for m in range(Q)] x,y = list(zip(*xy)) l_rin = [[] for o in range(N)] for m in range(N-1): l_rin[a[m]-1].extend([b[m]]) l_rin[b[m]-1].extend(...
s640362586
p03634
u528825252
1503662203
Python
Python (3.4.3)
py
Runtime Error
1078
117136
556
import sys sys.setrecursionlimit(50000) N = int(input()) M = [[] for i in range(N+1)] for i in range(N-1): a, b, c = list(map(int, input().split(" "))) M[a].append((b,c)) M[b].append((a,c)) Qn, K = list(map(int, input().split(" "))) Q = [] for i in range(Qn): Q.append(list(map(int, input().split(" "...
s687620350
p03634
u528825252
1503661837
Python
Python (3.4.3)
py
Runtime Error
1065
71352
515
N = int(input()) M = [[] for i in range(N+1)] for i in range(N-1): a, b, c = list(map(int, input().split(" "))) M[a].append((b,c)) M[b].append((a,c)) Qn, K = list(map(int, input().split(" "))) Q = [] for i in range(Qn): Q.append(list(map(int, input().split(" ")))) distance = [0]*(N+1) def dfs(k, pa...
s497798017
p03634
u466826467
1503155627
Python
Python (3.4.3)
py
Runtime Error
1539
46872
654
def dfs(v, p, d): distance[v] = d for tmp in G[v]: if tmp[0] == p: continue dfs(tmp[0], v, d + tmp[1]) if __name__ == '__main__': N = int(input()) G = [[] for i in range(N)] for i in range(N - 1): # print(G) a, b, c = list(map(int, input().split())) ...
s383089078
p03634
u466826467
1503155347
Python
Python (3.4.3)
py
Runtime Error
1451
48384
591
def dfs(v, p, d): distance[v] = d for tmp in G[v]: if tmp[0] == p: continue dfs(tmp[0], v, d + tmp[1]) if __name__ == '__main__': N = int(input()) G = [[] for i in range(N + 1)] for i in range(N - 1): # print(G) a, b, c = list(map(int, input().split())) ...
s696140012
p03634
u076936237
1502997730
Python
Python (3.4.3)
py
Runtime Error
2105
86968
710
def search_dist(g, dist, e): for b, c in g.get(e): if dist[b] is not None: continue dist[b] = dist[e] + c search_dist(g, dist, b) def main(): g = {} N = int(input()) abc = [] for _ in range(N-1): abc.append(list(map(int, input().split(' ')))) for a, b...
s797185007
p03634
u076936237
1502997563
Python
Python (3.4.3)
py
Runtime Error
2104
72212
671
def search_dist(g, dist, e): for b, c in g.get(e): if dist[b] is not None: continue dist[b] = dist[e] + c search_dist(g, dist, b) def main(): g = {} N = int(input()) for _ in range(N-1): a, b, c = list(map(int, input().split(' '))) g[a] = g.get(a, [])...
s574746293
p03634
u076936237
1502997247
Python
Python (3.4.3)
py
Runtime Error
2104
72204
670
def search_dist(g, dist, e): for b, c in g.get(e): if dist[b] < 10**16: continue dist[b] = dist[e] + c search_dist(g, dist, b) def main(): g = {} N = int(input()) for _ in range(N-1): a, b, c = list(map(int, input().split(' '))) g[a] = g.get(a, []) + ...
s095019123
p03634
u076936237
1502996971
Python
Python (3.4.3)
py
Runtime Error
2104
48004
627
def search_dist(g, dist, e): for b, c in g.get(e): if dist[b] < 10**16: continue dist[b] = dist[e] + c search_dist(g, dist, b) def main(): g = {} N = int(input()) for _ in range(N-1): a, b, c = list(map(int, input().split(' '))) g[a] = g.get(a, []) + ...
s931671899
p03634
u076936237
1502996814
Python
Python (3.4.3)
py
Runtime Error
2104
48068
628
def search_dist(g, dist, e): for b, c in g.get(e): if dist[b] < 10**15: continue dist[b] = dist[e] + c search_dist(g, dist, b) def main(): g = {} N = int(input()) for _ in range(N-1): a, b, c = list(map(int, input().split(' '))) g[a] = g.get(a, []) +...
s633276901
p03634
u893209854
1502943724
Python
Python (3.4.3)
py
Runtime Error
18
3192
1011
import sys sys.setrecursionlimit(10000000000000000) tree = dict() cost = dict() N = int(input()) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) else: ...
s926471761
p03634
u893209854
1502943559
Python
Python (3.4.3)
py
Runtime Error
2143
596092
1001
#! -*- coding: utf-8 -*- import sys tree = dict() cost = dict() N = int(input()) sys.setrecursionlimit(N*10) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) ...
s864531444
p03634
u893209854
1502942818
Python
Python (3.4.3)
py
Runtime Error
1275
69972
958
tree = dict() cost = dict() N = int(input()) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) else: tree[b] = [] tree[b].append(a) cost[...
s018749553
p03634
u893209854
1502942719
Python
Python (3.4.3)
py
Runtime Error
1102
65188
934
tree = dict() cost = dict() N = int(input()) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) else: tree[b] = [] tree[b].append(a) cost[...
s304969428
p03634
u893209854
1502942514
Python
Python (3.4.3)
py
Runtime Error
1275
70500
954
tree = dict() cost = dict() N = int(input()) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) else: tree[b] = [] tree[b].append(a) cost[...
s846878703
p03634
u893209854
1502942350
Python
Python (3.4.3)
py
Runtime Error
1126
65804
962
#! -*- coding: utf-8 -*- tree = dict() cost = dict() N = int(input()) for i in range(N - 1): a, b, c = map(int, input().split()) if a in tree: tree[a].append(b) else: tree[a] = [] tree[a].append(b) if b in tree: tree[b].append(a) else: tree[b] = [] t...
s396561185
p03634
u247359764
1502871551
Python
Python (2.7.6)
py
Runtime Error
10
2568
1340
#include<bits/stdc++.h> using namespace std; #define lli long long int const lli mod=1e9+7; const lli pINF=LLONG_MAX; const lli nINF=-LLONG_MAX; void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);} lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;} lli invmod(lli a) {retu...
s339605407
p03634
u280667879
1502833656
Python
Python (2.7.6)
py
Runtime Error
412
40940
235
import sys from scipy.sparse import* f=lambda*z:map(int,sys.stdin.readline().split()) n,=f();a,b,c=zip(*map(f,range(n-1)));q,k=f() z=csgraph.bellman_ford(csr_matrix((c,(a,b)),[n+1]*2),0,k) for _ in range(q):x,y=f();print int(z[x]+z[y])
s019918021
p03634
u280667879
1502830233
Python
Python (2.7.6)
py
Runtime Error
413
40800
232
import sys from scipy.sparse import* f=lambda*z:map(int,sys.stdin.readline().split()) n,=f();a,b,c=zip(*map(f,[0]*~-n));q,k=f() z=csgraph.bellman_ford(csr_matrix((c,(a,b)),[n+1]*2),0,k) for _ in range(q):x,y=f();print int(z[x]+z[y])
s156061418
p03634
u280667879
1502829942
Python
Python (2.7.6)
py
Runtime Error
418
40924
277
import sys if sys.version_info[0]>=3: raw_input=input from scipy.sparse import* f=lambda*z:map(int,sys.stdin.readline().split()) n,=f();a,b,c=zip(*map(f,[0]*~-n));q,k=f() z=csgraph.shortest_path(csr_matrix((c,(a,b)),[n+1]*2),0,k) for _ in range(q):x,y=f();print int(z[x]+z[y])
s132329820
p03634
u280667879
1502829207
Python
Python (2.7.6)
py
Runtime Error
2110
50308
246
import sys from scipy.sparse import* f=lambda*z:map(int,sys.stdin.readline().split()) n,=f();a,b,c=zip(*map(f,[0]*~-n));q,k=f();x,y=zip(*map(f,[0]*q)) z=csgraph.dijkstra(csr_matrix((c,(a,b)),[n+1]*2),0,k) for _ in range(q):x,y=f();print z[x]+z[y]
s986441398
p03634
u280667879
1502810516
Python
PyPy2 (5.6.0)
py
Runtime Error
34
28012
208
from scipy.sparse import* f=lambda*z:map(int,raw_input().split()) n,=f();a,b,c=zip(*map(f,[0]*~-n));q,k=f() z=csgraph.dijkstra(csr_matrix((c,(a,b)),[n+1]*2),0,k) for _ in range(q):x,y=f();print int(z[x]+z[y])
s077096999
p03634
u978783125
1502772406
Python
Python (3.4.3)
py
Runtime Error
957
131004
503
import sys sys.setrecursionlimit(100000) n = int(input()) tree = [[] for i in range(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)) depth = [0] * (n + 1) def dfs(v, p, d): depth[v] = d for to, cost in tree[v]: if to != p: ...
s551242395
p03634
u978783125
1502772165
Python
Python (3.4.3)
py
Runtime Error
953
57152
461
n = int(input()) tree = [[] for i in range(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)) depth = [0] * (n + 1) def dfs(v, p, d): depth[v] = d for to, cost in tree[v]: if to != p: dfs(to, v, d + cost) q, k = map(...
s965520607
p03634
u978783125
1502771820
Python
Python (3.4.3)
py
Runtime Error
1371
43640
442
n = int(input()) tree = [[] for i in range(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)) depth = [0] * (n + 1) def dfs(v, p, d): depth[v] = d for to, cost in tree[v]: if to != p: dfs(to, v, d + cost) q, k = map(...
s055558334
p03634
u978783125
1502771633
Python
Python (3.4.3)
py
Runtime Error
1377
43640
443
n = int(input()) tree = [[] for i in range(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)) depth = [0] * (n + 1) def dfs(v, p, d): depth[v] = d for to, cost in tree[v]: if to != p: dfs(to, v, d + cost) q, k = map(...
s775357121
p03634
u978783125
1502771086
Python
Python (3.4.3)
py
Runtime Error
1365
43716
461
tree = [[] for i in range(100001)] depth = [0] * 100001 def dfs(v, p, d): depth[v] = d for to, cost in tree[v]: if to == p: continue dfs(to, v, d + cost) n = int(input()) for i in range(n - 1): a, b, c = map(int, input().split()) tree[a].append((b, c)) tree[b].append((a...
s421409421
p03634
u160414758
1502683436
Python
Python (3.4.3)
py
Runtime Error
1771
64188
657
#import sys;sys.setrecursionlimit(int(1e7)) class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = [[] for i in range(N+1)] for i in range(N-1): a,b,c = map(int,input().split()) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b...
s768414452
p03634
u712187387
1502678322
Python
Python (3.4.3)
py
Runtime Error
1390
46508
433
N = int(input()) A = [[ ] for _ in range(N)] for n 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().split()) dist = [-1 for _ in range(len(A))] q = list(range(len(A))) def DFS(v,d): dist[v] = d; for i,c in A[v]: if dist[i]==-1: DF...
s699133124
p03634
u712187387
1502674686
Python
Python (3.4.3)
py
Runtime Error
1423
46896
459
import heapq import copy N = int(input()) A = [[ ] for _ in range(N)] for n 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().split()) dist = [-1 for _ in range(len(A))] q = list(range(len(A))) def DFS(v,d): dist[v] = d; for i,c in A[v]: ...
s975868851
p03634
u160414758
1502662955
Python
Python (3.4.3)
py
Runtime Error
1903
75296
632
class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = {i:[] for i in range(N+1)} for i in range(N-1): a,b,c = list(map(int,input().split())) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b].append(edge(a,c)) Q,K = list(map(i...
s868907409
p03634
u160414758
1502662728
Python
Python (3.4.3)
py
Runtime Error
1905
65776
630
class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = [[] for i in range(N+1)] for i in range(N-1): a,b,c = list(map(int,input().split())) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b].append(edge(a,c)) Q,K = list(map(int,...
s704251538
p03634
u160414758
1502662380
Python
Python (3.4.3)
py
Runtime Error
1809
66684
666
class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = [[] for i in range(N+1)] for i in range(N-1): a,b,c = list(map(int,input().split())) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b].append(edge(a,c)) Q,K = list(map(int...
s286165468
p03634
u160414758
1502662299
Python
Python (3.4.3)
py
Runtime Error
1882
65852
665
class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = [[] for i in range(N+1)] for i in range(N-1): a,b,c = list(map(int,input().split())) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b].append(edge(a,c)) Q,K = list(map(int...
s896146924
p03634
u160414758
1502662177
Python
Python (3.4.3)
py
Runtime Error
1808
65804
675
class edge(): def __init__(self,_to,_cost): self.to = _to; self.cost = _cost; N = int(input()) tree = [[] for i in range(N)] for i in range(N-1): a,b,c = list(map(int,input().split())) a = a - 1 b = b - 1 tree[a].append(edge(b,c)) tree[b].append(edge(a,c)) Q,K = list(map(int,in...