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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s547133075 | p03660 | u909304507 | 1500183570 | Python | Python (3.4.3) | py | Runtime Error | 2138 | 572088 | 2366 | # coding: utf-8
class Node:
def __init__(self, id):
self.id = id
self._connection = set()
def add_connection(self, node):
self._connection.add(node)
def get_connection(self):
return self._connection
def __repr__(self):
return str(self.id)
def get_ln_input... |
s488972428 | p03660 | u909304507 | 1500183091 | Python | Python (3.4.3) | py | Runtime Error | 2139 | 572104 | 2419 | # coding: utf-8
class Node:
def __init__(self, id):
self.id = id
self._connection = set()
def add_connection(self, node):
self._connection.add(node)
def get_connection(self):
return self._connection
def __repr__(self):
return str(self.id)
def get_ln_input... |
s668597651 | p03660 | u268210555 | 1500178587 | Python | Python (3.4.3) | py | Runtime Error | 718 | 111264 | 588 | import sys
sys.setrecursionlimit(sys.getrecursionlimit()*100)
n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
a = []
def f(i, p):
a.append(i)
if i == n:
return True
for j in g[i]:
if j != p:
... |
s802257498 | p03660 | u268210555 | 1500178471 | Python | Python (3.4.3) | py | Runtime Error | 504 | 22100 | 525 | n = int(input())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
a = []
def f(i, p):
a.append(i)
if i == n:
return True
for j in g[i]:
if j != p:
if f(j, i):
return True
a.pop()
f(1,0... |
s423265980 | p03660 | u314057689 | 1500173069 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 22724 | 1461 | def main():
N = int(input())
tree = [[] for i in range(N)]
for n in range(N-1):
a, b = map(lambda x: int(x)-1, input().split())
tree[a].append(b)
tree[b].append(a)
# print(np.array(tree))
Q = [(x, [0, x], 0) for x in tree[0]]
reached = [1] + [0]*(N-2) + [0]
while l... |
s147371691 | p03660 | u451610133 | 1500172748 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 125 | import random
def main():
sample_list = ['Fennec','Snuke']
random.shuffle(sample_list)
print sample_list[1] |
s552244841 | p03660 | u069170167 | 1500172637 | Python | Python (3.4.3) | py | Runtime Error | 307 | 16600 | 404 | N = int(input())
edge = [tuple(map(int,input().split())) for i in range(N-1)]
import networkx as nx
G = nx.Graph()
G.add_nodes_from(range(1,N))
G.add_edges_from(edge)
path = nx.shortest_path(G, 1, N)
pathlen = len(path)
G.remove_edges_from([(path[(pathlen)//2-1], path[(pathlen)//2])])
cut = [len(g) for g in nx.connect... |
s367933945 | p03660 | u451610133 | 1500172466 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 123 | import random
def main():
sample_list = ['Fennec','Snuke']
random.shuffle(sample_list)
print sample_list |
s346043785 | p03660 | u451610133 | 1500172373 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 110 | import random
def a():
sample_list = ['Fennec','Snuke']
random.shuffle(sample_list)
print sample_list
return 0 |
s510238292 | p03660 | u451610133 | 1500172321 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 102 | import random
def a:
sample_list = ['Fennec','Snuke']
random.shuffle(sample_list)
print sample_list |
s119958063 | p03660 | u451610133 | 1500172206 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 93 | import random
sample_list = ['Fennec','Snuke']
random.shuffle(sample_list)
print sample_list |
s722962318 | p03660 | u909304507 | 1500172025 | Python | Python (3.4.3) | py | Runtime Error | 1026 | 88148 | 2215 | # coding: utf-8
class Node:
def __init__(self, id):
self.id = id
self._connection = set()
def add_connection(self, node):
self._connection.add(node)
def get_connection(self):
return self._connection
def get_ln_inputs():
return input().split()
def get_ln_int_inpu... |
s223032794 | p03660 | u580225095 | 1500171842 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 479 | # -*- coding: utf-8 -*-
#勝者がフェネックならば Fennec と、すぬけくんならば Snuke と出力せよ。
import sys
N = int(input())
A = {}
for i in range(N):
B = input().split()
A.update({int(B[0]),int(B[1])})
X = A[1]
Y = A[N-1]
if Y == X:
print("Fennec")
sys.exit()
for i in range(N-1):
X = A[X]
if X == Y:
print("S... |
s032895261 | p03660 | u254456372 | 1500171698 | Python | Python (3.4.3) | py | Runtime Error | 621 | 124732 | 1462 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import re
import math
import collections
import itertools
import functools
DEBUG = True
DEBUG = False
def dbg(*args):
if DEBUG:
print("DBG: ", file=sys.stderr, end="")
print(*args, file=sys.stderr)
N = None
G = None
BLACK = 1
WHITE = 2
... |
s248566917 | p03660 | u883465106 | 1500169302 | Python | Python (3.4.3) | py | Runtime Error | 1007 | 71560 | 1262 | from collections import defaultdict
from collections import deque
import math
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N-1)]
d = defaultdict(list)
for a,b in AB:
d[a-1].append(b-1)
d[b-1].append(a-1)
def get_distance(start):
visited = set([start,])
distance = [99999999... |
s090297537 | p03661 | u993435350 | 1580287453 | Python | Python (3.4.3) | py | Runtime Error | 70 | 24948 | 214 | N = int(input())
A = list(map(int,input().split()))
P = []
S = sum(A)
snuke = 0
ans = 10 ** 9
for i in range(0,N - 1):
snuke += A[i]
ans = (S - 2 * snuke)
if ans >= dif:
ans = dif
print(ans)
|
s822635560 | p03661 | u368780724 | 1576172561 | Python | PyPy3 (2.4.0) | py | Runtime Error | 183 | 51824 | 538 | print('?', 10**10)
if input() == 'Y':
for nod in range(10):
print('?', 10**nod+1)
if input() == 'Y':
break
ans = 10**nod
else:
for nod in range(1, 10):
print('?', 10**nod)
if input() == 'Y':
continue
nod -= 1
break
ok = 10**(nod... |
s509805740 | p03661 | u785989355 | 1559891581 | Python | PyPy3 (2.4.0) | py | Runtime Error | 260 | 86092 | 1474 |
N=int(input())
e_list = [[] for i in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
a,b=a-1,b-1
e_list[a].append(b)
e_list[b].append(a)
vi = 0 #時と場合によってここを変える
from collections import deque
Q = deque([vi])
checked_list = [False for i in range(N)]
checked_list[vi]=True
prev_list = [-1... |
s378073995 | p03661 | u652081898 | 1551245432 | Python | Python (3.4.3) | py | Runtime Error | 72 | 23800 | 170 | n = int(input())
a = list(map(int, input().split()))
x = 0
y = sum(a)
ans = []
if i in range(n-1):
x += a[i]
y -= a[i]
ans.append(abs(x-y))
print(min(ans)) |
s698035042 | p03661 | u620868411 | 1535157520 | Python | Python (3.4.3) | py | Runtime Error | 146 | 26648 | 254 | # -*- coding: utf-8 -*-
n = int(input())
aa = [0]
s = 0
for x in input().split():
a = int(x)
aa.append(aa[-1]+a)
s += a
ret = abs(2*a[0]-s)
for i in range(1,n):
if abs(aa[i]-(s-aa[i]))<ret:
ret = abs(aa[i]-(s-aa[i]))
print(ret)
|
s219684942 | p03661 | u682985065 | 1522888299 | Python | Python (3.4.3) | py | Runtime Error | 78 | 34232 | 517 | n = int(input())
root = [[] for i in range(n+1)]
leaf = [0]*(n+1)
leaf[0] = -1
leaf[1] = 1
leaf[-1] = 2
for _ in range(n-1):
a, b = map(int, input().split())
root[a].append(b)
root[b].append(a)
turn = 1
while 0 in leaf:
for idx, i in enumerate(leaf):
if i == turn:
for t in root[idx... |
s122035163 | p03661 | u353919145 | 1514432398 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2696 | 1079 | def QSortPosition(list,low,high):
LsaveNum=list[low]
pivotkey=list[low]
while(low<high):
while(list[low]<pivotkey) :
low+=1
list[high]=list[low]
high-=1
while(list[high]>pivotkey):
high-=1
list[low]=list[high]
low+=1
list[low]=Lsave... |
s375563557 | p03661 | u018679195 | 1514432299 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 1078 | def QSortPosition(list,low,high):
LsaveNum=list[low]
pivotkey=list[low]
while(low<high):
while(list[low]<pivotkey) :
low+=1
list[high]=list[low]
high-=1
while(list[high]>pivotkey):
high-=1
list[low]=list[high]
low+=1
list[low]=Lsave... |
s671085246 | p03661 | u495415554 | 1511132293 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 449 | @profile
def main():
N = int(input())
a = list(map(int, input().split()))
#N = 1000
#a = [i for i in range(N)]
#summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]
summation = []
sumtemp = sum(a)
tmp1 = 0
for i in range(len(a)-1):
tmp1 += a[i]
... |
s008579393 | p03661 | u495415554 | 1511132173 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 449 | @profile
def main():
#N = int(input())
#a = list(map(int, input().split()))
N = 1000
a = [i for i in range(N)]
#summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]
summation = []
sumtemp = sum(a)
tmp1 = 0
for i in range(len(a)-1):
tmp1 += a[i]
... |
s190795610 | p03661 | u639444166 | 1501731016 | Python | Python (2.7.6) | py | Runtime Error | 179 | 34284 | 1441 | #!usr/bim/python
#! -*- coding: utf-8 -*-
n = raw_input()
n = int(n)
tree = []
i = 0
while i < n:
tree.append([])
i += 1
i = 0
while i < n-1:
ab = raw_input()
ab = ab.split()
ab = map(int,ab)
tree[ab[0]-1].append(ab[1])
tree[ab[1]-1].append(ab[0])
i += 1
black = [n]*n
white = [n]*n
... |
s144753721 | p03661 | u835482198 | 1500824689 | Python | Python (3.4.3) | py | Runtime Error | 64 | 19068 | 341 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
# http://arc078.contest.atcoder.jp/tasks/arc078_a
N = int(input())
a = map(int, input().split())
sum_num = sum(a)
current_sum = 0
min_diff = float('inf')
for i in range(0, N - 1):
current_sum += a[i]
min_diff = min(min_diff, abs(current_sum - (sum_num - current_su... |
s776649160 | p03661 | u257514933 | 1500430901 | Python | Python (2.7.6) | py | Runtime Error | 27 | 14104 | 1649 | import sys
def _rec(pos, n, edges, path, visited):
if pos in visited:
return None
visited.add(pos)
if pos == n:
return path
for to_node in edges[pos]:
if to_node in visited:
continue
path.append(to_node)
ret = _rec(to_node, n, edges, path, visited)
... |
s452042060 | p03661 | u552668967 | 1500253999 | Python | Python (2.7.6) | py | Runtime Error | 102 | 18416 | 175 | from sys import stdin
ma = 10**18
n = int(stdin.readline())
a = map(int,stdin.readline().split())
x = 0
s = sum(n)
for i in a[:-1]:
x+= i
ma = min(ma, abs(s-2*x) )
print ma |
s059310266 | p03661 | u552668967 | 1500253970 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2568 | 183 | from sys import stdin
ma = 10**18
n = int(stdin.readline().split())
a = map(int,stdin.readline().split())
x = 0
s = sum(n)
for i in a[:-1]:
x+= i
ma = min(ma, abs(s-2*x) )
print ma |
s390050224 | p03661 | u872191059 | 1500182020 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38640 | 742 | DEBUG = False
if DEBUG:
N = int(input())
def check(n):
print("? " + str(n), flush = True)
if DEBUG:
rtn = 'Y' if (n <= N) == (str(n) <= str(N)) else 'N'
print(rtn)
return rtn
else:
return input()
if check(10000000000) == 'Y':
for i in range(11, 0, -1):
n = 1... |
s404010053 | p03661 | u125337618 | 1500172243 | Python | Python (3.4.3) | py | Runtime Error | 74 | 24832 | 261 | N, nums = int(input()), list(map(int, input().split()))
total, ano = sum(nums), 0
for i in range(len(nums)-1):
total -= nums[i]
ano += nums[i]
if abs(ano-total) < last_dif or i == 0:
dif = abs(ano-total)
last_dif = dif
print(dif) |
s426146549 | p03661 | u125337618 | 1500172163 | Python | Python (3.4.3) | py | Runtime Error | 71 | 24832 | 253 | N, nums = int(input()), list(map(int, input().split()))
total, ano = sum(nums), 0
for i in range(len(nums)-1):
total -= nums[i]
ano += nums[i]
if abs(ano-total) < last_dif or i == 0:
dif, last_dif = abs(ano-total), dif
print(dif) |
s532938854 | p03661 | u125337618 | 1500169931 | Python | Python (3.4.3) | py | Runtime Error | 157 | 24824 | 277 | N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000
for i in range(len(nums)-1):
total -= nums[i]
ano += nums[i]
if abs(ano-total) < last_dif:
dif = abs(ano-total)
last_dif = dif
print(dif)
|
s795678715 | p03661 | u125337618 | 1500169921 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 279 | # N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000
for i in range(len(nums)-1):
total -= nums[i]
ano += nums[i]
if abs(ano-total) < last_dif:
dif = abs(ano-total)
last_dif = dif
print(dif)
|
s811869669 | p03661 | u272028993 | 1500169183 | Python | PyPy2 (5.6.0) | py | Runtime Error | 97 | 62876 | 995 | import sys
sys.setrecursionlimit(10**8)
def find_path(now, par):
if now == n - 1:
path.append(n - 1)
return True
for to in g[now]:
if to == par: continue
if find_path(to, now):
path.append(now)
return True
return False
def dfs(now, par, color):
c... |
s982263546 | p03661 | u764868186 | 1500167655 | Python | Python (3.4.3) | py | Runtime Error | 77 | 24832 | 215 | N = int(input())
As = [int(x) for x in input().split()]
S = sum(As)
print(S)
for i in range(1,N):
subs = sum(As[:i])
temp = abs(2 * subs - S)
if ans is None or temp < ans:
ans = temp
print(ans)
|
s543774627 | p03661 | u985443069 | 1500167138 | Python | Python (3.4.3) | py | Runtime Error | 166 | 23800 | 1030 | import sys
# sys.stdin = open('a1.in')
def read_int_list():
return list(map(int, input().split()))
import sys
# sys.stdin = open('a1.in')
def read_int_list():
return list(map(int, input().split()))
def read_int():
return int(input())
def read_str_list():
return input().split()
def read_str()... |
s417418135 | p03662 | u729133443 | 1598781666 | Python | Python (3.8.2) | py | Runtime Error | 1111 | 180796 | 163 | from networkx import*
N,*t=map(str.split,open(0))
s=shortest_path_length
x=s(G:=Graph(t),'1')
y=s(G,N)
print('FSennunkeec'[sum(x[k]>y[k]for k in x)*2>=int(*N)::2]) |
s016405339 | p03662 | u671861352 | 1589949335 | Python | Python (3.4.3) | py | Runtime Error | 731 | 65416 | 1007 | #!python3
class Node:
def __init__(self, num):
self.num = num
self.v = 1
self.parent = 0
self.deep = None
def LI():
return list(map(int, input().split()))
# input
N = int(input())
AB = [LI() for _ in range(N - 1)]
# link
link = [[] for _ in range(N + 1)]
for a, b in AB:
... |
s465130843 | p03662 | u671861352 | 1589949025 | Python | Python (3.4.3) | py | Runtime Error | 724 | 65416 | 1018 | #!python3
class Node:
def __init__(self, num):
self.num = num
self.v = 1
self.parent = None
self.deep = None
def LI():
return list(map(int, input().split()))
# input
N = int(input())
AB = [LI() for _ in range(N - 1)]
# link
link = [[] for _ in range(N + 1)]
for a, b in AB:
... |
s760853507 | p03662 | u655834330 | 1587212321 | Python | Python (3.4.3) | py | Runtime Error | 521 | 45020 | 1461 |
from collections import deque
def submit():
n = int(input())
edge = {i: [] for i in range(1, n + 1)}
for _ in range(n - 1):
a, b = map(int, input().split())
edge[a].append(b)
edge[b].append(a)
# 1とNの最短路を求める
def dfs(q, path, hist):
p = q.pop()
if p == n:
... |
s990883448 | p03662 | u919025034 | 1586277056 | Python | PyPy3 (2.4.0) | py | Runtime Error | 759 | 75168 | 1911 | N=int(input())
G=[[] for i in range(N)]
F=[0 for i in range(N)]
A=[]
for i in range(N-1):
a,b=map(int,input().split())
a-=1;b-=1
G[a].append(b)
G[b].append(a)
A.append([a,b])
def dfs(s,R):
F[s]=1
if s==N-1:
return [s]
else:
for n in G[s]:
if F[n]==0:
k=dfs(n,R)
if len... |
s385045827 | p03662 | u919025034 | 1586272958 | Python | PyPy3 (2.4.0) | py | Runtime Error | 740 | 75552 | 1909 | N=int(input())
G=[[] for i in range(N)]
F=[0 for i in range(N)]
A=[]
for i in range(N-1):
a,b=map(int,input().split())
a-=1;b-=1
G[a].append(b)
G[b].append(a)
A.append([a,b])
root=[]
def dfs(s):
flag=0
F[s]=1
if s!=N-1:
for n in G[s]:
if F[n]==0:
j=dfs(n)
if j==1:
... |
s419510907 | p03662 | u919025034 | 1586198447 | Python | PyPy3 (2.4.0) | py | Runtime Error | 716 | 61232 | 595 | N=int(input())
A=[0 for _ in range(N)]
G=[[] for i in range(N)]
F=[0 for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a-=1;b-=1
G[a].append(b)
G[b].append(a)
root=[]
def dp(s):
flag=0
F[s]=1
l=1
for n in G[s]:
if F[n]==0:
i,j=dp(n)
l+=i
if j==1:
flag=... |
s428127354 | p03662 | u223904637 | 1575737671 | Python | PyPy3 (2.4.0) | py | Runtime Error | 605 | 56656 | 716 | n=int(input())
g=[[] for i in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
a-=1
b-=1
g[a].append(b)
g[b].append(a)
q=[[0,[0]]]
v=[0]*n
v[0]=1
f=0
while True:
p=q.pop(0)
#if p[1][-1]==n-1:
#break
v[p[0]]=1
for i in g[p[0]]:
if v[i]==0:
v[i]=1... |
s868778104 | p03662 | u426108351 | 1571437248 | Python | Python (3.4.3) | py | Runtime Error | 216 | 22704 | 838 | import sys
input = sys.stdin.readline
N = int(input())
tree = [[] for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
tree[a].append(b)
tree[b].append(a)
dist_fennec = [100001] * (N+1)
dist_snuke = [100001] * (N+1)
q = [1]
dist[1] = 0
while q:
now = q.pop()
for next in tree[... |
s143478454 | p03662 | u865741247 | 1570244853 | Python | PyPy3 (2.4.0) | py | Runtime Error | 771 | 70360 | 731 |
import math
N = int(input())
graph = {}
SCORE = 0
def dfs(visted,v,depth):
visted[v] = depth
for next_v in graph[v]:
if visted[next_v] == -1 :
dfs(visted,next_v,depth + 1)
for _ in range(N-1):
a,b = map(int,input().split(" "))
if a not in graph:
graph[a] = [b]
else... |
s485788170 | p03662 | u980322611 | 1569344657 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2112 | 138656 | 1880 | class UnionFind:
def __init__(self, n):
self.par = [-1 for i in range(n+1)]
self.rank = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(... |
s739547366 | p03662 | u037430802 | 1567309118 | Python | Python (3.4.3) | py | Runtime Error | 540 | 24612 | 643 | N = int(input())
ab = [[] for _ in range(N)]
for i in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
ab[a].append(b)
ab[b].append(a)
dF = [0] * N
dS = [0] * N
def dfs(now, d, dlist, visited):
if visited[now] == False:
dlist[now] = d
visited[now] = True
fo... |
s604058727 | p03662 | u644778646 | 1563248646 | Python | Python (3.4.3) | py | Runtime Error | 539 | 26904 | 1154 | N = int(input())
e = [ [] for i in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
a-=1
b-=1
e[a].append(b)
e[b].append(a)
col = [ -1 for i in range(N)]
col[0] = 0
p = []
def dfs(n,c,path):
global p
path = path + [n]
if n == N - 1:
p = path
for v in e[n]:
... |
s172463373 | p03662 | u644778646 | 1563236114 | Python | PyPy3 (2.4.0) | py | Runtime Error | 758 | 67436 | 1226 | N = int(input())
e = [ [] for i in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
a-=1
b-=1
e[a].append(b)
e[b].append(a)
col = [ -1 for i in range(N)]
col[0] = 0
def dfs(n,c):
if not e[n]:
return
for v in e[n]:
if col[v] == -1:
col[v] = c + 1
... |
s843791679 | p03662 | u644778646 | 1563236010 | Python | PyPy3 (2.4.0) | py | Runtime Error | 727 | 66208 | 1123 | N = int(input())
e = [ [] for i in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
a-=1
b-=1
e[a].append(b)
e[b].append(a)
col = [ -1 for i in range(N)]
col[0] = 0
def dfs(n,c):
for v in e[n]:
if col[v] == -1:
col[v] = c + 1
dfs(v,c+1)
dfs(0,0)
... |
s914566062 | p03662 | u644778646 | 1563235391 | Python | PyPy3 (2.4.0) | py | Runtime Error | 728 | 66464 | 1081 | N = int(input())
e = [ [] for i in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
a-=1
b-=1
e[a].append(b)
e[b].append(a)
col = [ -1 for i in range(N)]
col[0] = 0
def dfs(n,c):
for v in e[n]:
if col[v] == -1:
col[v] = c + 1
dfs(v,c+1)
dfs(0,0)
... |
s627808671 | p03662 | u390694622 | 1555432468 | Python | Python (3.4.3) | py | Runtime Error | 503 | 23732 | 899 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
edges[a-1].append(b-1)
edges[b-1].append(a-1)
# visited = [False for _ in range(N)]
def dfs(start,stop,visitedArray):
visitedArray[start] = True
if start == stop:
return
else:
for ... |
s330530152 | p03662 | u390694622 | 1555431802 | Python | Python (3.4.3) | py | Runtime Error | 596 | 23524 | 862 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
edges[a-1].append(b-1)
edges[b-1].append(a-1)
visited = [False for _ in range(N)]
def dfs(start,stop):
visited[start] = True
if start == stop:
return
else:
for term in edges[start]... |
s938783666 | p03662 | u390694622 | 1555431617 | Python | Python (3.4.3) | py | Runtime Error | 521 | 23532 | 814 | N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
edges[a-1].append(b-1)
edges[b-1].append(a-1)
visited = [False for _ in range(N)]
def dfs(start,stop):
visited[start] = True
if start == stop:
return
else:
for term in edges[start]... |
s046573392 | p03662 | u657913472 | 1552542582 | Python | Python (3.4.3) | py | Runtime Error | 534 | 46772 | 205 | from scipy.sparse import*
f=lambda*z:list(map(int,input().split()))
n,=f()
c=[1]*~-n
print('FSennunkeec'[sum(g>h for g,h in zip(*csgraph.dijkstra(csr_matrix((c,zip(*map(f,c))),[n+1]*2),0,[1,n])))*2>=n::2]) |
s411811790 | p03662 | u572144347 | 1551450407 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 598 | N=int(input())
import sys
ab=[[int(j) for j in sys.stdin.readline()] for _ in range (N-1)]
con=[[] for _ in range(N+1)]
for a,b in ab :
con[a].append(b)
con[b].append(a)
#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
n,c=q.pop()
pc[n]=c
for ch in con[n]:
if vis[ch]==T... |
s265688022 | p03662 | u054106284 | 1549688524 | Python | Python (3.4.3) | py | Runtime Error | 565 | 23664 | 663 | N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
a, b = (int(i) for i in input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
prev = [-1]*N
dp = [0]*(N+1)
def DFS(start):
res = 0
for u in G[start]:
if u != prev[start]:
prev[u] = start
res += DFS(u)
... |
s061249445 | p03662 | u827202523 | 1547878014 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 28580 | 1015 | def getN():
return int(input())
def getMN():
a = input().split()
b = [int(i) for i in a]
return b[0],b[1]
def getlist():
a = input().split()
b = [int(i) for i in a]
return b
n = getN()
edge = [[] for i in range(n)]
for i in range(n-1):
a,b = getlist()
edge[a-1].append(b-1)
edg... |
s332819870 | p03662 | u657913472 | 1542826015 | Python | Python (3.4.3) | py | Runtime Error | 605 | 62600 | 213 | from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,zip(*map(f,[0]*~-n))),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2>=n::2]) |
s436078032 | p03662 | u657913472 | 1542825998 | Python | Python (3.4.3) | py | Runtime Error | 619 | 62596 | 212 | from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,zip(*map(f,[0]*~-n))),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2/n::2]) |
s888896898 | p03662 | u657913472 | 1542825897 | Python | Python (3.4.3) | py | Runtime Error | 1142 | 68188 | 222 | from scipy.sparse import*;f=lambda*z:map(int,input().split());n,=f();a,b=zip(*map(f,[0]*~-n));g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,(a,b)),[n+1]*2),0,[1,n]);print('FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2/n::2]) |
s588739250 | p03662 | u042105122 | 1542552177 | Python | Python (3.4.3) | py | Runtime Error | 757 | 112832 | 2228 | import sys
def main():
sys.setrecursionlimit(100001) # recursion limit hack
buf = input()
N = int(buf)
a = []
b = []
for i in range(N-1):
buf = input()
buflist = buf.split()
a.append(int(buflist[0]) - 1)
b.append(int(buflist[1]) - 1)
graph = []
for i in r... |
s974252873 | p03662 | u042105122 | 1542552042 | Python | Python (3.4.3) | py | Runtime Error | 420 | 23640 | 2160 |
def main():
buf = input()
N = int(buf)
a = []
b = []
for i in range(N-1):
buf = input()
buflist = buf.split()
a.append(int(buflist[0]) - 1)
b.append(int(buflist[1]) - 1)
graph = []
for i in range(N):
graph.append([])
for i in range(N-1):
g... |
s410410117 | p03662 | u620868411 | 1540067238 | Python | Python (3.4.3) | py | Runtime Error | 474 | 22976 | 684 | # -*- coding: utf-8 -*-
n = int(input())
edge = [[] for _ in range(n+1)]
for _ in range(n-1):
a,b = map(int, input().split())
edge[a].append(b)
edge[b].append(a)
inf = 10**5
def bfs(visited, s):
for e in edge[s]:
if visited[e]==inf:
visited[e] = visited[s]+1
bfs(visited... |
s619022601 | p03662 | u478870821 | 1535521684 | Python | PyPy3 (2.4.0) | py | Runtime Error | 726 | 62112 | 700 | from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
N = read()
edges = [[] for _ in range(N)]
for _ in range(N-1):
a, b = reads(... |
s047304112 | p03662 | u218843509 | 1535428477 | Python | PyPy3 (2.4.0) | py | Runtime Error | 162 | 38256 | 868 | from collections import deque
def bfs(start):
queue = deque([start])
visited = []
while queue:
label = queue.pop()
visited.append(label)
for v in d[label]:
if tekazu[v] == float("inf"):
tekazu[v] = tekazu[label] + 1
queue.appendleft(v)
... |
s365815617 | p03662 | u884982181 | 1534915708 | Python | Python (3.4.3) | py | Runtime Error | 958 | 53296 | 934 | n = int(input())
p = []
for i in range(n-1):
p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p:
l[pi[0]].append([pi[0],pi[1]])
l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
ruto.exte... |
s984182014 | p03662 | u884982181 | 1534914991 | Python | Python (3.4.3) | py | Runtime Error | 630 | 47052 | 950 | n = int(input())
p = []
for i in range(n-1):
p.append(list(map(int, input().split()))+ [1])
lw = [[] for i in range(n+1)]
for path in p:
lw[path[0]].append((path[1],path[2]))
lw[path[1]].append((path[0],path[2]))
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ru... |
s459124057 | p03662 | u692632484 | 1514067782 | Python | Python (3.4.3) | py | Runtime Error | 488 | 22964 | 494 | # -*- coding: utf-8 -*-
#import sys
N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(j)-1 for j in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
def paint(here,dist):
step[here]=dist
for to in edge[here]:... |
s070567766 | p03662 | u692632484 | 1514067395 | Python | Python (3.4.3) | py | Runtime Error | 476 | 22976 | 832 | # -*- coding: utf-8 -*-
#import sys
N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(j)-1 for j in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
def paint(here,dist):
step[here]=dist
for to in edge[here]:... |
s064825267 | p03662 | u692632484 | 1514067064 | Python | Python (3.4.3) | py | Runtime Error | 478 | 22972 | 830 | # -*- coding: utf-8 -*-
#import sys
N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(j)-1 for j in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
def paint(here,dist):
step[here]=dist
for to in edge[here]:... |
s953894746 | p03662 | u692632484 | 1514066880 | Python | Python (3.4.3) | py | Runtime Error | 492 | 22988 | 1813 | # -*- coding: utf-8 -*-
#import sys
N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(j)-1 for j in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
def paint(here,dist):
step[here]=dist
for to in edge[here]:... |
s393382813 | p03662 | u803848678 | 1513659654 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 4670 | #相手のパスを潰したい
# こちら側に来てほしくない場合,最短経路を潰すしか無い
# 最適を簡単に表せない A - B - C - D
# EF-| |-GH...
# のとき、A→EFとやっていると、Bを取られて死ぬ
# でもこれをいちいち計算できない
# 「相手のパスを潰す」、というのは、最短経路がより短いほうが勝つと考える?
# でも相手にパスが潰されるかどうかはわからない
# とりあえずやってみる
n = int(input())
INF = 10**6
graph = [[float("inf"... |
s016080396 | p03662 | u692632484 | 1512797474 | Python | Python (3.4.3) | py | Runtime Error | 500 | 23008 | 1462 | N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(i)-1 for i in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
step[0]=0
def paint(here,dist):
for to in edge[here]:
if step[to]>dist+1:
... |
s548153222 | p03662 | u692632484 | 1512796336 | Python | Python (3.4.3) | py | Runtime Error | 508 | 23004 | 1239 | N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
a,b=[int(i)-1 for i in input().split()]
edge[a].append(b)
edge[b].append(a)
#入力終了
step=[999999999 for i in range(N)]
step[0]=0
def paint(here,dist):
for to in edge[here]:
if step[to]>dist+1:
... |
s260805617 | p03662 | u639444166 | 1501768801 | Python | Python (2.7.6) | py | Runtime Error | 92 | 12544 | 2379 | #!usr/bim/python
#! -*- coding: utf-8 -*-
import numpy as np
n = raw_input()
n = int(n)
tree = np.zeros([n,n],dtype = np.uint8)
i = 0
while i < n-1:
ab = raw_input()
ab = ab.split()
ab = map(int,ab)
tree[ab[0]-1,ab[1]-1]=1
tree[ab[1]-1,ab[0]-1]=1
i += 1
black = np.tile([n],n)
white = np.til... |
s778934972 | p03662 | u639444166 | 1501767273 | Python | Python (2.7.6) | py | Runtime Error | 215 | 17132 | 1603 | #!usr/bim/python
#! -*- coding: utf-8 -*-
import numpy as np
n = raw_input()
n = int(n)
black_tree = np.zeros([n,n],dtype = np.uint8)
i = 0
while i < n-1:
ab = raw_input()
ab = ab.split()
ab = map(int,ab)
black_tree[ab[0]-1,ab[1]-1]=1
black_tree[ab[1]-1,ab[0]-1]=1
i += 1
black = np.tile([n]... |
s135795886 | p03662 | u639444166 | 1501767239 | Python | Python (2.7.6) | py | Runtime Error | 120 | 11884 | 1602 | #!usr/bim/python
#! -*- coding: utf-8 -*-
import numpy as np
n = raw_input()
n = int(n)
black_tree = np.zeros([n,n],dtype = np.uint8)
i = 0
while i < n-1:
ab = raw_input()
ab = ab.split()
ab = map(int,ab)
black_tree[ab[0]-1,ab[1]-1]=1
black_tree[ab[1]-1,ab[0]-1]=1
i += 1
black = np.tile([n]... |
s124144673 | p03662 | u299869545 | 1500676191 | Python | Python (2.7.6) | py | Runtime Error | 2105 | 24996 | 843 | n = input()
edge = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, raw_input().split())
a -= 1
b -= 1
edge[a] += [b]
edge[b] += [a]
path = []
color = [0] * n
def dfs(x, y, last = -1):
global path
path += [x]
if x == y:
return True
for to in edge[x]:
if to... |
s428341942 | p03662 | u391331433 | 1500436800 | Python | Python (2.7.6) | py | Runtime Error | 718 | 38932 | 3588 | import sys
from collections import deque
import copy
from math import *
def get_read_func(fileobject):
if fileobject == None :
return raw_input
else:
return fileobject.readline
class mas_node():
def __init__(self, now_number, pass_route):
self.now_number = now_number
self.p... |
s365538876 | p03662 | u257514933 | 1500431119 | Python | Python (2.7.6) | py | Runtime Error | 352 | 27704 | 1650 | import sys
def _rec(pos, n, edges, path, visited):
if pos in visited:
return None
visited.add(pos)
if pos == n:
return path
for to_node in edges[pos]:
if to_node in visited:
continue
path.append(to_node)
ret = _rec(to_node, n, edges, path, visited)
... |
s486884240 | p03662 | u257514933 | 1500431040 | Python | Python (2.7.6) | py | Runtime Error | 358 | 27704 | 1650 | import sys
def _rec(pos, n, edges, path, visited):
if pos in visited:
return None
visited.add(pos)
if pos == n:
return path
for to_node in edges[pos]:
if to_node in visited:
continue
path.append(to_node)
ret = _rec(to_node, n, edges, path, visited)
... |
s838883197 | p03662 | u257514933 | 1500430912 | Python | Python (2.7.6) | py | Runtime Error | 364 | 31672 | 1649 | import sys
def _rec(pos, n, edges, path, visited):
if pos in visited:
return None
visited.add(pos)
if pos == n:
return path
for to_node in edges[pos]:
if to_node in visited:
continue
path.append(to_node)
ret = _rec(to_node, n, edges, path, visited)
... |
s177958343 | p03662 | u391331433 | 1500350128 | Python | Python (2.7.6) | py | Runtime Error | 2105 | 32020 | 3547 | import sys
from collections import deque
import copy
from math import *
def get_read_func(fileobject):
if fileobject == None :
return raw_input
else:
return fileobject.readline
class mas_node():
def __init__(self, now_number, pass_route):
self.now_number = now_number
self.p... |
s820094889 | p03662 | u280667879 | 1500254960 | Python | Python (2.7.6) | py | Runtime Error | 357 | 28164 | 239 | from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());d=lambda s:csgraph.dijkstra(csr_matrix(([1]*n,(a,b)),[n+1]*2),0,s);n,=f();a,b=zip(*map(f,[0]*n));g=d(1);h=d(n);print['Snuke','Fennec'][sum(g[i]>h[i]for i in range(n+1))*2<n] |
s054603538 | p03662 | u280667879 | 1500254821 | Python | Python (2.7.6) | py | Runtime Error | 448 | 37732 | 241 | from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());d=lambda s:csgraph.dijkstra(csr_matrix(([1]*n,(a,b)),[n+1]*2),0,s);n,=f();a,b=zip(*map(f,[0]*~-n));g=d(1);h=d(n);print['Snuke','Fennec'][sum(g[i]>h[i]for i in range(n+1))*2<n] |
s433610357 | p03662 | u346308892 | 1500173735 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 82612 | 3261 |
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={}
self.nodes={}
def add_edge(self,edge,cost):
... |
s797668929 | p03662 | u346308892 | 1500172872 | Python | Python (3.4.3) | py | Runtime Error | 2109 | 82612 | 3261 | 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={}
self.nodes={}
def add_edge(self,edge,cost):
i... |
s045574343 | p03662 | u177481830 | 1500171916 | Python | Python (3.4.3) | py | Runtime Error | 745 | 32764 | 1028 | import numpy as np
import math
N=int(input())
nei_lst=[[] for _ in range(N+1)]
for i in range(N-1):
n, m=[int(_) for _ in input().split()]
nei_lst[n].append(m)
nei_lst[m].append(n)
visited_lst=[False for _ in range(N+1)]
visited_lst[1]=True
via_lst=[]#経由地記憶
stack=[1]#行ける場所
while True:
n=stack[-... |
s516246078 | p03662 | u346308892 | 1500171204 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 125336 | 2418 |
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={}
self.nodes={}
def add_edge(self,edge,cost):
... |
s884078759 | p03662 | u133038626 | 1500169832 | Python | Python (3.4.3) | py | Runtime Error | 552 | 40476 | 1282 | # coding: utf-8
import collections
class Graph(object):
def __init__(self, N):
self.N = N
self.paths = collections.defaultdict(set)
def path(self, n1, n2):
self.paths[n1].add(n2)
self.paths[n2].add(n1)
def dfs(self, n, f):
# fからNへの最短経路を探す
if n == self.N:
... |
s980849414 | p03662 | u765237551 | 1500169010 | Python | Python (3.4.3) | py | Runtime Error | 490 | 38428 | 823 | n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]
neighbors = [[] for _ in range(n)]
for x, y in xys:
neighbors[x-1].append(y-1)
neighbors[y-1].append(x-1)
froms = [-1 for _ in range(n)]
froms[0] = -2
def f(x):
for y in neighbors[x]:
if froms[y]==-1 :
fro... |
s227727651 | p03662 | u379305729 | 1500168306 | Python | Python (3.4.3) | py | Runtime Error | 572 | 32340 | 932 | def search(prev, start, stop):
global nodes, edges
for neigh in nodes[start]:
if neigh==prev:
continue
if neigh==stop:
return [stop,start]
res=search(start,neigh,stop)
if res!=False:
res.append(start)
return res
return False
de... |
s623546565 | p03662 | u541568482 | 1500168241 | Python | Python (3.4.3) | py | Runtime Error | 312 | 22232 | 835 | import sys
from collections import deque
cin = sys.stdin
# cin = open("in.txt", "r")
def line2N():
return map(int, cin.readline().split())
N, = line2N()
adj = [[] for i in range(N+1)]
for i in range(N-1):
u, v = line2N()
adj[u].append(v)
adj[v].append(u)
color = [0]*(N+1)
h_cnt = 1
t_cnt = 1
dq_hea... |
s729711060 | p03662 | u427222815 | 1500168175 | Python | Python (3.4.3) | py | Runtime Error | 16 | 2940 | 920 | #include<bits/stdc++.h>
using namespace std;
const int N = 200110;
int n, x, y, i, j, white, black, tot, cnt, last, k;
int a[N], nex[N], st[N], b[N], f[N], s[N], d[N], num[N];
bool g[N];
void add(int x, int y)
{
b[++tot] = y;
nex[tot] = st[x];
st[x] = tot;
}
void build(int x, int deep)
{
d[x] = deep;
g[x] = 1;
... |
s850475738 | p03665 | u896941378 | 1599335821 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9164 | 472 | import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if __name__ == '__main__':
N, P = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
if P == 0:
if i==1:
print(0)
quit()
for i in range(... |
s452806063 | p03665 | u006880673 | 1598669092 | Python | PyPy3 (7.3.0) | py | Runtime Error | 100 | 74628 | 1244 | from scipy.special import comb
N, P = map(int, input().split())
A = list(map(int, input().split()))
MAX_C = 100
# def comb_dp():
# """
# dpテーブルを作ってnCkを計算.
# modのpは素数でなくてよい.
# 1 <= k <= n <= 2000程度
# O(MAX_C ** 2).
# """
# Com = [[0]*MAX_C for _ in range(MAX_C)]
# for i in range(1, MAX_C... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.