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
s221740811
p03659
u463655976
1560475220
Python
Python (3.4.3)
py
Runtime Error
65
19068
160
N = int(input()) a = map(int, input().split()) s = sum(a) w = None for i in a[:-1]: s -= 2 * a if w is None: w = s else: w = min(w, s) print(w)
s614111300
p03659
u797550216
1560042746
Python
PyPy2 (5.6.0)
py
Runtime Error
94
68324
312
n = int(input()) l = list(map(int,input().split())) l.reverse() x = 0 sum_x = [] for i in range(n-1): x += l[i] sum_x.append(x) sum_y = [sum(l)]*(n-1) for i in range(n-1): sum_y[i] -= sum_x[i] abs_xy = [] for i in range(n-1): abs_xy.append(abs(sum_x[i]-sum_y[i])) print(min(abs_xy))
s597407828
p03659
u734548018
1558141886
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38640
279
# /usr/bin/python # -*- coding: utf-8 -*- import math import numpy as np N = int(input()) An = list(map(int, input().split())) sm = [0, sum(An)] ans = abs(An[0] - sum(An[1:])) for i in range(N-1): sm[0] += An[i] sm[1] -= An[i] ans = min(ans, abs(sm[0]-sm[1])) print(ans)
s715302351
p03659
u734548018
1558141559
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38384
265
# /usr/bin/python # -*- coding: utf-8 -*- import math import numpy as np N = int(input()) An = np.asarray(list(map(int, input().split()))) cumsum = np.cumsum(An) sm = np.sum(An) ans = 10**14+1 for i in range(N-1): ans = min(ans, abs(sm-2*cumsum[i])) print(ans)
s330466770
p03659
u814781830
1556497622
Python
Python (3.4.3)
py
Runtime Error
79
24832
142
N = int(input()) a = [int(i) for i in input().split()] res = [] for i in range(1,len(a)): res.append(abs(a[:i+1]-a[i:])) print(min(res))
s258459226
p03659
u037430802
1555612715
Python
Python (3.4.3)
py
Runtime Error
71
24832
217
#普通にやるとTLE n = int(input()) a = list(map(int, input().split())) total = sum(a) ans = float("inf") for i in range(n-1): x += a[i] y = total - x if(abs(x-y) < ans): ans = abs(x-y) print(ans)
s037280078
p03659
u442581202
1555433646
Python
Python (3.4.3)
py
Runtime Error
112
23800
233
import math n = int(input()) data = list(map(int,input().split())) s = 0 for i in range(n): s += data[i] data[i] = s a = data[-1] res = math.inf for i in range(n-1): res = min(res,abs(data[i]-(a-data[i]))) print(res)
s859888328
p03659
u013408661
1554246474
Python
Python (3.4.3)
py
Runtime Error
68
24800
173
n=int(input()) a=list(map(int,input().split())) b=[] sum_=0 for i in a: sum_+=i b.append(sum_a) ans=10**18 for i in range(n-1): ans=min(ans,abs(b[-1]-b[i])) print(ans)
s983734943
p03659
u013408661
1554246455
Python
Python (3.4.3)
py
Runtime Error
72
24800
174
n=int(input()) a=list(map(int,input().split())) b=[] sum_=0 for i in a: sum_a+=i b.append(sum_a) ans=10**18 for i in range(n-1): ans=min(ans,abs(b[-1]-b[i])) print(ans)
s554410993
p03659
u771532493
1552780764
Python
Python (3.4.3)
py
Runtime Error
17
2940
173
N=int(input()) lst=[int(i) for i in input().split()] import numpy res=numpy.cumsum(lst) ans=10e10 for i in range(N): ans=min(ans,abs(res[i]-(res[-1]-res[i])) print(ans)
s902786746
p03659
u543954314
1550724323
Python
Python (3.4.3)
py
Runtime Error
73
23800
177
n = int(input()) a = list(map(int, input().split())) s = sum(a) ans = float("inf") for i in range(1,n): x = sum(s[:i])*2 if ans > abs(x - s): ans = abs(x - s) print(ans)
s508322296
p03659
u191829404
1550441465
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38412
313
from collections import defaultdict, Counter import math from bisect import bisect_left, bisect_right import numpy as np #### START n = int(input()) a = list(map(int,input().split())) ans = 10**100 for i in range(1, n): if ans>abs(sum(a[:i])-sum(a[i:])): ans = abs(sum(a[:i])-sum(a[i:])) print(ans)
s829310519
p03659
u325264482
1549245184
Python
Python (3.4.3)
py
Runtime Error
2104
23800
165
N = int(input()) a = list(map(int, input().split())) a = sorted(a) X = sum(a) ans = [] for i in range(1, N - 1): ans.append(X - 2*sum(a[:i])) print(min(ans))
s277134150
p03659
u700806147
1547071687
Python
Python (3.4.3)
py
Runtime Error
76
24816
209
N = int(input()) A = list(map(int, input().split())) A_r = A[::-1] cumsum_A = np.cumsum(A) cumsum_A_r = np.cumsum(A_r) x = [abs(a - a_r) for (a, a_r) in zip(cumsum_A[:-1], cumsum_A_r[-2::-1])] print(min(x))
s868223173
p03659
u328755070
1546121301
Python
Python (3.4.3)
py
Runtime Error
18
3064
207
N = int(input()) a = list(map(int, input().split())) A = 0 B = sum(a) min = B for i in range(N-1): A += a[i] B -= a[i] if min > abs(A - B): min = abs(A - B) print(ans)
s236468983
p03659
u853900545
1545711713
Python
Python (3.4.3)
py
Runtime Error
78
24832
226
n = int(input()) a = list(map(int,input().split())) A = sum(a[:n-1:])-a[n] c = 10*9 c = min(c,A) if n == 2: print(abs(a[0]-a[1])) else: for i in range(1,n-1): A=A-2*a[n-i] c = min(c,abs(A)) print(c)
s619958999
p03659
u853900545
1545711396
Python
Python (3.4.3)
py
Runtime Error
19
2940
229
n = int(input()) a = list(map(int,input().split())) if n == 2: print(abs(a[0]-a[1])) else: A = sum(a[:n:])-a[n-1] c = 10*9 c = min(c,A) for i in range(1,n-1): A=abs(A-2*a[n-i]) c = min(c,A) print(c)
s997278406
p03659
u853900545
1545711370
Python
Python (3.4.3)
py
Runtime Error
18
2940
229
n = int(input()) a = list(map(int,input().split())) if n == 2: print(abs(a[0]-a[1])) else: A = sum(a[:n:])-a[n-1] c = 10*9 c = min(c,A) for i in range(1,n-1): A=abs(A-2*a[n-i]) c = min(c,A) print(c)
s949068237
p03659
u844789719
1543290527
Python
Python (3.4.3)
py
Runtime Error
241
24672
316
N = int(input()) A = sorted([int(_) for _ in input().split()], key=lambda x: abs(x)) ans = 0 pos = False neg = False while A: a = A.pop() if ans * a > 0: ans -= a neg = True else: ans += a pos = True if pos & neg: print(abs(ans)) else: print(abs(A[0]-sum(A[1:])))
s791329732
p03659
u240793404
1541000960
Python
Python (3.4.3)
py
Runtime Error
17
3060
232
from _overlapped import NULL n = int(input()) a = list(map(int,input().split())) ans = NULL for i in range(n): tmp = abs(sum(a[:i])-sum(a[i:])) if ans == NULL: ans = tmp if tmp < ans: ans = tmp print(ans)
s019091236
p03659
u603234915
1539963969
Python
Python (3.4.3)
py
Runtime Error
17
2940
231
def main(): N = int(input()) l = list(map(int, input().split())) ans = [] X = sum(l) for i in range(N-1): X = abs(X-2*l[i]) ans.append(X) print(min(ans)) if __name__ == '__main__': main()
s057557297
p03659
u940102677
1539868722
Python
Python (3.4.3)
py
Runtime Error
65
19068
152
n = int(input()) a = map(int, input().split()) s = sum(a) x = a[0] m = abs(s-2*x) for i in range(1,n-1): x += a[i] m = min(m,abs(s-2*x)) print(s)
s476474042
p03659
u513081876
1537923651
Python
Python (3.4.3)
py
Runtime Error
64
19068
187
n = int(input()) a = map(int, input().split()) sunu = sum(a) arai = 0 ans = 2*10**9 for i in range(n-1): sunu -= a[i] arai += a[i] ans = min(ans,abs(sunu-arai)) print(ans)
s753640265
p03659
u932465688
1537218953
Python
Python (3.4.3)
py
Runtime Error
17
2940
147
N = int(input()) L = list(map(int,input().split())) S = sum(L) A = [] for i in range(1,N): p = abs(2*sum(L[0:i])-S) A.append(p) print(min(A))
s771200576
p03659
u102902647
1536825346
Python
Python (3.4.3)
py
Runtime Error
2104
24812
174
N = int(input()) A = [int(i) for i in input().split()] res = [] for i in range(1, N-1): snk = sum(A[:i]) arg = sum(A[i:]) res.append(abs(snk-arg)) print(min(res))
s151908153
p03659
u427344224
1536452607
Python
Python (3.4.3)
py
Runtime Error
70
24932
330
N = int(input()) a_list = list(map(int, input().split())) a_sum = sum(a_list) min_num = float("inf") r = [] for i in range(1, N): if len(r) == 0: r.append(a_list[0]) else: r.append(r[i-1] + a_list[i]) x = r[i-1] y = a_sum - x if min_num >= abs(x-y): min_num = abs(x-y) prin...
s510308490
p03659
u807772568
1534273641
Python
Python (3.4.3)
py
Runtime Error
68
23800
174
a = int(input()) aa = list(map(int,input().split())) for i in range(1,a): aa[i] += a[i-1] su = 10**20 for i in range(a): su = min(su,abs(aa[a-1]-2*aa[i])) print(su)
s978030999
p03659
u807772568
1534273565
Python
Python (3.4.3)
py
Runtime Error
69
24832
173
a = int(input()) aa = list(map(int,input().split())) for i in range(1,a): aa[i] += a[i-1] su = 10**20 for i in range(a): su = min(su,abs(aa[a-1]-2*a[i])) print(su)
s654548962
p03659
u807772568
1534273548
Python
Python (3.4.3)
py
Runtime Error
70
24812
173
a = int(input()) aa = list(map(int,input().split())) for i in range(1,a): aa[i] += a[i-1] su = 10**20 for i in range(a): su = min(su,abs(aa[a-1]-2*a[i])) print(sU)
s097435757
p03659
u419686324
1534220034
Python
Python (3.4.3)
py
Runtime Error
78
25188
206
import math N = int(input()) A = [int(x) for x in input().split()] total = sum(A) ans = math.inf nusuke = 0 for a in A[:-1]: nusuke += a ans = min(ans, abs(nusuke - (total - nusuke))) print(ans)
s005616688
p03659
u200239931
1528068339
Python
Python (3.4.3)
py
Runtime Error
37
19068
724
def getinputdata(): array_result = [] data = input() array_result.append(data.split(" ")) flg = True try: while flg: data = input() if(data != ""): array_result.append(data.split(" ")) flg = True ...
s503227038
p03659
u226108478
1525465958
Python
Python (3.4.3)
py
Runtime Error
166
24392
435
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': from itertools import accumulate from bisect import bisect_left n = int(input()) a = sorted(list(map(int, input().split()))) summed_a = list(accumulate(a)) x = bisect_left(summed_a, max(summed_a) // 2) ...
s467482132
p03659
u503901534
1524896017
Python
Python (3.4.3)
py
Runtime Error
18
3060
245
n = int(input()) a = list(map(int,input().split())) sss = 0 for i in range(n): sss=sss + a[i] ppp = 0 qqq = abs(sss - 2 * a[0]) for i in range(n): ppp=ppp + a[i] qo = abs(sss-2ppp) if qqq > qo: qqq=qo print(qqq)
s337588499
p03659
u766407523
1524745628
Python
Python (3.4.3)
py
Runtime Error
68
23800
212
import math N = int(input()) a = list(map(int, input().split())) ans = math.inf f, s = 0, sum(a) for a_i in a: f += a_i s -= a_i ans = min(ans, abs(f-s)) if N == 2: ans = abs(a[0]-a[1]) print(ans)
s453761682
p03659
u766407523
1524744495
Python
Python (3.4.3)
py
Runtime Error
68
23800
196
import math N = int(input()) a = list(map(int, input().split())) ans = math.inf for i in range(1, N): ans = min(ans, abs(sum(a[:i])-sum(a[i:]))) if N == 2: ans = abs(a[0]-a[1]) print(ans)
s511981095
p03659
u766407523
1524712040
Python
Python (3.4.3)
py
Runtime Error
68
23800
198
import math N = int(input()) a = list(map(int, input().split())) ans = math.inf for i in range(1, N-1): ans = min(ans, abs(sum(a[:i])-sum(a[i:]))) if N == 2: ans = abs(a[0]-a[1]) print(ans)
s628240294
p03659
u766407523
1524711117
Python
Python (3.4.3)
py
Runtime Error
69
23800
197
import math N = int(input()) a = list(map(int, input().split())) ans = math.inf for i in range(1, N-1): ans = min(ans, abs(sum(a[:i])-sum(a[i:]))) if N == 2: ans = abs(a[0]-a[1]) print(ans)
s588606624
p03659
u952708174
1522637877
Python
Python (3.4.3)
py
Runtime Error
17
3060
434
def c_splitting_pile(N, A): # Aの要素の総和をX、カードの山の先頭i枚の総和をxとすると、 # |y-x|=|X-2x|である。各iについてこの値を計算すればよい total = sum(A) ans = float('inf') s = 0 for i in range(N-1): s += A[i] ans = min(ans, abs(total - s * 2)) return ans N = int(input()) A = [int(i) for i in input().split()] print(...
s051628474
p03659
u030726788
1520043093
Python
Python (3.4.3)
py
Runtime Error
70
23800
225
import sys n=int(input()) a=list(map(int,input().split())) s=sum(a) if(n==2): mi=abs(a[0]-a[1]) else: s1=a[0] for i in range(1,len(a)-1): s1+=a[i] s2=s-s1 #print(s1,s2) mi=min([mi,abs(s1-s2)]) print(mi)
s507750173
p03659
u557171945
1518558614
Python
Python (3.4.3)
py
Runtime Error
2107
54808
409
def search(ans, s, ar, si = 0, ari = 0): if si+ari == n: if not(ari == 0) and not(si == 0): ans.append(abs(sum(s)-sum(ar))) return s.append(a[si+ari]) search(ans,s,ar,si+1,ari) s.pop() ar.append(a[si+ari]) search(ans,s,ar,si,ari+1) ar.pop() n = int(input()) a =...
s918704603
p03659
u136090046
1510791924
Python
Python (3.4.3)
py
Runtime Error
87
23800
318
import math num = int(input()) cards = [int(x) for x in input().split()] res = sum(cards) res2 = 0 judge = math.inf if num == 2: judge = abs(cards[0]-cards[1]) else: for i in cards: res -= i res2 += i div = abs(res - res2) judge = div if div < judge else judge print(judge)
s503329168
p03659
u136090046
1510791858
Python
Python (3.4.3)
py
Runtime Error
87
23800
318
import math num = int(input()) cards = [int(x) for x in input().split()] res = sum(cards) res2 = 0 judge = math.inf if num == 2: judge = abs(cards[0]-cards[1]) else: for i in cards: res -= i res2 += i div = abs(res - res2) judge = div if div < judge else judge print(judge)
s841926973
p03659
u858136677
1507153551
Python
Python (3.4.3)
py
Runtime Error
2104
23800
355
def abs(n): if n >= 0: return n else: return -n n = int(input()) a = list(map(int,input().split())) x = 0 y = 0 difference = [] total = 0 if n % 2 != 0: n += 1 for i in range(n): total += a[i] for i in range(1,n//2 +1): for k in range(i): x += a[k] y = total - x b = x - y difference.append(abs(b)) dif...
s399858661
p03659
u425351967
1506611817
Python
Python (3.4.3)
py
Runtime Error
17
2940
276
~ "arc078_a.py" 13L, 193C 1,1 全て N = int(input()) a = [int(n) for n in input().split()] x = 0 y = sum(a) res = 1000000000000000 for i in range(N-1): x += a[i] y -= a[i] if res > abs(x-y): res = abs(x-y) print(res)
s516333962
p03659
u425351967
1506611805
Python
Python (3.4.3)
py
Runtime Error
18
2940
277
~ "arc078_a.py" 13L, 193C 1,1 全て N = int(input()) a = [int(n) for n in input().split()] x = 0 y = sum(a) res = 1000000000000000 for i in range(N-1): x += a[i] y -= a[i] if res > abs(x-y): res = abs(x-y) print(res)
s137186180
p03659
u872833608
1504964281
Python
Python (3.4.3)
py
Runtime Error
99
17904
225
N = int(input()) card = map(int,input().split(" ")) all = 0 for i in card: all += i a = all ab = all for i in range(len(card),-1): b -= card[i] if abs(a - b) > ab: break a,ab = b,abs(a - b) print(ab)
s675607328
p03659
u666428701
1501191282
Python
Python (3.4.3)
py
Runtime Error
79
23800
215
# -*- coding: utf-8 -*- n = int(input()) a =list(map(int, input().split())) N = sum(a) r = float('inf') x = 0 for i in range(N-1): x += a[i] y = N - x if r > abs(x -y): r = abs(x -y) print(r)
s803206366
p03659
u351527281
1500950541
Python
Python (3.4.3)
py
Runtime Error
17
2940
208
n = int(input()) a = [int(i) for i in input().split()] result = abs(sum(a[0:1]) - sum(a[1:])) for i in range(1:n-1): d = abs(sum(a[0:i+1]) - sum(a[i+1:])) if d<result: result = d print(result)
s638830961
p03659
u846694620
1500174473
Python
Python (3.4.3)
py
Runtime Error
82
23800
189
import math n = int(input()) a = [int(x) for x in input().split()] l = 0 r = sum(a) d = math.inf for i in range(n - 1): l += a[i] r -= a[i] d = min(d, abs(l - r)) print(d)
s859300462
p03659
u371037736
1500174463
Python
Python (3.4.3)
py
Runtime Error
20
5616
481
num_cards = int(input()) str_value_of_cards_list = input().split value_of_cards_list = [int(i) for i in str_value_of_cards_list] num_A = 0 num_B = 0 a =0 while(is_yet_in): for num_card in range(num_cards): if num_A - num_B > 0: a = num_card is_yet_in = false break ...
s448311128
p03659
u371037736
1500174344
Python
Python (3.4.3)
py
Runtime Error
17
2940
443
num_cards = int(input()) str_value_of_cards_list = input().split value_of_cards_list = [int(i) for i in str_value_of_cards_list] num_A = 0 num_B = 0 a =0 while(): for num_card in range(num_cards): if num_A - num_B > 0: a = num_card break: for i in value_of_cards_list[:num...
s274652952
p03659
u462626125
1500173879
Python
Python (3.4.3)
py
Runtime Error
17
3064
201
nums = [int(x) for x in input().split()] N = nums[0],nums[1] A = [int(x) for x in input().split()] X = sum(A) MIN = 10**8 for i in range(N): s = A[0:i] MIN = (MIN,abs(X - 2*sum(s))) print(MIN)
s200852795
p03659
u462626125
1500173878
Python
Python (3.4.3)
py
Runtime Error
18
3064
201
nums = [int(x) for x in input().split()] N = nums[0],nums[1] A = [int(x) for x in input().split()] X = sum(A) MIN = 10**8 for i in range(N): s = A[0:i] MIN = (MIN,abs(X - 2*sum(s))) print(MIN)
s827336167
p03659
u462626125
1500173836
Python
Python (3.4.3)
py
Runtime Error
17
2940
200
nums = [int(x) for x in input().split()] N = nums[0],nums[1] A = [int(x) for x in input().split()] X = sum(A) MIN = 10**8 for i in range(N): s = [0:i] MIN = (MIN,abs(X - 2*sum(s))) print(MIN)
s203336739
p03659
u772180901
1500173307
Python
Python (3.4.3)
py
Runtime Error
117
19068
245
n = int(input()) arr = input().split() ans = [] for i in range(n): arr[i] = int(arr[i]) x = 0 y = sum(arr) for i in range(n): if x <= y: x += arr[i] y -= arr[i] ans.append(x - y) ans = map(abs,ans) print(min(ans))
s599897484
p03659
u371037736
1500172884
Python
Python (3.4.3)
py
Runtime Error
18
3188
444
num_cards = int(input()) str_value_of_cards_list = input().split value_of_cards_list = [int(i) for i in str_value_of_cards_list] num_A = 0 num_B = 0 a =0 while(): for num_card in range(num_cards): if num_A - num_B > 0: a = num_card break: for i in value_of_cards_list[:num_c...
s851061626
p03659
u343991457
1500172772
Python
Python (2.7.6)
py
Runtime Error
11
2692
226
n=input() a=[]; for i in range(n): a.append(input()) for i in range(n-1): a[i+1]=a[i+1]+a[i] p=1 q=n-1 while q-p>1: if a[n]-2*a[(q+p)/2]>0 p=(p+q)/2 else q=(p+q)/2 print(min(abs(a[n]-2*a[p]),abs(a[n]-2*a[q])))
s801713438
p03659
u711741418
1500170139
Python
Python (3.4.3)
py
Runtime Error
400
26876
303
#!/usr/bin/env python3 # -*- coding: utf-8 -*- N = int(input()) ax = list(map(int, input().split())) ls = [] A = sum(ax[:1]) B = sum(ax[1:]) for i in range(2, N): sub = abs(A-B) print(sub) ls.append(sub) if(sub is 0): break A -= ax[i] B += ax[i] print(sorted(ls)[0])
s269619933
p03659
u772180901
1500170116
Python
Python (3.4.3)
py
Runtime Error
123
19068
232
n = int(input()) arr = input().split() ans = [] for i in range(n): arr[i] = int(arr[i]) x = 0 y = sum(arr) for i in range(n): if x <= y: x += arr[i] y -= arr[i] ans.append(abs(x - y)) print(min(ans))
s447327649
p03659
u354915818
1500169345
Python
Python (3.4.3)
py
Runtime Error
198
32548
419
s = input().split() s = [int(i) for i in s] N = s[0] s = input().split() a = [int(i) for i in s] L = [0] * N L[0] = a[0] - sum(a[1 : ]) if N == 2 : print(abs(a[0] - a[1])) else : MIN = float("inf") for i in range(1 , N - 1 ) : L[i] = L[i - 1] + 2 * a[i] if L[i] * L[i - 1] <= 0 : ...
s333524924
p03660
u074220993
1599903719
Python
Python (3.8.2)
py
Runtime Error
801
85932
2219
import typing from typing import List, NamedTuple, Deque, Set, Counter class node: def __init__(self, id: int) -> None: self.id: int = id self.parent: node = self self.root: node = self self.rank: int = 0 self.connection: List[node] = [] def addConnection(self, other: '...
s299536194
p03660
u074220993
1599902559
Python
Python (3.8.2)
py
Runtime Error
849
86056
2113
from collections import deque, Counter import typing from typing import List, NamedTuple, Deque, Set, Counter class node: def __init__(self, id: int) -> None: self.id: int = id self.parent: node = self self.root: node = self self.rank: int = 0 self.connection: List[node] =...
s709541178
p03660
u074220993
1599901987
Python
Python (3.8.2)
py
Runtime Error
773
86016
2084
from collections import deque, Counter import typing from typing import List, NamedTuple, Deque, Set, Counter class node: def __init__(self, id: int) -> None: self.id: int = id self.parent: node = self self.root: int = self self.rank: int = 0 self.connection: List[node] = ...
s034700344
p03660
u231095456
1599514615
Python
Python (3.8.2)
py
Runtime Error
692
43872
785
import heapq as hq N = int(input()) edges = [[] for _ in range(N)] for _ in range(N-1): a,b = map(int,input().split()) a-=1 b-=1 edges[a].append((b,1)) edges[b].append((a,1)) INF = float("inf") d = [INF]*N d[0] = 0 q = [(0,0)] while q: dist, i = hq.heappop(q) if d[i] < dist: continue...
s044422064
p03660
u192154323
1598898724
Python
Python (3.8.2)
py
Runtime Error
1045
651688
1268
from collections import deque import sys sys.setrecursionlimit(10**7) n = int(input()) ad_ls = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) ad_ls[a-1].append(b-1) ad_ls[b-1].append(a-1) # 最終的にsnukeがnの半分以上のマスを所有していればsnukeの勝ち # まず、fennecからsnukeへのパスを求める node_from = [-1] * n time ...
s413953673
p03660
u192154323
1598898684
Python
PyPy3 (7.3.0)
py
Runtime Error
1112
731788
1268
from collections import deque import sys sys.setrecursionlimit(10**7) n = int(input()) ad_ls = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) ad_ls[a-1].append(b-1) ad_ls[b-1].append(a-1) # 最終的にsnukeがnの半分以上のマスを所有していればsnukeの勝ち # まず、fennecからsnukeへのパスを求める node_from = [-1] * n time ...
s108192942
p03660
u192154323
1598898659
Python
PyPy3 (7.3.0)
py
Runtime Error
321
93212
1228
from collections import deque n = int(input()) ad_ls = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) ad_ls[a-1].append(b-1) ad_ls[b-1].append(a-1) # 最終的にsnukeがnの半分以上のマスを所有していればsnukeの勝ち # まず、fennecからsnukeへのパスを求める node_from = [-1] * n time = [float('inf')] * n q = deque() q.appe...
s828474818
p03660
u070201429
1598719929
Python
PyPy3 (7.3.0)
py
Runtime Error
234
100112
995
from sys import stdin, setrecursionlimit def input(): return stdin.readline().strip() #setrecursionlimit((10**5) * 2) n = int(input()) edge = [[] for _ in range(n)] for _ in range(n-1): i, j = map(int, input().split()) i -= 1 j -= 1 edge[i].append(j) edge[j].append(i) # root: 0 # edge1: pare...
s814133521
p03660
u107639613
1596680020
Python
PyPy3 (7.3.0)
py
Runtime Error
200
96384
4641
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() class UnionFind(): """ https://note.nkmk.me/python-union-find/ DFSの上位互換と考えて良い 2要素x, yがpath-connectedかどうかをlogオーダーで判定する(螺旋本の14.1節参照) さらに連結成分の要素数がO(1)で取得可能なように改造してある """ def __init__(self, n): ...
s486535169
p03660
u306950978
1596555871
Python
Python (3.8.2)
py
Runtime Error
425
31292
839
from collections import deque def f(x,q): for i in route[x]: if not visit[i]: visit[i] = True f(i,q+[i]) visit[i] = False if i == n-1: p = q + [i-1] flag = True return p n = int(input()) route = [[] for i in rang...
s840052336
p03660
u980783809
1595979284
Python
Python (3.8.2)
py
Runtime Error
343
43560
769
n = int(input()) abss = [] g = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) abss.append((a-1,b-1)) g[a-1].append(b-1) g[b-1].append(a-1) ds = [-1]*n n_l_total = [0] def dfs(idx,s): ds[idx] = 1 ret = None for i in g[idx]: if ds[i] == -1: s_...
s230171744
p03660
u786020649
1595915917
Python
Python (3.8.2)
py
Runtime Error
267
38804
680
from collections import deque, defaultdict def main(): n=int(input()) edges=[tuple(map(int,input().split())) for _ in range(n-1)] d=defaultdict(list) for e in edges: d[e[0]].append(e[1]) d[e[1]].append(e[0]) def dist(m): dl=[-1]*(n+1) cv=deque([m]) nv=deque([1]) while nv: c+=1 ...
s957213408
p03660
u685983477
1594563376
Python
PyPy3 (7.3.0)
py
Runtime Error
300
90336
1327
import itertools from collections import deque n=int(input()) edge = [[] for _ in range(n)] visited = [0]*n for i in range(n-1): a,b=map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) path = [] def dfs(i): visited[i]=1 if(i==n-1): return 1 else: for j in edge[i...
s946037716
p03660
u819135704
1593491652
Python
Python (3.8.2)
py
Runtime Error
268
26864
1062
import collections N = int(input()) tree = [[] for _ in range(N)] #i行目には、i番目のマスと隣り合っているマスの番号が加えられる for _ in range(N-1): a, b = map(int, input().split()) tree[a-1].append(b-1) tree[b-1].append(a-1) color = [0] * N #色が塗られていなければ0、黒は1、白は-1 color[0] = 1 color[N-1] = -1 que = collections.depue() #色が塗られたマスの番号を、隣...
s419783389
p03660
u127499732
1592963904
Python
Python (3.8.2)
py
Runtime Error
791
49136
1598
def dijkstra(s, g): import heapq n = len(g) heap = [(0, s)] heapq.heapify(heap) prev = [-1] * n cost = [float("Inf")] * n cost[s] = 0 while heap: c, v = heapq.heappop(heap) x = cost[v] if c > x: continue for d, u in g[v]: path = ...
s401743963
p03660
u677121387
1592347271
Python
Python (3.4.3)
py
Runtime Error
551
28332
793
n = int(input()) G = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) dist = [(0,-1) for _ in range(n)] def dfs(now,prev=-1): for nxt in G[now]: if nxt == prev: continue dist[nxt] = (dist[now][0]+1,now) ...
s180446900
p03660
u760569096
1591427477
Python
Python (3.4.3)
py
Runtime Error
470
24788
737
from collections import deque N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N q=deque() a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0 and j != i: a[j] = a[i] + 1...
s414130811
p03660
u760569096
1591427215
Python
Python (3.4.3)
py
Runtime Error
459
24788
715
from collections import deque N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N q=deque() a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0: a[j] = a[i] + 1 q.ap...
s330341210
p03660
u760569096
1591426692
Python
Python (3.4.3)
py
Runtime Error
470
24784
731
from collections import deque N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N e = [] a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0: a[j] = a[i] + 1 e.appen...
s680542025
p03660
u760569096
1591425109
Python
Python (3.4.3)
py
Runtime Error
480
24456
698
N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N e = [] a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0: a[j] = a[i] + 1 e.append(j) if len(e) != 0: f =...
s944356141
p03660
u760569096
1591424691
Python
Python (3.4.3)
py
Runtime Error
457
24460
703
N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N e = [] a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0: a[j] = a[i] + 1 e.append(j) if len(e) != 0: f =...
s127942299
p03660
u760569096
1591422928
Python
Python (3.4.3)
py
Runtime Error
468
24456
712
N = int(input()) g = [ [] for i in range(N)] for _ in range(N-1): a, b = map(int, input().split()) g[b-1].append(a-1) g[a-1].append(b-1) visit = [0]*N e = [] a = [0]*N b = [0]*N def tansakuf(i): visit[i] = 1 for j in g[i]: if visit[j] == 0: a[j] = a[i] + 1 e.append(j) if len(e) != 0: f =...
s812856089
p03660
u545368057
1591276563
Python
Python (3.4.3)
py
Runtime Error
608
24812
1221
n = int(input()) edges = [[] for i in range(n)] for i in range(n-1): a,b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) f = 0 s = 0 from collections import deque ps = [-1] * n used = [False] * n used[0] = True # 始めどこから行くか q = deque([0]) while len(q) > 0: a = q.po...
s336790260
p03660
u380524497
1591128637
Python
Python (3.4.3)
py
Runtime Error
591
22960
1230
n = int(input()) edges = [[] for _ in range(n)] for _ in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) seen = [-1] * n def dfs(node, prev): if seen[node] != -1: return seen[node] = prev for to in edges[node]: dfs(to,...
s624324687
p03660
u380524497
1591128565
Python
Python (3.4.3)
py
Runtime Error
506
23016
1230
n = int(input()) edges = [[] for _ in range(n)] for _ in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) seen = [-1] * n def dfs(node, prev): if seen[node] != -1: return seen[node] = prev for to in edges[node]: dfs(to,...
s710704116
p03660
u338824669
1590953886
Python
Python (3.4.3)
py
Runtime Error
484
24000
799
from collections import deque N=int(input()) graph=[[] for _ in range(N)] for _ in range(N-1): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) dist=[float("inf")]*N dist[0]=0 prev=[None]*N def dfs1(v,parent,d): prev[v]=parent dist[v]=d for v2 in graph[v]:...
s498197830
p03660
u698176039
1590723365
Python
Python (3.4.3)
py
Runtime Error
570
130028
1142
# 2020-05-28 22:45:55 import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline N = int(input()) ab = [list(map(int,input().split())) for _ in range (N-1)] edge = [[] for _ in range(N)] for u,v in ab: edge[u-1].append(v-1) edge[v-1].append(u-1) fromNode = [0] * N def dfs(v, p): for nv in edge[v...
s579664819
p03660
u698176039
1590723185
Python
Python (3.4.3)
py
Runtime Error
576
130028
1143
# 2020-05-28 22:45:55 import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline N = int(input()) ab = [list(map(int,input().split())) for _ in range (N-1)] edge = [[] for _ in range(N)] for u,v in ab: edge[u-1].append(v-1) edge[v-1].append(u-1) fromNode = [-1] * N def dfs(v, p): for nv in edge[...
s375411201
p03660
u988402778
1589143481
Python
PyPy3 (2.4.0)
py
Runtime Error
2114
146588
20094
def main(sample_file = ''): """ convenient functions # for i, a in enumerate(iterable) # q, mod = divmod(a, b) # divmod(x, y) returns the tuple (x//y, x%y) # Higher-order function: reduce(operator.mul, xyz_count, 1) # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc...
s359903453
p03660
u988402778
1589139178
Python
PyPy3 (2.4.0)
py
Runtime Error
2112
146488
20050
def main(sample_file = ''): """ convenient functions # for i, a in enumerate(iterable) # q, mod = divmod(a, b) # divmod(x, y) returns the tuple (x//y, x%y) # Higher-order function: reduce(operator.mul, xyz_count, 1) # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc...
s749264238
p03660
u145600939
1588987569
Python
Python (3.4.3)
py
Runtime Error
548
24460
554
n = int(input()) path = [[] for _ in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1 b -= 1 path[a].append(b) path[b].append(a) parent = [-1]*n size = [1]*n d = [0]*n def dfs(now): for nxt in path[now]: if nxt != parent[now]: parent[nxt] = now ...
s200117524
p03660
u203843959
1588541894
Python
Python (3.4.3)
py
Runtime Error
368
27176
1327
import sys input=sys.stdin.readline from collections import deque N=int(input()) graph=[[] for _ in range(N+1)] for _ in range(N-1): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) #print(graph) def dfs_init(u,ls): global path visited[u]=True if u==N: path=ls return for v...
s059544017
p03660
u609061751
1588383109
Python
PyPy3 (2.4.0)
py
Runtime Error
399
66864
1169
import sys input = sys.stdin.readline import heapq def dijkstra(s): # 始点sから各頂点への最短距離 d = [float('inf')]*n d[s] = 0 # 各頂点が訪問済みかどうか used = [False]*n used[s] = True # 仮の距離を記録するヒープ que = [] for e in edge[s]: heapq.heappush(que, e) while que: minedge = heapq.heappop(q...
s057973143
p03660
u291766461
1588361580
Python
PyPy3 (2.4.0)
py
Runtime Error
715
59936
549
N = int(input()) edges = [[] for _ in range(N)] for _ in range(N-1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) dist = [0] * N def dfs(u, d, p=-1): global dist dist[u] = d for v in edges[u]: if v == p: continue dfs(v,...
s371377982
p03660
u867320886
1588209665
Python
Python (3.4.3)
py
Runtime Error
861
114332
498
import sys sys.setrecursionlimit(100000) n = int(input()) edge = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) def dfs(v,d,dist): dist[v] = d for ve in edge[v]: if dist[ve] is None: dist = dfs(ve, d+1, dis...
s713645581
p03660
u867320886
1588209259
Python
Python (3.4.3)
py
Runtime Error
530
22884
456
n = int(input()) edge = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) def dfs(v,d,dist): dist[v] = d for ve in edge[v]: if dist[ve] is None: dist = dfs(ve, d+1, dist) return dist f_dist = dfs(...
s211292815
p03660
u867320886
1588209026
Python
Python (3.4.3)
py
Runtime Error
521
22888
473
def dfs(v,d,dist,edge): dist[v] = d for ve in edge[v]: if dist[ve] is None: dist = dfs(ve, d+1, dist, edge) return dist n = int(input()) edge = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) f_dist...
s441291250
p03660
u256093215
1587605771
Python
Python (3.4.3)
py
Runtime Error
651
24452
622
N = int(input()) g = [[] for _ in range(N + 5)] #g = [[0 for i in range(N+1)] for j in range(N+1)] Fennec = [0]*(N+1) Sunuke = [0]*(N+1) mass = [0]*(N+1) def dFs(r,f,d): Fennec[r]=int(d) for x in range(len(g[r])): if g[r][x]!= f: dFs(g[r][x],r,d+1) def dfS(r,f,d): Sunuke[r]=int(d) for x in range(len(g[r])): ...
s261316348
p03660
u652057333
1587298016
Python
PyPy3 (2.4.0)
py
Runtime Error
386
59824
994
import sys input = sys.stdin.buffer.readline from collections import deque n = int(input()) edges = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) nodes = [0 for _ in range(n)] """ white = all - black """ goal = n - 1 def dfs(nu...
s351313091
p03660
u652057333
1587297797
Python
PyPy3 (2.4.0)
py
Runtime Error
487
64048
984
import sys input = sys.stdin.buffer.readline n = int(input()) edges = [[] for _ in range(n)] for i in range(n-1): a, b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) nodes = [0 for _ in range(n)] """ white = all - black """ goal = n - 1 def dfs(num, f_num): if num == goal:...