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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s930862632 | p03660 | u655834330 | 1587212207 | Python | Python (3.4.3) | py | Runtime Error | 553 | 45024 | 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:
... |
s388498961 | p03660 | u655834330 | 1587173508 | Python | Python (3.4.3) | py | Runtime Error | 494 | 31196 | 1316 |
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(path):
for e in edge[path[-1]]:
if e ... |
s979584373 | p03660 | u814986259 | 1586570150 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 661 | import collections
N = int(input())
G = [set() for i in range(N)]
for i in range(N-1):
a, b = map(int, input().split())
a -= 1
b -= 1
G[a].add(b)
G[b].add(a)
F = [-1]*N
F[0] = 0
q = collections.deque()
q.append(0)
while(q):
x = q.popleft()
for y in G[x]:
if F[y] < 0:
F... |
s360806777 | p03660 | u952467214 | 1586493230 | Python | Python (3.4.3) | py | Runtime Error | 489 | 36360 | 595 | n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
def dfs(v, parent, dist):
if dist[v] == -1:
dist[v] = dist[parent]+1
for next_v in es[v]:
if dist[next_v] == -1:
... |
s700263249 | p03660 | u952467214 | 1586493150 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 594 | n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
def dfs(v, parent, dist):
if dist[v] == -1:
dist[v] = dist[parent]+1
for next_v in es[v]:
if dist[next_v] == -1:
... |
s059419152 | p03660 | u952467214 | 1586493015 | Python | Python (3.4.3) | py | Runtime Error | 550 | 36364 | 586 | n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
def dfs(v, parent, dist):
if dist[v] == -1:
dist[v] = dist[parent]+1
for next_v in es[v]:
if dist[next_v] == -1:
... |
s538085548 | p03660 | u952467214 | 1586492657 | Python | Python (3.4.3) | py | Runtime Error | 543 | 36552 | 756 | n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
INF = 10**6
dist0 = [INF] * n
dist0[0] = 0
def dfs0(v, parent = -1):
if dist0[v] == INF:
dist0[v] = dist0[parent]+1
for next_v... |
s958791655 | p03660 | u952467214 | 1586492350 | Python | Python (3.4.3) | py | Runtime Error | 573 | 37332 | 795 | n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
INF = float('inf')
dist0 = [INF] * n
dist0[0] = 0
visited0 = [0]*n
def dfs0(v, parent = -1):
if dist0[v] == INF:
dist0[v] = dist0[p... |
s941025876 | p03660 | u935984175 | 1584973647 | Python | Python (3.4.3) | py | Runtime Error | 319 | 23928 | 979 | import sys
rl = sys.stdin.readline
def solve():
N = int(rl())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
a, b = map(lambda x: int(x) - 1, rl().split())
graph[a].append(b)
graph[b].append(a)
fen_dist, sun_dist = [0] * N, [0] * N
def dfs1(node, parent, di... |
s156974813 | p03660 | u561231954 | 1584828325 | Python | Python (3.4.3) | py | Runtime Error | 301 | 24756 | 1006 | import sys
input = sys.stdin.readline
INF = 10**20
MOD = 10**9 + 7
from itertools import permutations
def main():
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)
de... |
s632078698 | p03660 | u955251526 | 1584487529 | Python | Python (3.4.3) | py | Runtime Error | 887 | 144736 | 609 | import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
connect = [set() for _ in range(n)]
for a, b in edge:
connect[a-1].add(b-1)
connect[b-1].add(a-1)
d1 = [0] * n
dn = [0] * n
def dfs(v, ng, dis, d):
d[v] = dis
ng.add(v)
for n i... |
s690263566 | p03660 | u955251526 | 1584487324 | Python | Python (3.4.3) | py | Runtime Error | 873 | 144736 | 608 | import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
connect = [set() for _ in range(n)]
for a, b in edge:
connect[a-1].add(b-1)
connect[b-1].add(a-1)
d1 = [0] * n
dn = [0] * n
def dfs(v, ng, dis, d):
d[v] = dis
ng.add(v)
for n i... |
s761572198 | p03660 | u955251526 | 1584487273 | Python | Python (3.4.3) | py | Runtime Error | 661 | 55448 | 565 | n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
connect = [set() for _ in range(n)]
for a, b in edge:
connect[a-1].add(b-1)
connect[b-1].add(a-1)
d1 = [0] * n
dn = [0] * n
def dfs(v, ng, dis, d):
d[v] = dis
ng.add(v)
for n in connect[v]:
if n not in ng:
... |
s723627936 | p03660 | u237316771 | 1584295721 | Python | Python (3.4.3) | py | Runtime Error | 267 | 31376 | 1623 | #!/usr/bin/env python3
from collections import deque
import sys
try:
from typing import Deque, List
except ImportError:
pass
def dfs(G: "List[List[int]]", a: int, b: int, par: int = -1):
for t in G[a]:
if t == par:
continue
if t == b:
return [t]
path = dfs(G... |
s220011908 | p03660 | u798818115 | 1584071102 | Python | Python (3.4.3) | py | Runtime Error | 605 | 27616 | 1121 | # coding: utf-8
# Your code here!
def killme(num,lis):
visited[num]=1
if num==N-1:
lis.append(num)
for index,item in enumerate(lis):
highway[item]=index
else:
for next_n in way[num]:
if visited[next_n]==0:
killme(next_n,lis+[num])
return
... |
s267251509 | p03660 | u964299793 | 1583797835 | Python | Python (3.4.3) | py | Runtime Error | 515 | 23684 | 546 | n=int(input())
edges=[[] for _ in range(n)]
dist=[0]*n
for i in range(n-1):
u,v=map(int,input().split())
u-=1
v-=1
edges[u].append(v)
edges[v].append(u)
dist=[ [0]*n for _ in range(2)]
#do a dfs
def dfs(u,p,idd):#u=curr , p=par
for nei in edges[u]:
if nei==p:
continue
dist[idd][nei]=1+dist[idd... |
s614370696 | p03660 | u498487134 | 1583092086 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1123 | 73116 | 1311 | #!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import queue
def main():
mod=10**9+7
N=I()
adj=[[] for _ in range(N)]
for i in range(N-1):
a,b=MI()
a-=1
b-=1
adj[a].append(b)
... |
s057186162 | p03660 | u144913062 | 1582847078 | Python | PyPy3 (2.4.0) | py | Runtime Error | 806 | 105468 | 1538 | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, size):
self.parent = list(range(size))
self.rank = [0] * size
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self, ... |
s493139854 | p03660 | u561083515 | 1582411034 | Python | Python (3.4.3) | py | Runtime Error | 600 | 29336 | 777 | # https://atcoder.jp/contests/abc067/tasks/arc078_b
from collections import deque
N = int(input())
E = [[] for _ in range(N)]
for _ in range(N-1):
a,b = map(int,input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
def dist_from_X(X):
dist = [-1] * N
que = deque([X])
dist[X] = 0
whi... |
s801870250 | p03660 | u562935282 | 1579376180 | Python | Python (3.4.3) | py | Runtime Error | 464 | 35668 | 734 | def dfs(v, d):
for u in g[v]:
if d[u] != init:
continue
d[u] = d[v] + 1
dfs(u, d)
def main():
import sys
input = sys.stdin.readline
global g, init
n = int(input())
g = tuple(set() for _ in range(n))
for _ in range(n - 1):
a, b = (int(x) - 1 fo... |
s492633377 | p03660 | u754022296 | 1577463240 | Python | Python (3.4.3) | py | Runtime Error | 305 | 24948 | 839 | import sys
input = sys.stdin.readline
def main():
n = int(input())
F = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
F[a].append(b)
F[b].append(a)
seenB = [False]*n
seenW = [False]*n
seenB[n-1] = True
seenW[0] = True
def dfs(v, seen):
... |
s419256455 | p03660 | u754022296 | 1577463100 | Python | Python (3.4.3) | py | Runtime Error | 342 | 23836 | 794 | import sys
input = sys.stdin.readline
def main():
n = int(input())
F = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
F[a].append(b)
F[b].append(a)
seenB = [False]*n
seenW = [False]*n
seenB[n-1] = True
seenW[0] = True
def dfs(v, seen):
... |
s362084063 | p03660 | u754022296 | 1577462086 | Python | Python (3.4.3) | py | Runtime Error | 314 | 23840 | 762 | import sys
input = sys.stdin.readline
def main():
n = int(input())
F = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
F[a].append(b)
F[b].append(a)
seenB = [False]*n
seenW = [False]*n
seenB[n-1] = True
seenW[0] = True
def dfs(v, seen):
... |
s514713038 | p03660 | u945181840 | 1576511722 | Python | Python (3.4.3) | py | Runtime Error | 248 | 34520 | 472 | import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path
read = sys.stdin.read
N, *ab = map(int, read().split())
graph = csr_matrix(([1] * (N - 1), (ab[::2], ab[1::2])), shape=(N + 1, N + 1))
distance = shortest_path(graph, directed=False, indices=[1, N])
d1 = distance[0]
dn = dis... |
s994213779 | p03660 | u761989513 | 1576307548 | Python | Python (3.4.3) | py | Runtime Error | 606 | 26168 | 1376 | def dfs_f(now, kyori):
kyori_f[now] = kyori
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、白く塗られていない
if not memo_f[next] and next != n - 1:
memo_f[next] = True
dfs_f(next, kyori + 1)
def dfs_s(now, kyori):
kyori_s[now] = kyori
# 今いる頂点から行ける頂点を順に... |
s648797391 | p03660 | u761989513 | 1576296855 | Python | Python (3.4.3) | py | Runtime Error | 584 | 22952 | 1349 | def dfs_f(now):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、白く塗られていない
if not memo_f[next] and next != n - 1:
memo_f[next] = True
dfs_f(next)
def dfs_s(now):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、黒く塗られていない
... |
s453929948 | p03660 | u761989513 | 1576296130 | Python | Python (3.4.3) | py | Runtime Error | 514 | 22952 | 1038 | def dfs_f(now):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、白く塗られていない
if not memo_f[next] and next != n - 1:
memo_f[next] = True
dfs_f(next)
def dfs_s(now):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、黒く塗られていない
... |
s364837863 | p03660 | u761989513 | 1576295932 | Python | Python (3.4.3) | py | Runtime Error | 523 | 22948 | 1068 | def dfs_f(now, prev):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、白く塗られていない
if not memo_f[next] and next != n - 1:
memo_f[next] = True
dfs_f(next, now)
def dfs_s(now, prev):
# 今いる頂点から行ける頂点を順に next に入れてループ
for next in g[now]:
# 行ったことがない、白... |
s610911004 | p03660 | u190406011 | 1576009181 | Python | PyPy3 (2.4.0) | py | Runtime Error | 492 | 74852 | 1032 | import sys
n = int(input())
graph = {i : [] for i in range(n)}
for i in range(n-1):
a, b = [int(i) for i in sys.stdin.readline().split()]
a -= 1
b -= 1
graph[a].append(b)
graph[b].append(a)
stack = [0]
already = set()
parent = [i for i in range(n)]
flg = False
while len(stack) > 0:
cur = stack.... |
s300274172 | p03660 | u343454379 | 1574024697 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 26072 | 607 | N=int(input())
ab=[[] for _ in range(N)]
for _ in range(N-1):
a,b=map(int,input().split())
ab[a-1].append(b)
ab[b-1].append(a)
def dfs(p,pa):
global path
if p==N:
path=pa
else:
for i in ab[p-1]:
if i not in pa:
dfs(i,pa+[i])
dfs(1,[1])
def dfs2(p):
a=0
seen.append(p)
for i in... |
s662142842 | p03660 | u520276780 | 1573711622 | Python | PyPy3 (2.4.0) | py | Runtime Error | 701 | 63648 | 941 | #木
#お互いの始点を目指すのが最善
#import heapq
#heapじゃない
from collections import deque
n = int(input())
Ad = [[] for _ in range(n)]
for i in range(n-1):
ai,bi = map(int, input().split( ))
ai-=1
bi-=1
Ad[ai].append(bi)
Ad[bi].append(ai)
#0(元々は1)を根とする
P = [-1 for i in range(n)]
D = [-1 for i in range(n)]
Q = dequ... |
s810301625 | p03660 | u367130284 | 1572359650 | Python | PyPy3 (2.4.0) | py | Runtime Error | 304 | 55216 | 685 | from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
def BFS(point,d):
cost=[1e7]*(n+1)
cost[point]=0
Q=[]
Q.append_left((0,point))
while Q:
c,p=Q.pop()
for np in d[p]:
if cost[np]==1e7:
cost[np]=c+1
... |
s575398746 | p03660 | u367130284 | 1572359460 | Python | PyPy3 (2.4.0) | py | Runtime Error | 434 | 110300 | 686 | from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
def BFS(point,d):
cost=[1e7]*(n+1)
cost[point]=0
Q=[]
Q.appendleft((0,point))
while Q:
c,p=Q.pop()
for np in d[p]:
if cost[np]==1e7:
cost[np]=c+1
... |
s363979006 | p03660 | u367130284 | 1572309396 | Python | Python (3.4.3) | py | Runtime Error | 2109 | 68028 | 3089 | #高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
class UNION_FIND(object):
def __init__(self,n):
#親の番号を格納する。親だった場合は-(その集合のサイズ)
#作るときはParentの値を全て-1にする
#こうすると全てバラバラになる
self.parent=[-1]*(n+1)
def root(self,x):
... |
s042506031 | p03660 | u367130284 | 1572309144 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2109 | 104280 | 3085 | #高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
class UNION_FIND(object):
def __init__(self,n):
#親の番号を格納する。親だった場合は-(その集合のサイズ)
#作るときはParentの値を全て-1にする
#こうすると全てバラバラになる
self.parent=[-1]*(n+1)
def root(self,x):
... |
s874725731 | p03660 | u367130284 | 1572308951 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2109 | 104280 | 3085 | #高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
class UNION_FIND(object):
def __init__(self,n):
#親の番号を格納する。親だった場合は-(その集合のサイズ)
#作るときはParentの値を全て-1にする
#こうすると全てバラバラになる
self.parent=[-1]*(n+1)
def root(self,x):
... |
s069301530 | p03660 | u367130284 | 1572308254 | Python | Python (3.4.3) | py | Runtime Error | 2108 | 63404 | 3297 | #高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()
class UNION_FIND(object):
def __init__(self,n):
#親の番号を格納する。親だった場合は-(その集合のサイズ)
#作るときはParentの値を全て-1にする
#こうすると全てバラバラになる
self.parent=[-1]*(n+1)
def root(self,x):
... |
s201727017 | p03660 | u310678820 | 1569517034 | Python | Python (3.4.3) | py | Runtime Error | 480 | 26392 | 1000 | from collections import deque
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)
def dfs(route):
v0 = route[-1]
if v0 == 0:
for v in edges[0]:
if v == N-1:
return rout... |
s431350096 | p03660 | u037430802 | 1568921785 | Python | Python (3.4.3) | py | Runtime Error | 531 | 23724 | 1091 | N = int(input())
es = [[] for _ in range(N)]
for i in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
es[a].append(b)
es[b].append(a)
"""
相手の取れるマス目を減らすようにとるとよい
相手よりそのマスに近ければそのマスを取得できる
フェネックくん、すぬけ君について初期地点からそれぞれへの距離が必要
"""
def solve(now, depth, depth_list, es, visited):
visited[now] = Tr... |
s072607228 | p03660 | u414425367 | 1568754523 | Python | PyPy3 (2.4.0) | py | Runtime Error | 741 | 60524 | 675 | 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)
prevs=[0]*N
def dfs(prev,curr):
prevs[curr]=prev
if curr == N-1:
return
for c in edges[curr]:
if c!=prev:
dfs(curr,c)
dfs(-1,0)
... |
s505902746 | p03660 | u414425367 | 1568754426 | Python | PyPy3 (2.4.0) | py | Runtime Error | 626 | 55584 | 673 | N=int(input())
edges=[[] for _ in range(N)]
for _ in range(N):
A,B=map(int,input().split())
edges[A-1].append(B-1)
edges[B-1].append(A-1)
prevs=[0]*N
def dfs(prev,curr):
prevs[curr]=prev
if curr == N-1:
return
for c in edges[curr]:
if c!=prev:
dfs(curr,c)
dfs(-1,0)
pa... |
s522381644 | p03660 | u714378447 | 1567629689 | Python | Python (3.4.3) | py | Runtime Error | 571 | 23884 | 412 | import math
N=int(input())
G=[[] for i in range(N)]
for _ in range(N-1):
a,b=map(lambda x:int(x)-1,input().split())
G[a].append(b)
G[b].append(a)
depth=[[0]*N for i in range(2)]
def dfs(d, i, p, k=0):
for t in G[i]:
if t!=p:
depth[k][t]=d
dfs(d+1, t, i,k)
dfs(1,0,-1, 0)
dfs(1,N-1,-1, 1)
cnt=0
for... |
s208683220 | p03660 | u714378447 | 1567629017 | Python | Python (3.4.3) | py | Runtime Error | 488 | 24536 | 464 | import math
N=int(input())
G=[[] for i in range(N)]
for _ in range(N-1):
a,b=map(lambda x:int(x)-1,input().split())
G[a].append(b)
G[b].append(a)
seen=[False]*N
seen[0]=True
depth=[0]*N
sub_tree=[1]*N
ne=[0]
def dfs(d, i, p):
for t in G[i]:
if t!=p:
depth[t]=d
dfs(d+1, t, i)
sub_tree[i]+=sub_tr... |
s661467492 | p03660 | u077291787 | 1567267866 | Python | Python (3.4.3) | py | Runtime Error | 771 | 124524 | 739 | # ABC067D - Fennec VS. Snuke (ARC078D)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
def dfs(v: int, x: int, y: int) -> None:
D[y][v] = x
for u in G[v]:
if not D[y][u]:
dfs(u, x + 1, y)
def main():
global G, D
N = int(input())
E = tuple(tuple(map(int, ... |
s954835178 | p03660 | u677523557 | 1567112649 | Python | Python (3.4.3) | py | Runtime Error | 767 | 112052 | 1111 | import sys
sys.setrecursionlimit(100000)
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def dfs(p, checked, now):
#print(p, checked, now)
if p == N-1:
return now, True
ok = False
f... |
s919087501 | p03660 | u654470292 | 1567056367 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2158 | 820744 | 760 | import sys
sys.setrecursionlimit(20000)
def input():
return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
ki[ab[i][0]].append(ab[i][1])
ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[0,0] for i in range(n+... |
s040813049 | p03660 | u654470292 | 1567056052 | Python | PyPy3 (2.4.0) | py | Runtime Error | 503 | 83036 | 731 | import sys
def input():
return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
ki[ab[i][0]].append(ab[i][1])
ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[0,0] for i in range(n+1)]
def tansaku(m, dis, hito)... |
s289512214 | p03660 | u654470292 | 1567055909 | Python | PyPy3 (2.4.0) | py | Runtime Error | 501 | 83260 | 753 | import sys
def input():
return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
ki[ab[i][0]].append(ab[i][1])
ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[0,0] for i in range(n+1)]
def tansaku(m, dis, hito)... |
s527590088 | p03660 | u654470292 | 1566972096 | Python | PyPy3 (2.4.0) | py | Runtime Error | 608 | 92892 | 776 | import sys
def input():
return sys.stdin.readline()[:-1]
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
ki=[[] for i in range(n+1)]
for i in range(n-1):
ki[ab[i][0]].append(ab[i][1])
ki[ab[i][1]].append(ab[i][0])
# print(ki)
kyori=[[0,0] for i in range(n+1)]
def tansaku(m, dis, hito)... |
s593410500 | p03660 | u619819312 | 1566505764 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 795 | n=int(input())
s=[[]for i in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
s[a].append(b)
s[b].append(a)
def f(a,b):
c,flag,ans=[[a,[0,a]]],False,[]
while c or flag=False:
p,q=c.pop()
for i in s[p]:
if i==b:
ans=q[1:]+[b]
br... |
s045398434 | p03660 | u497596438 | 1560915825 | Python | PyPy3 (2.4.0) | py | Runtime Error | 625 | 55712 | 745 | N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
stack1=deque(G[0])
stack2=deque(G[N-1])
X=[-1]*N
X[0]=1
X[N-1]=0
while(stack1 or stack2):
Stack1=deque()
for i in stack1:
if X[i]==-1:
X[i]=1
... |
s770902010 | p03660 | u200785298 | 1560909434 | Python | Python (3.4.3) | py | Runtime Error | 277 | 31004 | 1708 | #!/usr/bin/env python3
import sys
def solve(N: int, a: "List[int]", b: "List[int]"):
conn = [[] for _ in range(N)]
for i in range(N - 1):
conn[a[i] - 1].append(b[i] - 1)
conn[b[i] - 1].append(a[i] - 1)
def find_path(idx, target, conn, visited):
visited[idx] = True
if idx ==... |
s726262250 | p03660 | u129836004 | 1559916844 | Python | Python (3.4.3) | py | Runtime Error | 448 | 22892 | 468 | 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)
dist1 = [0]*(N+1)
def func1(now, prv, d):
dist1[now] = d
for p in G[now]:
if p != prv:
func1(p, now, d+1)
func1(1, 0, 0)
fen = 0
sun = 0
d = dist1[N]
... |
s483109546 | p03660 | u102461423 | 1556915278 | Python | Python (3.4.3) | py | Runtime Error | 504 | 23692 | 602 | # 木グラフなので各プレイヤから近い点の個数を比べればよい
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)
INF = 10**18
d_fe = [INF]*N
d_sn = [INF]*N
d_fe[0] = 0
d_sn[-1] = 0
def f(d,x):
dx = d[x]
for v in edge[x]:
if d[v] == INF... |
s035111991 | p03660 | u041075929 | 1556496388 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 835 | // Created by sz
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, d1[N], dn[N];
vector<int> g[N];
void dfs(int u, int pre,int* d ){
for(auto i: g[u]){
if (i==pre)continue;
d[i] = d[pre] + 1;
dfs(i, u, d);
}
}
int main(){
#ifdef LOCAL
freopen("./in... |
s809314614 | p03660 | u052499405 | 1555220138 | Python | Python (3.4.3) | py | Runtime Error | 555 | 44192 | 969 | n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]
e = [[] for _ in range(n)]
for a, b in ab:
e[a-1].append(b-1)
e[b-1].append(a-1)
shortest = []
def get_path(start, end, par, path):
global shortest
if end in e[start]:
shortest = path + [end]
return sho... |
s230033547 | p03660 | u623819879 | 1554693250 | Python | PyPy3 (2.4.0) | py | Runtime Error | 923 | 96800 | 838 | from collections import deque
n=int(input())
a=[0]*(n+1)
b=[0]*(n+1)
g=[[] for _ in range(n+1)]
for i in range(1,n):
a[i],b[i]=map(int,input().split())
g[a[i]].append(b[i])
g[b[i]].append(a[i])
def bfs(x):
cnt=0
q=deque()
q.append(x)
vst=set()
while len(q)>0:
c=q.popleft()
... |
s482996761 | p03660 | u562935282 | 1553385587 | Python | Python (3.4.3) | py | Runtime Error | 584 | 30876 | 1747 | def dfs(v, d, path):
# 頂点(0, N - 1)間の最短距離を求める
# m_dist[v]:=頂点0からの最短距離
res = []
if m_dist[v] < float('inf'):
return
m_dist[v] = min(m_dist[v], d)
if v == N - 1:
return path
for nv in e[v]:
ret = dfs(nv, d + 1, path + [nv])
if ret:
res = ret
... |
s552289881 | p03660 | u352623442 | 1551558739 | Python | Python (3.4.3) | py | Runtime Error | 376 | 21168 | 530 | n = int(input())
a = [[] for i in range(n)]
for i in range(n):
x,y = map(int,input().split())
a[x-1].append(y-1)
a[y-1].append(x-1)
def dfs(v):
d = [-1 for i in range(n)]
q = []
d[v] = 0
q.append(v)
while len(q):
v = q.pop()
for i in a[v]:
if d[i] == -1:
... |
s762367872 | p03660 | u731028462 | 1543876521 | Python | Python (3.4.3) | py | Runtime Error | 546 | 28568 | 672 | from collections import defaultdict
N = int(input())
g = [[] for i in range(N)]
for i in range(N-1):
a,b = list(map(int,input().split()))
a,b = a-1,b-1
g[a] += [b]
g[b] += [a]
def bfs(g, st):
queue = [st]
distances = [-1 for i in range(N)]
distances[st] = 0
while queue:
... |
s862703213 | p03660 | u658993896 | 1543006200 | Python | Python (3.4.3) | py | Runtime Error | 610 | 31836 | 569 | def dps(road,dist,node,d):
for x in road[node]:
if dist[x]<0:
dist[x]=d
dps(road,dist,x,d+1)
N=int(input())
road=[[] for _ in range(N)]
f_d=[-1 for _ in range(N)]
s_d=[-1 for _ in range(N)]
f_d[0]=0
s_d[-1]=0
for i in range(N-1):
a,b=list(map(int,input().split()))
road[... |
s429130651 | p03660 | u658993896 | 1543003948 | Python | Python (3.4.3) | py | Runtime Error | 535 | 29172 | 880 | def sp(road,used,node,goal,path):
if node == goal:
return True
for x in road[node]:
if used[x]!=1:
used[x]=1
if sp(road,used,x,goal,path):
used[x]=2
path.append(x)
return True
def dps(road,used,node):
for x in road[node... |
s045345622 | p03660 | u658993896 | 1543001746 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 609 | road=[[] for _ in range(N)]
used=[0 for _ in range(N)]
for i in range(N-1):
a,b=list(map(int,input().split()))
road[a-1].append(b-1)
road[b-1].append(a-1)
start=0
for i in range(N):
if len(road[i])==1:
start=i
break
used[start]=1
f=0
s=0
for i in range(N):
if start == 0:
f... |
s565800132 | p03660 | u604896914 | 1541674951 | Python | Python (3.4.3) | py | Runtime Error | 637 | 42852 | 973 | import math,sys
sys.setrecursionlimit(1500)
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
f... |
s394502664 | p03660 | u604896914 | 1541674844 | Python | Python (3.4.3) | py | Runtime Error | 19 | 3064 | 950 | sys.setrecursionlimit(1500)
import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range... |
s846500310 | p03660 | u604896914 | 1541596660 | Python | Python (3.4.3) | py | Runtime Error | 611 | 42980 | 923 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s766762042 | p03660 | u604896914 | 1541595242 | Python | Python (3.4.3) | py | Runtime Error | 687 | 42852 | 922 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s189428753 | p03660 | u604896914 | 1541594997 | Python | Python (3.4.3) | py | Runtime Error | 732 | 42852 | 922 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s745874332 | p03660 | u604896914 | 1541594861 | Python | Python (3.4.3) | py | Runtime Error | 810 | 42852 | 923 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s508106955 | p03660 | u604896914 | 1541594805 | Python | Python (3.4.3) | py | Runtime Error | 614 | 42852 | 922 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s309264778 | p03660 | u604896914 | 1541594790 | Python | Python (3.4.3) | py | Runtime Error | 720 | 42852 | 922 | import math
def gcd(a,b):
"""Compute the greatest common divisor of a and b"""
while b > 0:
a, b = b, a % b
return a
def lcm(a, b):
"""Compute the lowest common multiple of a and b"""
return a * b / gcd(a, b)
N = int(input())
# Y,P,i
adj = {}
for i in range(N):
adj[i] = []
for i in... |
s972682293 | p03660 | u620084012 | 1538577248 | Python | Python (3.4.3) | py | Runtime Error | 848 | 118336 | 772 | # ABC 067 D
import sys
sys.setrecursionlimit(100000)
N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
a, b = map(int,input().split())
G[a].append(b)
G[b].append(a)
kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]
def dfs1(now, dist):
for tsugi in G[now]:
... |
s265193958 | p03660 | u620084012 | 1538576578 | Python | Python (3.4.3) | py | Runtime Error | 486 | 23784 | 730 | # ABC 067 D
N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
a, b = map(int,input().split())
G[a].append(b)
G[b].append(a)
kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]
def dfs1(now, dist):
for tsugi in G[now]:
if kyori1[tsugi] == 100000:
... |
s052773578 | p03660 | u270681687 | 1537961384 | Python | Python (3.4.3) | py | Runtime Error | 674 | 41380 | 1838 | from collections import deque
n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
parent = [-1 for i in range(n)]
dist = [-1 for i in range(n)]
flag = [0 for i in range(n)]
def dfs(s):
flag[s] = 1
dist[s] = 0
d... |
s206028312 | p03660 | u270681687 | 1537928525 | Python | Python (3.4.3) | py | Runtime Error | 381 | 21448 | 1760 | from collections import deque
n = int(input())
g = [[] for i in range(n)]
for i in range(n):
a, b = map(int, input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
parent = [-1 for i in range(n)]
dist = [-1 for i in range(n)]
flag = [0 for i in range(n)]
def dfs(s):
flag[s] = 0
dist[s] = 0
q =... |
s188658025 | p03660 | u884982181 | 1534912787 | Python | Python (3.4.3) | py | Runtime Error | 590 | 36320 | 1139 | n = int(input())
p = []
for i in range(n-1):
p.append(list(map(int, input().split())))
l = [[] for i in range(n+1)]
for pi in p:
l[pi[0]].append(pi[1])
l[pi[1]].append(pi[0])
memo = [0] * (n+1)
memo[1] = 1
mi = []
ruto = []
def dfs(start,end,ruto):
ruto.extend(l[start])
memo[start] = 1
while ruto:
... |
s110044119 | p03660 | u828847847 | 1534678578 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2696 | 683 | inf = float("inf")
dist1 = [inf for i in range(n)]
dist1[0] = 0
stk = []
for i in edge[0]:
stk.append([i,1])
while stk:
t,c = stk.pop()
if dist1[t] == inf :
dist1[t] = c
for i in edge[t]:
stk.append([i,c+1])
dist2 = [inf for i in range(n)]
dist2[n-1] = 0
for i in edge[n-1]:
... |
s047041720 | p03660 | u858136677 | 1534524156 | Python | Python (3.4.3) | py | Runtime Error | 1622 | 41548 | 1294 | def bfs(branch,n,start):
arrival = [0 for i in range(n+1)]
q = [start]
arrival[q[0]]=1
while len(q) >= 1:
for k in range(len(branch[q[0]])):
if arrival[branch[q[0]][k]] == 0:
arrival[branch[q[0]][k]] = arrival[q[0]] + 1
q.append(branch[q[0]][k])
... |
s529873614 | p03660 | u858136677 | 1534523416 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 41552 | 1585 | def bfs(branch,n,start):
arrival = [0 for i in range(n+1)]
q = [start]
arrival[q[0]]=1
while len(q) >= 1:
for k in range(len(branch[q[0]])):
if arrival[branch[q[0]][k]] == 0:
arrival[branch[q[0]][k]] = arrival[q[0]] + 1
q.append(branch[q[0]][k])
... |
s282322423 | p03660 | u824237520 | 1531507316 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 41672 | 1539 | n = int(input())
p = [ [] for _ in range(n) ]
for i in range(n - 1):
a, b = map(int, input().split())
p[a - 1].append(b - 1)
p[b - 1].append(a - 1)
f = [[0], []]
f[1] = [] + p[0]
if n - 1 in f[1]:
f[1].remove(n - 1)
if len(f[1]) == 0:
print("Snuke")
else:
print("Fennec")
ex... |
s278464711 | p03660 | u467736898 | 1529306751 | Python | Python (3.4.3) | py | Runtime Error | 445 | 22104 | 839 | N = int(input())
Node = [[] for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
Node[a].append(b)
Node[b].append(a)
Route = [1]
def dfs(n, np):
for nc in Node[n]:
if nc == np:
continue
elif nc == N:
Route.append(N)
return True
... |
s581077959 | p03660 | u062147869 | 1528832773 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3192 | 1400 | class Unionfindtree:
def __init__(self,number):
self.par = [i for i in range(number)]
self.rank = [0]*(number)
def find(self,x):#親を探す
if self.par[x] ==x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(sel... |
s070020108 | p03660 | u480847874 | 1526940723 | Python | Python (3.4.3) | py | Runtime Error | 774 | 140996 | 819 | import sys
sys.setrecursionlimit(100000)
def m():
def dfs(v, p, c, depth):
depth[v] = c
for child in graph[v]:
if child == p:
continue
dfs(child, v, depth[v]+1, depth)
n = int(input())
graph = [[] for _ in range(n + 1)]
depth_from1 = [0] * (n+1)
... |
s437625659 | p03660 | u480847874 | 1526940656 | Python | Python (3.4.3) | py | Runtime Error | 431 | 25484 | 781 | def m():
def dfs(v, p, c, depth):
depth[v] = c
for child in graph[v]:
if child == p:
continue
dfs(child, v, depth[v]+1, depth)
n = int(input())
graph = [[] for _ in range(n + 1)]
depth_from1 = [0] * (2*n+1)
depth_fromN = [0] * (2*n+1)
depth... |
s749637595 | p03660 | u480847874 | 1526940154 | Python | Python (3.4.3) | py | Runtime Error | 442 | 23928 | 777 | def m():
def dfs(v, p, c, depth):
depth[v] = c
for child in graph[v]:
if child == p:
continue
dfs(child, v, depth[v]+1, depth)
n = int(input())
graph = [[] for _ in range(n + 1)]
depth_from1 = [0] * (n+1)
depth_fromN = [0] * (n+1)
depth_fro... |
s603652652 | p03660 | u118642796 | 1526787300 | Python | Python (3.4.3) | py | Runtime Error | 447 | 22880 | 1409 | 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)
s = ["n"]*(N+1)
s[1] = "b"
s[N] = "w"
def DFS(v):
global s
for i in g[v]:
if s[i] == "w":
return
... |
s681943556 | p03660 | u353919145 | 1517633172 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 471 | #include <bits/stdc++.h>
using namespace std;
int n,a,b;vector<int> g[100005];int d1[100005],d2[100005];void dfs(int r,int f,int d,int dist[]){dist[r]=d;for(int x=0;x<g[r].size();x++)if(g[r][x]!=f)dfs(g[r][x],r,d+1,dist);}int main(){cin>>n;for(int i=0;i<n-1;i++){cin>>a>>b;a--,b--;g[a].push_back(b);g[b].push_back(a);}df... |
s515358231 | p03660 | u089230684 | 1517621766 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 763 | N=int(input())
G=[[] for i in range(N+1)]
for_in range(N-1):
a, b = inpl()
G[a].append(b)
G[b].append(a)
F=["" for i in range(N+1)]
S=["" for i in range(N+1)]
visited = [False for i in range(N+1)]
Q = deque([(1, 0)])
while len(Q):
m, d = Q.popleft()
if visited[m]:
continue
else:
... |
s969823195 | p03660 | u925364229 | 1515880796 | Python | Python (3.4.3) | py | Runtime Error | 474 | 40992 | 607 | N = int(input())
fen_count = 0
E = [dict() for _ in range(N+1)]
for i in range(N-1):
a,b = map(int,input().split(" "))
E[a][b] = 1
E[b][a] = 1
def dfs(ver,prev,rank):
global fen_count
flag = -1
fen_count += 1
for nextver in E[ver].keys():
if nextver == prev:
pass
elif nextver == N:
flag = rank
else:... |
s017709558 | p03660 | u925364229 | 1515880367 | Python | Python (3.4.3) | py | Runtime Error | 488 | 40992 | 606 | N = int(input())
fen_count = 0
E = [dict() for _ in range(N+1)]
for i in range(N-1):
a,b = map(int,input().split(" "))
E[a][b] = 1
E[b][a] = 1
def dfs(ver,prev,rank):
global fen_count
flag = -1
fen_count += 1
for nextver in E[ver].keys():
if nextver == prev:
continue
elif nextver == N:
flag = 1
else... |
s628302367 | p03660 | u425351967 | 1506613335 | Python | PyPy3 (2.4.0) | py | Runtime Error | 794 | 80544 | 468 | N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
a, b = [int(n)-1 for n in input().split()]
adj[a].append(b)
adj[b].append(a)
def dfs(now, cost, dic):
dic[now] = cost
for nx in adj[now]:
if nx not in dic:
dfs(nx, cost+1, dic)
dist_f = {}
dist_s = {}
dfs(0, 0, dist_f)
dfs(N-1, ... |
s972256064 | p03660 | u425351967 | 1506613296 | Python | Python (3.4.3) | py | Runtime Error | 632 | 39200 | 468 | N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
a, b = [int(n)-1 for n in input().split()]
adj[a].append(b)
adj[b].append(a)
def dfs(now, cost, dic):
dic[now] = cost
for nx in adj[now]:
if nx not in dic:
dfs(nx, cost+1, dic)
dist_f = {}
dist_s = {}
dfs(0, 0, dist_f)
dfs(N-1, ... |
s599767924 | p03660 | u425351967 | 1506613142 | Python | Python (3.4.3) | py | Runtime Error | 669 | 39072 | 469 | N = int(input())
adj = [[] for n in range(N)]
for i in range(N-1):
a, b = [int(n)-1 for n in input().split()]
adj[a].append(b)
adj[b].append(a)
def dfs(now, cost, dic):
dic[now] = cost
for nx in adj[now]:
if nx not in dic:
dfs(nx, cost+1, dic)
dist_f = {}
dist_s = {}
dfs(0, 0, dist_f)
dfs(N-1, ... |
s380980956 | p03660 | u160414758 | 1503973167 | Python | Python (3.4.3) | py | Runtime Error | 416 | 35688 | 636 | import sys
input = sys.stdin.readline
N = int(input())
tree = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int,input().split())
tree[a].append((b,1))
tree[b].append((a,1))
depth = [None]*(N+1)
def DFS(v,p,d):
depth[v] = d
for e in tree[v]:
if e[0] != p:
DFS(e[0], v,... |
s763239673 | p03660 | u362829196 | 1501169919 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 34264 | 870 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import copy
def calcDist(x, i_list, j, l):
if len(i_list) == 0:
return N
min = N
for i in i_list:
if i == j:
return l
if not i in chains:
chains[i] = []
i_list_c = copy.copy(chains[i])
if x in i_list_c:
i_list_c.remove(x)
m = calcDist(i,... |
s182076551 | p03660 | u362829196 | 1501169790 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 34268 | 830 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import copy
def calcDist(x, i_list, j, l):
if len(i_list) == 0:
return N
min = N
for i in i_list:
if i == j:
return l
i_list_c = copy.copy(chains[i])
if x in i_list_c:
i_list_c.remove(x)
m = calcDist(i, i_list_c, j, l + 1)
if min > m:
mi... |
s274627479 | p03660 | u362829196 | 1501169571 | Python | Python (3.4.3) | py | Runtime Error | 2105 | 34268 | 883 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import copy
def calcDist(x, i_list, j, l):
if len(i_list) == 0:
return N
min = N
for i in i_list:
if i == j:
return l
i_list_c = copy.copy(chains[i])
if x in i_list_c:
i_list_c.remove(x)
m = calcDist(i, i_list_c, j, l + 1)
if min > m:
mi... |
s182775661 | p03660 | u735154525 | 1500241679 | Python | Python (2.7.6) | py | Runtime Error | 2105 | 25592 | 2125 | # -*- coding: utf-8 -*-
import copy
def l_search(land, op):
tmp = []
for i in range(len(land[0]) - 1):
print land[0][i], op
if land[0][i] == op:
tmp.append(i)
print tmp
return tmp
def nxt_l(road, land):
tmp = []
for i in range(len(road)):
for j in ... |
s351978204 | p03660 | u565009467 | 1500222283 | Python | Python (2.7.6) | py | Runtime Error | 470 | 34316 | 842 | n=input()
graph=[[] for i in range(n+1)]
for i in range(n-1):
v,u=list(map(int,raw_input().split()))
graph[v].append(u)
graph[u].append(v)
dist= [-1 for i in range(n+1)]
dist[1]=0
son=[[] for i in range(n+1)]
queue=[1]
father=[0 for i in range(n+1)]
def bfs(u):
for v in graph[u]:
if dist[v]==-1... |
s966448129 | p03660 | u846372029 | 1500195996 | Python | Python (3.4.3) | py | Runtime Error | 576 | 42044 | 1089 | # Fennec VS. Snuke
N = int(input())
p = []
for i in range(N-1):
pi = list(map(int, input().split()))
p.append(pi)
#隣接リスト
l = [[] for i in range(N)]
for pi in p: #0-originedに注意
l[pi[0]-1].append(pi[1]-1)
l[pi[1]-1].append(pi[0]-1)
path = []
def short(N,i, p=1): #1とNの間の最短経路を探索
path.append(i)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.