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
s265401107
p03633
u346308892
1502588230
Python
Python (3.4.3)
py
Runtime Error
17
3064
423
def spaceinput(): return list(map(int,input().split(" "))) def gcd(m,n): if m<n: return gcd(n, m) r=m%n if r == 0: return n return gcd(n,r) def glm(m,n): return m*n/gcd(m,n) N=int(input()) for i in range(N): try: x.append(int(input())) except: pass l...
s047112440
p03633
u106342872
1502588205
Python
Python (3.4.3)
py
Runtime Error
74
3952
303
#! -*- coding:utf-8 -*- def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): return a * b / gcd(a, b) n = int(input()) arr = [] for i in range(n): arr.append(int(input())) x = [0]*n x[0] = arr[0] for i in range(n-1): x[i+1] = lcm(x[i],arr[i+1]) print(int(x[-1]))
s369561838
p03633
u346308892
1502588183
Python
Python (3.4.3)
py
Runtime Error
17
3064
387
def spaceinput(): return list(map(int,input().split(" "))) def gcd(m,n): if m<n: return gcd(n, m) r=m%n if r == 0: return n return gcd(n,r) def glm(m,n): return m*n/gcd(m,n) N=int(input()) for i in range(N): x.append(int(input())) l=x[0] for k in range(1,len(x)): t...
s547536198
p03633
u562446079
1502588170
Python
Python (3.4.3)
py
Runtime Error
17
3064
263
from math import gcd def lcm(a, b): """Return lowest common multiple.""" return a * b // gcd(a, b) n = int(input()) arr = [] for _ in range(n): x = int(input()) arr.append(x) gc = arr[0] for i in range(1, len(arr)): gc = lcm(arr[i], gc) print(gc)
s367760341
p03633
u582243208
1502588138
Python
Python (3.4.3)
py
Runtime Error
18
3060
152
import math def lcm(a, b): return a * b / math.gcd(a, b) n = int(input()) ans = 1 for i in range(n): ans = lcm(ans, int(input())) print(ans)
s943793444
p03633
u792547805
1502588111
Python
Python (3.4.3)
py
Runtime Error
18
3064
236
def gcd(a, b): while b > 0: a, b = b, a%b return a def lcm(a, b): return a*b/gcd(a, b) n = int(input()) T = [] for i in range(n): T.append(int(input())) temp = 1 for num in T: temp = int(lcm(num, temp)) print(temp)
s588179628
p03633
u346308892
1502588065
Python
Python (3.4.3)
py
Runtime Error
19
3188
348
def spaceinput(): return list(map(int,input().split(" "))) def gcd(m,n): if m<n: return gcd(n, m) r=m%n if r == 0: return n return gcd(n,r) def glm(m,n): return m*n/gcd(m,n) N=int(input()) for i in range(N): x.append(int(input())) l=x[0] for k in range(1,len(x)): l=...
s338351496
p03633
u630452895
1502588040
Python
Python (3.4.3)
py
Runtime Error
17
3060
214
import math n = int(input()) t = [ int(input()) for i in range(n)] def lc(a,b): return a // math.gcd(a,b) * b def lcm(b): ans = b[0] for i in b: ans = lc(ans,i) return ans print(lcm(t))
s047652495
p03633
u402032430
1502588007
Python
Python (3.4.3)
py
Runtime Error
17
2940
168
from math import gcd def lcm(m, n): return m * n // gcd(m, n) N = int(input()) answer = 1 for i in range(N): answer = lcm(answer, int(input())) print(answer)
s078240139
p03633
u473999868
1502587982
Python
Python (3.4.3)
py
Runtime Error
23
3572
265
import math as m from functools import reduce n=int(input()) l=set([]) def gcd(a,b): while a != 0: c = a a = b % a b = c return b def f(a,b): return int(a*b/gcd(a,b)) for i in range(n): l.add(int(input())) print(reduce(f,l))
s652154491
p03633
u346308892
1502587964
Python
Python (3.4.3)
py
Runtime Error
17
3064
349
def spaceinput(): return list(map(int,input().split(" "))) def gcd(m,n): if m<n: return gcd(n, m) r=m%n if r == 0: return n return gcd(n,r) def glm(m,n): return m*n/gcd(m,n) N=int(input()) for i in range(N): x.append(int(input())) l=x[0] for k in range(1,len(x)): l...
s019538600
p03633
u914739916
1502587896
Python
Python (3.4.3)
py
Runtime Error
18
3060
261
import math def lcm(a, b): return a * b / math.gcd(a, b) n = int(input()) if n == 1: print(input()) else: v = [int(input()) for i in range(n)] ans = lcm(v[0], v[1]) for i in range(1, n): ans = lcm(ans, v[i]) print(ans)
s781827077
p03633
u233780116
1502587873
Python
Python (3.4.3)
py
Runtime Error
17
2940
213
import math GCD = 1 ###最大公約数 LCM = 1 ###最小公倍数 N = int(input()) for i in range(N): a = int(input()) if a / GCD == 0: continue GCD = math.gcd(GCD, a) LCM = LCM * a / GCD print(int(LCM))
s173444505
p03633
u346308892
1502587864
Python
Python (3.4.3)
py
Runtime Error
17
3064
348
def spaceinput(): return list(map(int,input().split(" "))) def gcd(m,n): if m<n: return gcd(n, m) r=m%n if r == 0: return n return gcd(n,r) def glm(m,n): return m*n/gcd(m,n) N=int(input()) for i in range(N): x.append(int(input())) l=x[0] for k in range(1,len(x)): l=...
s102743767
p03633
u792547805
1502587824
Python
Python (3.4.3)
py
Runtime Error
19
3060
253
def gcd(a, b): while b > 0: a, b = b, a%b return a def lcm(a, b): return a*b/gcd(a, b) n = int(input()) T = [0 for i in range(n)] for i in range(n): T[i] = int(input()) temp = 1 for num in T: temp = int(lcm(num, temp)) print(temp)
s975656850
p03633
u582243208
1502587774
Python
Python (3.4.3)
py
Runtime Error
17
3060
153
import math def lcm(a, b): return a * b // math.gcd(a, b) n = int(input()) ans = 1 for i in range(n): ans = lcm(ans, int(input())) print(ans)
s553530705
p03633
u233780116
1502587748
Python
Python (3.4.3)
py
Runtime Error
17
3060
184
import math GCD = 1 ###最大公約数 LCM = 1 ###最小公倍数 N = int(input()) for i in range(N): a = int(input()) GCD = math.gcd(GCD, a) LCM = LCM * a / GCD print(int(LCM))
s482633546
p03633
u335295553
1502587743
Python
Python (3.4.3)
py
Runtime Error
17
3060
201
import math def lcm(a, b): return a*b // math.gcd(a, b) n = int(input()) ls = [] for i in range(n): ls.append(int(input())) result = ls[0] for i in ls[1:]: result = lcm(i,result) print(result)
s559817389
p03633
u202619899
1502587630
Python
Python (3.4.3)
py
Runtime Error
24
3572
195
import math import functools def lcm(a, b): return a * b // math.gcd(a, b) N = int(input()) T = [] for i in range(N): T.append(int(input())) res = functools.reduce(lcm, T) print(res)
s152455701
p03633
u104282757
1502587319
Python
Python (3.4.3)
py
Runtime Error
17
2940
312
N = int(input()) a_list = [] for _ in range(N): a_list.append(int(input()) def gcd(a, b): if a < b: a, b = b, a if b == 0: return a c = a % b return gcd(b, c) res = 1 for i in range(N): d = gcd(res, a_list[i]) res = res // d res = res * a_list[i] print(res)
s380025805
p03633
u473999868
1502587057
Python
Python (3.4.3)
py
Runtime Error
35
3828
185
import math as m from functools import reduce n=int(input()) l=set([]) def f(a,b): return int(a*b/m.gcd(a,b)) for i in range(n): l.add(int(input())) print(reduce(f,l))
s001829004
p03633
u635974378
1502587029
Python
Python (3.4.3)
py
Runtime Error
17
3064
267
def gcd(a, b): if min(a,b) == 0: return max(a,b) if a==b: return a if b>a: a,b = b,a return gcd(b, a%b) N = int(input()) ret = 1 for i in range(N): hoge = int(input()) ret = int((ret * hoge)/gcd(ret, hoge)) print(ret)
s580845280
p03633
u294283114
1502587009
Python
Python (3.4.3)
py
Runtime Error
17
3064
234
import math def lcm(x, y): return int(int(x * y) / math.gcd(x, y)) n = int(input()) t = [i for i in range(n)] for i in range(n): t[i] = int(input()) ans = t[0] for i in range(1, n): ans = lcm(ans, t[i]) print(int(ans))
s297279872
p03633
u837390123
1502586865
Python
Python (2.7.6)
py
Runtime Error
32
4392
203
from fractions import gcd n = int(raw_input()) a = [] for i in range(n): a.append(int(raw_input())) result = a[0] for i in range(1, n): result = result * a[i] / gcd(result, a[i]) print result / g
s127865877
p03633
u635974378
1502586686
Python
Python (3.4.3)
py
Runtime Error
17
2940
144
from math import gcd N = int(input()) ret = 1 for i in range(N): hoge = int(input()) ret = int((ret * hoge)/gcd(ret, hoge)) print(ret)
s470791028
p03633
u045939752
1502586680
Python
Python (3.4.3)
py
Runtime Error
17
3060
140
import math N=int(input()) A = [ int(input()) for _ in range(N) ] ans = A[0] for x in A[1:]: ans = ans * x // math.gcd(ans, x) print(ans)
s119565551
p03633
u889725830
1502586573
Python
Python (3.4.3)
py
Runtime Error
17
2940
136
import math n = int(input()) a = [int(input()) for i in range(n)] x = a[0] for i in a[1:]: x = (x * i) // math.gcd(x,i) print(x)
s806873421
p03633
u156163787
1502586437
Python
PyPy3 (2.4.0)
py
Runtime Error
170
38640
115
import math n=int(input()) res=1 for _ in range(n): x=int(input()) res=res//math.gcd(res,x)*x print(res)
s648656146
p03634
u174523836
1601350244
Python
Python (3.8.2)
py
Runtime Error
1001
67388
541
N = int(input()) tree = {} for _ in range(N-1): A, B, C = [int(i) for i in input().split()] if A not in tree: tree[A] = [] if B not in tree: tree[B] = [] tree[A].append((B, C)) tree[B].append((A, C)) c = {} q = [] visited = set() def dfs(a, acc): c[a] = acc for n, cost in tree[a]: if n no...
s283923556
p03634
u759109971
1601130484
Python
Python (3.8.2)
py
Runtime Error
986
65744
564
N = int(input()) a = [[] for _ in range(N + 1)]; b = [[] for _ in range(N + 1)] for i in range(N - 1): p, q, r = list(map(int, input().split())) a[p].append([q, r]); a[q].append([p, r]) Q, K = map(int, input().split()) x = []; y = [] for i in range(Q): p, q = map(int, input().split()) x.append(p); y.app...
s551386883
p03634
u630211216
1600310988
Python
Python (3.8.2)
py
Runtime Error
1022
50668
473
N=int(input()) G=[[] for _ in range(N)] for _ 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=map(int,input().split()) K-=1 dist=[-1 for _ in range(N)] dist[K]=0 def dfs(G,x,dist): for p in G[x]: if dist[p[0]]!=-1: continue ...
s090087476
p03634
u995062424
1600008036
Python
Python (3.8.2)
py
Runtime Error
867
47676
488
N = int(input()) graph = [[] 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()) visited = [0 for _ in range(N)] def DFS(a, b, c): for i, j in graph[b]: if(i != a): ...
s357223171
p03634
u995062424
1599950724
Python
Python (3.8.2)
py
Runtime Error
869
55000
479
N= int(input()) graph = {i+1:[] for i in range(N)} for i in range(N-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) Q, K = map(int, input().split()) visited = [0 for _ in range(N+1)] def DFS(a, b, c): for i, j in graph[b]: if(i != a): v...
s452713420
p03634
u995062424
1599950585
Python
Python (3.8.2)
py
Runtime Error
885
54912
483
N= int(input()) graph = {i+1:[] for i in range(N)} for i in range(N-1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) Q, K = map(int, input().split()) visited = [0 for _ in range(N+1)] def DFS(a, b, c): for i, j in graph[b]: if(i != a): v...
s495861612
p03634
u425184437
1599720878
Python
PyPy3 (7.3.0)
py
Runtime Error
739
106376
405
N=int(input()) tree=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) tree[a-1].append((b-1,c)) tree[b-1].append((a-1,c)) depth=[0 for i in range(N)] def dfs(v,p,d): depth[v]=d for vv,dd in tree[v]: if vv==p: continue dfs(vv,v,d+dd) Q,K=map(int,input().split()) dfs(K-1,-...
s541134199
p03634
u926412290
1599528448
Python
PyPy3 (7.3.0)
py
Runtime Error
554
126736
579
N = int(input()) to = [[] for _ in range(N)] for _ in range(N - 1): a, b, c = map(int, input().split()) a, b, = a - 1, b - 1 to[a].append((c, b)) to[b].append((c, a)) Q, K = map(int, input().split()) K -= 1 query = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(Q)] depth = [0] * N d...
s232722949
p03634
u857759499
1598927811
Python
Python (3.8.2)
py
Runtime Error
875
47492
380
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()) k -= 1 l = [0]*n def dfs(a,b,c): for i,j in t[b]: if i != a: l[i] = c+j dfs(b,i,c+j) dfs(-1,k,0) for _ in range(q): x,y...
s775991417
p03634
u886459614
1598401335
Python
Python (3.8.2)
py
Runtime Error
1048
50448
396
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].append([b,c]) G[b].append([a,c]) q,k=map(int,input().split()) D=[None]*(n+1) def dfs(x,d): D[x]=d for yy,dd in G[x] : if D[yy] is not None: continue dfs(yy,dd+d) dfs(k,0) fo...
s294349463
p03634
u189806337
1598400924
Python
PyPy3 (7.3.0)
py
Runtime Error
366
100700
610
n = int(input()) def bellman_ford(s): d = [float('inf')]*10 # 各頂点への最小コスト d[s] = 0 # 自身への距離は0 for i in range(10): update = False # 更新が行われたか for x, y, z in g: if d[y] > d[x] + z: d[y] = d[x] + z update = True if not update: break # 負閉路が存在 if i == 9: return -1 return d g = [] for _ in ra...
s619298393
p03634
u189806337
1598400766
Python
Python (3.8.2)
py
Runtime Error
520
45396
610
n = int(input()) def bellman_ford(s): d = [float('inf')]*10 # 各頂点への最小コスト d[s] = 0 # 自身への距離は0 for i in range(10): update = False # 更新が行われたか for x, y, z in g: if d[y] > d[x] + z: d[y] = d[x] + z update = True if not update: break # 負閉路が存在 if i == 9: return -1 return d g = [] for _ in ra...
s988634486
p03634
u074220993
1598236031
Python
Python (3.8.2)
py
Runtime Error
2207
56756
706
N =int(input()) #graph作成 graph = [[] 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()) K -= 1 query = [tuple(int(x) for x in input().split()) for _ in range(Q)] def dfs(v, graph, seen, dist, di...
s226008868
p03634
u334792253
1597802413
Python
PyPy3 (7.3.0)
py
Runtime Error
88
74812
846
import sys from collections import deque input = sys.stdin.readline N = int(input()) points = [list(map(int,input().split())) for _ in xrange(N-1)] Q, K = map(int,input().split()) Query = [list(map(int,input().split())) for _ in xrange(Q)] tree = [[0]*N for _ in xrange(N)] for i in range(N-1): a = points[i][0] - 1...
s347093226
p03634
u970109776
1597588342
Python
Python (3.8.2)
py
Runtime Error
1427
56504
748
#coding: utf-8 from collections import defaultdict import sys N = int(input()) G = {} for i in range(N-1): a, b, c = (int(x) for x in input().split()) if a not in G: G[a] = defaultdict(int) if b not in G: G[b] = defaultdict(int) G[a][b] = c G[b][a] = c Q, K = (int(x) for x in inpu...
s890412241
p03634
u288430479
1597082329
Python
PyPy3 (7.3.0)
py
Runtime Error
790
143976
538
n = int(input()) l = [list(map(int,input().split())) for _ in range(n-1)] q,k = map(int,input().split()) k -= 1 #kからの距離 tree = [[] for _ in range(n)] for a,b,c in l: a -= 1 b -= 1 tree[a].append([b,c]) tree[b].append([a,c]) bit = [0 for _ in range(n)] depth = [0 for _ in range(n)] def dfs(v,d=0): b...
s485384351
p03634
u107639613
1596511774
Python
PyPy3 (7.3.0)
py
Runtime Error
832
128776
2183
import sys from math import log2 def input(): return sys.stdin.readline().strip() def main(): """ Kの指定があるのに気づかずダブリングでLCA求めちゃった・・・! https://algo-logic.info/lca/ 勉強になったから良しとする。ポイントとして 1. parents[k][u]の求め方がまず再帰 2. LCAでまず深さを揃えるとこも2べき(必ずfor文はint(log2(N))まで回すこと!) 3. ダブリングは祖先が一致しない時だけ更新 を押さえと...
s941170942
p03634
u107639613
1596511441
Python
PyPy3 (7.3.0)
py
Runtime Error
807
129340
2171
import sys from math import log2 def input(): return sys.stdin.readline().strip() def main(): """ Kの指定があるのに気づかずダブリングでLCA求めちゃった・・・! https://algo-logic.info/lca/ 勉強になったから良しとする。ポイントとして 1. parents[k][u]の求め方がまず再帰 2. LCAでまず深さを揃えるとこも2べき(必ずfor文はint(log2(N))まで回すこと!) 3. ダブリングは祖先が一致しない時だけ更新 を押さえと...
s486576583
p03634
u107639613
1596511399
Python
PyPy3 (7.3.0)
py
Runtime Error
1004
130936
2197
import sys from math import log2 def input(): return sys.stdin.readline().strip() def main(): """ Kの指定があるのに気づかずダブリングでLCA求めちゃった・・・! https://algo-logic.info/lca/ 勉強になったから良しとする。ポイントとして 1. parents[k][u]の求め方がまず再帰 2. LCAでまず深さを揃えるとこも2べき(必ずfor文はint(log2(N))まで回すこと!) 3. ダブリングは祖先が一致しない時だけ更新 を押さえと...
s215036782
p03634
u815878613
1596330629
Python
PyPy3 (7.3.0)
py
Runtime Error
91
68752
384
import networkx as nx N = int(input()) ABC = [list(map(int, input().split())) for _ in range(N - 1)] Q, K = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(Q)] G = nx.Graph() for a, b, c in ABC: G.add_edge(a - 1, b - 1, weight=c) pred, dist = nx.dijkstra_predecessor_and_distance(G...
s098642942
p03634
u904406968
1596290514
Python
PyPy3 (7.3.0)
py
Runtime Error
805
210656
517
from collections import defaultdict adj = defaultdict(list) vis =[0 for i in range(1000000)] dis =[0 for i in range(1000000)] def dfs(u, p): for v, w in adj[u]: if v==p: continue dis[v]=dis[u]+w dfs(v, u) def main(): n = int(input()) for i in range(n-1): a, b, w = map(int , input().split()) adj[a].appe...
s785215523
p03634
u572193732
1595757478
Python
Python (3.8.2)
py
Runtime Error
988
50688
617
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append([b-1, c]) tree[b-1].append([a-1, c]) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_next...
s605685069
p03634
u572193732
1595756580
Python
Python (3.8.2)
py
Runtime Error
861
47908
620
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append((b-1, c)) tree[b-1].append((a-1, c)) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost=0): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_ne...
s300549948
p03634
u572193732
1595756489
Python
Python (3.8.2)
py
Runtime Error
843
47480
618
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append((b-1, c)) tree[b-1].append((a-1, c)) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_next...
s296421410
p03634
u572193732
1595756336
Python
Python (3.8.2)
py
Runtime Error
970
50580
618
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append([b-1, c]) tree[b-1].append([a-1, c]) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_next...
s675470440
p03634
u572193732
1595756295
Python
PyPy3 (7.3.0)
py
Runtime Error
725
126156
617
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append([b-1, c]) tree[b-1].append([a-1, c]) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_next...
s027546270
p03634
u572193732
1595755710
Python
PyPy3 (7.3.0)
py
Runtime Error
732
126428
618
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a, b, c = map(int, input().split()) tree[a-1].append([b-1, c]) tree[b-1].append([a-1, c]) Q, K = map(int, input().split()) dist = [-1] * N def dfs(v, total_cost): # v:頂点, total_cost:今までかかったコストの合計 dist[v] = total_cost for v_next...
s672282600
p03634
u475675023
1595740512
Python
Python (3.8.2)
py
Runtime Error
827
47556
465
def dfs(now_node,parent_node,dist): depth[now_node]=dist for next_node,w in graph[now_node]: if next_node==parent_node: continue dfs(next_node,now_node,dist+w) n=int(input()) graph=[[] for _ in range(n+1)] for _ in range(n-1): a,b,c=map(int,input().split()) graph[a].append((b,c)) graph[b].appen...
s412415748
p03634
u426764965
1595704624
Python
Python (3.8.2)
py
Runtime Error
628
104020
743
def abc070_d(): import sys read = sys.stdin.buffer.read inp = iter(map(int, read().split())) import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra n = next(inp) adjmtx = np.zeros((n, n), dtype=np.int32) for _ in range(n-1): a = nex...
s561546167
p03634
u426764965
1595703974
Python
Python (3.8.2)
py
Runtime Error
688
108624
743
def abc070_d(): import sys read = sys.stdin.buffer.read inp = iter(map(int, read().split())) import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra n = next(inp) adjmtx = np.zeros((n, n), dtype=np.int64) for _ in range(n-1): a = nex...
s094665955
p03634
u426764965
1595703332
Python
Python (3.8.2)
py
Runtime Error
691
108336
722
def abc070_d(): import sys read = sys.stdin.buffer.read inp = iter(map(int, read().split())) import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra n = next(inp) adjmtx = np.zeros((n, n), dtype=np.int64) for _ in range(n-1): a = nex...
s148245795
p03634
u747703115
1595689798
Python
PyPy3 (7.3.0)
py
Runtime Error
2208
3519028
683
import sys from collections import deque readline = sys.stdin.readline n = int(readline()) D = [[-1]*n for _ in range(n)] for i in range(n): D[i][i]=0 G = [[] for _ in range(n)] for i in range(n-1): a,b,c = map(lambda x:int(x)-1, map(int, readline().split())) G[a].append(b) G[b].append(a) D[a][b] = c+1...
s595301168
p03634
u653837719
1595539916
Python
PyPy3 (7.3.0)
py
Runtime Error
591
128436
502
def dfs(v, p, d): dist[v] = d for c, cost in edge[v]: if c == p: continue dfs(c, v, d + cost) n = int(input()) edge = [[] for _ in range(n)] for _ in range(n-1): a, b, c = map(int, input().split()) edge[a-1].append([b-1, c]) edge[b-1].append([a-1, c]) q, k = map(int, ...
s924424553
p03634
u830054172
1595084582
Python
Python (3.8.2)
py
Runtime Error
876
47852
485
def dfs(st, depth=0): dist[st] = depth for to, c in tree[st]: if dist[to]>=0: continue dfs(to, depth+c) N = int(input()) tree = [[] for _ in range(N)] dist = [-1]*N for _ in range(N-1): a,b,c = map(int, input().split()) tree[a-1].append((b-1, c)) tree[b-1].append((a-1,...
s357324280
p03634
u923270446
1594586848
Python
Python (3.8.2)
py
Runtime Error
977
50712
509
n = int(input()) d = [-1 for i in range(n)] e = [[] for i in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) e[a - 1].append([b - 1, c]) e[b - 1].append([a - 1, c]) q, k = map(int, input().split()) def dfs(cur, par, di): d[cur] = di for i in e[cur]: if d[i[0]] == -1: ...
s113366412
p03634
u788068140
1594490670
Python
Python (3.8.2)
py
Runtime Error
802
84380
1125
# N = 5 # ARR = [ # [1, 2, 1], # [1, 3, 1], # [2, 4, 1], # [3, 5, 1] # ] # # Q, K = 3, 1 # # BRR = [ # [2, 4], # [2, 3], # [4, 5], # ] # # N = int(input()) ARR = [list(map(int,input().split())) for i in range(N-1)] Q, K = map(int,input().split()) BRR = [list(map(int,input().split())) for...
s994564218
p03634
u595952233
1594488376
Python
Python (3.8.2)
py
Runtime Error
873
48152
501
from collections import deque n = int(input()) g = [[] for i in range(n)] for i in range(n-1): a, b, c = map(int, input().split()) a-=1; b-=1 g[a].append((b, c)) g[b].append((a, c)) q, k = map(int, input().split()) # 前処理 dist = [-1] * n def dfs(st, depth=0): dist[st] = depth for to, c in g[st]...
s040745152
p03634
u919730120
1594437238
Python
PyPy3 (7.3.0)
py
Runtime Error
2286
3528488
567
from collections import deque n=int(input()) e=[[] for _ in range(n+1)] l=[[0]*(n+1) for _ in range(n+1)] dist=[-1]*(n+1) for i in range(n-1): a,b,c=map(int,input().split()) e[a].append(b) e[b].append(a) l[a][b]=c l[b][a]=c q,k=map(int,input().split()) a=deque() a.append((k,0)) while a: x,d=a.po...
s474754787
p03634
u035907840
1594417033
Python
PyPy3 (7.3.0)
py
Runtime Error
1042
188484
1803
N = int(input()) G = [[] for _ in range(N)] length = {} for _ in range(N-1): a, b, c = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) length[(a-1, b-1)] = c length[(b-1, a-1)] = c r = 0 dist = [0]*N prv = [None]*N depth = [0]*N def dfs(v): for u in G[v]: if dist[u] > ...
s064998162
p03634
u711539583
1594266611
Python
PyPy3 (7.3.0)
py
Runtime Error
88
74708
1295
from scipy.sparse.csgraph import dijkstra from scipy.sparse import csr_matrix import sys input = sys.stdin.readline import heapq INF = 10 ** 18 class Edge(): def __init__(self, start, end, cost): self.start = start self.end = end self.cost = cost def __str__(self): return 'Edg...
s011902114
p03634
u374802266
1594265423
Python
Python (3.8.2)
py
Runtime Error
1062
50552
408
n=int(input()) edge=[[] for i in range(n)] for i in range(n-1): x,y,z=map(int,input().split()) edge[x-1].append([y-1,z]) edge[y-1].append([x-1,z]) q,k=map(int,input().split()) dist=[-1]*n def dfs(node,d): dist[node]=d for i in edge[node]: if dist[i[0]]==-1: dfs(i[0],d+i[1]) dfs(k...
s417172249
p03634
u948524308
1594074027
Python
Python (3.8.2)
py
Runtime Error
957
50508
406
N=int(input()) G=[[] for _ 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()) SD=[0]*N def DFS(v,p,d): SD[v]=d for i,co in G[v]: if i==p:continue DFS(i,v,d+co) return DFS(K-1,-1,0) for i ...
s790147264
p03634
u093041722
1593781049
Python
Python (3.8.2)
py
Runtime Error
2225
645588
432
import sys input = sys.stdin.readline import scipy.sparse N = int(input()) lil = scipy.sparse.lil_matrix((N, N), dtype = int) for i in range(N-1): a, b, c = (int(x) for x in input().split()) lil[a-1, b-1] = c lil2 = scipy.sparse.csgraph.dijkstra(lil,directed=False).astype(int) Q, K = (int(x) for x in input().s...
s848619947
p03634
u093041722
1593780627
Python
Python (3.8.2)
py
Runtime Error
2228
645640
396
import scipy.sparse N = int(input()) lil = scipy.sparse.lil_matrix((N, N), dtype = int) for i in range(N-1): a, b, c = (int(x) for x in input().split()) lil[a-1, b-1] = c lil2 = scipy.sparse.csgraph.dijkstra(lil, directed = False).astype(int) Q, K = (int(x) for x in input().split()) for i in range(Q): x, y ...
s106062450
p03634
u665038048
1593091513
Python
Python (3.8.2)
py
Runtime Error
2221
1163224
519
import numpy as np from scipy.sparse.csgraph import floyd_warshall, dijkstra n = int(input()) matrix = np.zeros((n, n),dtype=np.int64) for i in range(n-1): a, b, c = map(int, input().split()) matrix[a-1][b-1] = c matrix[b-1][a-1] = c min_span_matrix = dijkstra(matrix, directed=False, ...
s779496997
p03634
u665038048
1593091424
Python
Python (3.8.2)
py
Runtime Error
2221
1390036
515
import numpy as np from scipy.sparse.csgraph import floyd_warshall n = int(input()) matrix = np.zeros((n, n),dtype=np.int64) for i in range(n-1): a, b, c = map(int, input().split()) matrix[a-1][b-1] = c matrix[b-1][a-1] = c min_span_matrix = floyd_warshall(matrix, directed=False, ...
s396572704
p03634
u665038048
1593091244
Python
Python (3.8.2)
py
Runtime Error
2212
1466888
495
import numpy as np from scipy.sparse.csgraph import floyd_warshall n = int(input()) matrix = np.zeros((n, n)) for i in range(n-1): a, b, c = map(int, input().split()) matrix[a-1][b-1] = c matrix[b-1][a-1] = c min_span_matrix = floyd_warshall(matrix, directed=False, return...
s630883605
p03634
u245641078
1592933287
Python
PyPy3 (7.3.0)
py
Runtime Error
86
74816
1751
# -*- coding: utf-8 -*- def main(): h, w = map(int, input().split()) grids = [list(input()) for _ in range(h)] up = [[1 for __ in range(w)] for _ in range(h)] down = [[1 for __ in range(w)] for _ in range(h)] left = [[1 for __ in range(w)] for _ in range(h)] right = [[1 for __ in range(w)] for...
s325268465
p03634
u245641078
1592933177
Python
Python (3.8.2)
py
Runtime Error
27
9044
138
N, K = map(int,input().split()) a = list(map(int,input().split())) a = [0] + a A = [0]*(N+1) for i in range(1,N+1): A[i] = A[i-1] + a[i]
s023839402
p03634
u245641078
1592933153
Python
Python (3.8.2)
py
Runtime Error
26
9212
274
from itertools import accumulate N, K = map(int,input().split()) a = list(map(int,input().split())) a = [0] + a A = [0]*(N+1) for i in range(1,N+1): A[i] = A[i-1] + a[i] #A = list(accumulate(a)) ans = 0 for i in range(1,N-K+2): ans += A[i+K-1] - A[i-1] print(ans)
s920581700
p03634
u860002137
1592745803
Python
Python (3.8.2)
py
Runtime Error
581
57988
799
from heapq import heappush, heappop from collections import defaultdict n = int(input()) graph = defaultdict(list) # グラフにコストを格納 for _ in range(n - 1): a, b, c = map(int, input().split()) graph[a].append((b, c)) graph[b].append((a, c)) q, k = map(int, input().split()) # コストの初期化 INF = 1 << 60 dist = [INF...
s446459977
p03634
u054871430
1592703681
Python
PyPy3 (7.3.0)
py
Runtime Error
2209
138212
925
import sys TO_K = [] TREE = [] DISTANCE = [] def dfs(child, parent): for i_node in TREE[parent]: if i_node[0] == child: TO_K[child] = TO_K[parent] + i_node[1] for i_gch in TREE[child]: if i_gch[0] == parent: TO_K[child] = TO_K[parent] + i_gch[1] else: ...
s145484060
p03634
u054871430
1592689355
Python
PyPy3 (7.3.0)
py
Runtime Error
2208
140456
1073
import sys TO_K = [] TREE = [] DISTANCE = [] def dfs(child, parent): small, big = min(child, parent), max(child, parent) for i_distance in DISTANCE[small]: if i_distance[0] == big: TO_K[child] = TO_K[parent] + i_distance[1] for i_gch in TREE[child]: if i_gch == parent: ...
s531733082
p03634
u605674864
1592686370
Python
Python (3.8.2)
py
Runtime Error
904
47628
547
N=int(input()) import sys # sys.setrecursionlimit(10**6) 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()) D=[-1]*N D[K-1]=0 def dfs(start, nowd): to=T[start] for t in to: next_node,c=t ...
s965716838
p03634
u054514819
1592616273
Python
PyPy3 (7.3.0)
py
Runtime Error
2205
3544008
660
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) query = [[0]*N for _ in range(N)] for _ in range(N-1): a, b, c = mapint() query[a-1][b-1] = c query[b-1][a-1] = c Q, K = mapint() from collections import...
s028643981
p03634
u397384480
1592547809
Python
PyPy3 (7.3.0)
py
Runtime Error
666
112288
493
N = int(input()) tree = [[] for _ in range(N)] for i in range(N-1): a,b,c = map(int,input().split()) tree[a-1].append((b-1,c)) tree[b-1].append((a-1,c)) Q,K = map(int,(input().split())) dis = [-1]*N dis[K-1] = 0 def dfs(v,d): for i in tree[v]: d = dis[v] next,c = i if dis[next]...
s907873396
p03634
u127499732
1592357703
Python
Python (3.4.3)
py
Runtime Error
729
188240
960
def main(): from collections import defaultdict import sys sys.setrecursionlimit(100000) n, *rem = map(int, open(0).read().split()) t = 3 * (n - 1) abc = rem[:t] q, k = rem[t], rem[t + 1] xy = rem[t + 2:] m = [[] for _ in range(n + 1)] dist = defaultdict(dict) for a, b, c in...
s037876990
p03634
u127499732
1592357666
Python
Python (3.4.3)
py
Runtime Error
555
98988
959
def main(): from collections import defaultdict import sys sys.setrecursionlimit(20000) n, *rem = map(int, open(0).read().split()) t = 3 * (n - 1) abc = rem[:t] q, k = rem[t], rem[t + 1] xy = rem[t + 2:] m = [[] for _ in range(n + 1)] dist = defaultdict(dict) for a, b, c in ...
s359895788
p03634
u127499732
1592357468
Python
Python (3.4.3)
py
Runtime Error
576
96164
918
def main(): from collections import defaultdict, deque n, *rem = map(int, open(0).read().split()) t = 3 * (n - 1) abc = rem[:t] q, k = rem[t], rem[t + 1] xy = rem[t + 2:] m = [[] for _ in range(n + 1)] dist = defaultdict(dict) for a, b, c in zip(*[iter(abc)] * 3): m[a].appen...
s923114136
p03634
u627803856
1592239712
Python
PyPy3 (2.4.0)
py
Runtime Error
1676
106016
576
n = int(input()) tree = [[] for _ in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) a, b, c = a - 1, b - 1, c tree[a].append((b, c)) tree[b].append((a, c)) limit = 100010 depth = [0] * limit def dfs(v, p, d): # (現在の頂点v, vの親, 現在の距離) depth[v] = d for e in tree[v]: i...
s062159884
p03634
u477320129
1591842843
Python
Python (3.4.3)
py
Runtime Error
582
54152
1495
#!/usr/bin/env python3 import sys def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int, K: int, x: "List[int]", y: "List[int]"): edges = [[] for _ in range(N+1)] for aa, bb, cc in zip(a, b, c): edges[aa].append((bb, cc)) edges[bb].append((aa, cc)) costs = [None] * (N + ...
s410630547
p03634
u618002097
1591471849
Python
Python (3.4.3)
py
Runtime Error
2223
1926772
509
N = int(input()) graph = [[0] * (N+1) for i in range(N+1)] for i in range(N-1): a, b, c = map(int, input().split()) graph[a][b] = c graph[b][a] = c import numpy as np from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, \ bellman_ford, johnson from scipy.sparse import csr_matrix Q,...
s303567765
p03634
u025287757
1591384759
Python
Python (3.4.3)
py
Runtime Error
1713
49908
514
N = int(input()) a = [[] for i in range(N)] for i 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]) dist = [-1]*N Q, K = map(int, input().split()) dist[K-1] = 0 def dfs(now): for i, dis_e in a[now]: if dist[i] == -1: dist[i] = dist[now] + dis_e ...
s265343262
p03634
u025287757
1591383428
Python
Python (3.4.3)
py
Runtime Error
1108
56256
528
N = int(input()) a = [[] for i in range(N)] edge = {} for i 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]) dist = [-1]*N Q, K = map(int, input().split()) dist[K-1] = 0 def dfs(now): for i, dis_e in a[now]: if dist[i] == -1: dist[i] = dist[now] + di...
s317411540
p03634
u025287757
1591382961
Python
Python (3.4.3)
py
Runtime Error
1117
62296
609
N = int(input()) a = [[] for i in range(N)] edge = {} for i in range(N-1): A, B, C = map(int, input().split()) a[A-1].append(B-1) a[B-1].append(A-1) edge[str(A-1)+"and"+str(B-1)] = C edge[str(B-1)+"and"+ str(A-1)] = C dist = [-1]*N Q, K = map(int, input().split()) dist[K-1] = 0 def dfs(now): for i in a[no...
s577005038
p03634
u974792613
1591363698
Python
PyPy3 (2.4.0)
py
Runtime Error
1889
124192
599
def dfs(node, dis, adj_list): for next, d in adj_list[node]: if dis[next] == float("inf"): dis[next] = dis[node] + d dfs(next, dis, adj_list) return n = int(input()) adj_list = [[] for _ in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) a -= 1 ...
s934574057
p03634
u974792613
1591363499
Python
Python (3.4.3)
py
Runtime Error
1630
49852
599
def dfs(node, dis, adj_list): for next, d in adj_list[node]: if dis[next] == float("inf"): dis[next] = dis[node] + d dfs(next, dis, adj_list) return n = int(input()) adj_list = [[] for _ in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) a -= 1 ...
s057710713
p03634
u538632589
1591221429
Python
Python (3.4.3)
py
Runtime Error
983
48360
583
n = int(input()) edges = [[] for _ in range(n)] costs = [-1]*n def dfs(current): for nex, cost in edges[current]: if costs[nex] != -1: continue costs[nex] = costs[current] + cost dfs(nex) for i in range(n-1): a, b, c = map(int,input().split()) a -= 1 b -= 1 edge...
s353363663
p03634
u538632589
1591221061
Python
Python (3.4.3)
py
Runtime Error
970
48452
565
n = int(input()) edges = [[] for _ in range(n)] costs = [-1]*n def dfs(current, d): costs[current] = d for nex in edges[current]: if costs[nex[0]] != -1: continue dfs(nex[0], d+nex[1]) for i in range(n-1): a, b, c = map(int,input().split()) a -= 1 b -= 1 edges[a].app...
s991246945
p03634
u538632589
1591220739
Python
Python (3.4.3)
py
Runtime Error
969
48472
607
import heapq INF = 10**15 n = int(input()) edges = [[] for _ in range(n)] costs = [INF]*n def dfs(current, prev, d): costs[current] = d for nex in edges[current]: if nex[0] == prev: continue dfs(nex[0], current, d+nex[1]) for i in range(n-1): a, b, c = map(int,input().split()) ...
s944751358
p03634
u347600233
1591164826
Python
Python (3.4.3)
py
Runtime Error
902
49900
518
n = int(input()) to = [[] for _ in range(n + 1)] for i in range(n - 1): a, b, c = map(int, input().split()) to[a].append((b, c)) to[b].append((a, c)) q, k = map(int, input().split()) dist_k = [0] + [-1] * n dist_k[k] = 0 def dfs(v): for u, du in to[v]: if dist_k[u] != -1: continue ...
s514961146
p03634
u484229314
1590975463
Python
PyPy3 (2.4.0)
py
Runtime Error
1800
107296
511
from collections import deque N = int(input()) G = [[] for _ in range(N + 1)] for i in range(N - 1): a, b, c = [int(_) for _ in input().split()] G[a].append((b, c)) G[b].append((a, c)) Q, K = [int(_) for _ in input().split()] # make tree G2 = [-1] * (N + 1) def f(v, c, p): if G2[v] != -1: return ...