submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s472515885 | p04048 | Runtime Error | def f(x, y):
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * x + f(x, y - x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... |
s034131434 | p04048 | Runtime Error | def f(a, b):
if a == 1 and b == 1:
return 1
r = min(a, b)
q = max(a, b)
return 2*r + f(r, q-r)
N, X = map(int, raw_input().split())
print N + f(X, N-X) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... |
s046359757 | p04048 | Runtime Error | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import functools
def gcd(a, b):
while b:
a, b = b, a % b
return a
@functools.lru_cache(maxsize = None)
def func(N, X):
g = gcd(N, X)
if g == 1:
if X > N // 2:
return func(N, N - X)
if N == 2:
return 3
... | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... |
s124680257 | p04048 | Runtime Error | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import functools
def gcd(a, b):
while b:
a, b = b, a % b
return a
@functools.lru_cache(maxsize = None)
def func(N, X):
g = gcd(N, X)
if g == 1:
if X > N // 2:
return func(N, N - X)
if N == 2:
return 3
if N ... | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... |
s412168424 | p04048 | Runtime Error | n, x = map(int, raw_input().split())
g = gcd(n, x)
n /= g
x /= g
print 3 * (n - 1) * g
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilatera... |
s501653297 | p04049 | Wrong Answer | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
from collections import defaultdict
n,k = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
u,v = map(int, input().split())
u -= 1
v -= 1
ns[u... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s188309836 | p04049 | Wrong Answer | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
from collections import defaultdict
n,k = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
u,v = map(int, input().split())
u -= 1
v -= 1
ns[u... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s335687967 | p04049 | Wrong Answer | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
from collections import defaultdict
n,k = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
u,v = map(int, input().split())
u -= 1
v -= 1
ns[u... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s106835136 | p04049 | Wrong Answer | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
from collections import defaultdict
n,k = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
u,v = map(int, input().split())
u -= 1
v -= 1
ns[u... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s021807684 | p04049 | Wrong Answer |
class tree_unit:
def __init__(self, name):
self.name = name
self.conn = []
def add_conn(self, vectex):
self.conn.append(vectex)
def search(self, vectex):
if vectex in self.conn:
conn = self.conn[:].remove(vectex)
return conn
else:
return []
def __repr__(self):
return ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s634224044 | p04049 | Wrong Answer |
class tree_unit:
def __init__(self, name):
self.name = name
self.conn = []
def add_conn(self, vectex):
self.conn.append(vectex)
def search(self, vectex):
if vectex in self.conn:
conn = self.conn[:].remove(vectex)
return conn
else:
return []
def __repr__(self):
return ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s904820298 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n-1)]
graph = [[] for i in range(n+1)]
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
ans = n
rad = k//2
for center in range(1,n+1):
stack = [center]
dep = [-1]*(n+1)
dep[center] = 0
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s662629062 | p04049 | Wrong Answer | n, k = map(int, input().split())
g = [[] for _ 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)
if k % 2 == 0:
ans = 100000
for i in range(n):
s = [i]
d = [-1] * n
d[i] = 0
while s:
p = s.po... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s379139258 | p04049 | Wrong Answer |
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc001/tasks/agc001_c
削除後のグラフが連結だから、葉の方から消していく必要がある
直径の一端となる頂点と、そこから伸びている辺を全探索?
距離がK以下の頂点の数の最大値が答え
1辺が高々2回選択されるので O(N**2)
"""
import sys
sys.setrecursionlimit(10 ** 5)
N,K = map(int,input().split())
lis = [ [] for i in range(N) ]
for i in range(N-1):
a,b = map... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s667913919 | p04049 | Wrong Answer | from collections import deque
n, k = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n - 1)]
tree = [[] for i in range(n)]
for a, b in info:
a -= 1
b -= 1
tree[a].append(b)
tree[b].append(a)
def solve(root):
visited = [-1] * n
visited[root] = 0
res = 0
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s338913473 | p04049 | Wrong Answer | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from collections import deque
n, k = map(int, input().split())
radius = k // 2
edge = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
a -= 1; b -= 1
edge[a].append(b)
edge[b].append(... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s180465134 | p04049 | Wrong Answer | from collections import deque
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = [int(i) for i in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
insides = 0
if k%2==0:
#各頂点始まり、で調べる
for i in range(n):
queue = deque([i])... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s153410330 | p04049 | Wrong Answer | from collections import deque
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = [int(i) for i in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
insides = 0
if k%2==0:
#各頂点始まり、で調べる
for i in range(n):
queue = deque([i])... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s793243789 | p04049 | Wrong Answer | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,default... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s147361873 | p04049 | Wrong Answer | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,default... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s039168990 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
from collections import deque
from bisect import insort_left
N,K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
A,B = map(int,input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
def MAXDIST(s):
dist = [None] * N
que = deque([s])
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s616478388 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
from collections import deque
N,K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
A,B = map(int,input().split())
G[A-1].append(B-1)
G[B-1].append(A-1)
def MAXDIST(s):
dist = [None] * N
que = deque([s])
dist[s] = 0
while que:
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s448409036 | p04049 | Wrong Answer | from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
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)
ans = 10 ** 9
for i in range(1, N + 1):
if len(edge[i]) > 1:
conti... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s694614494 | p04049 | Wrong Answer | from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
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)
ans = 10 ** 9
for i in range(1, N + 1):
if len(edge[i]) > 1:
conti... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s843226192 | p04049 | Wrong Answer | n, k = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
g[a - 1].append(b - 1)
g[b - 1].append(a - 1)
s = [0]
d = [-1] * n
d[0] = 0
while s:
p = s.pop()
for node in g[p]:
if d[node] == -1:
d[node] = d[p] + 1
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s551253934 | p04049 | Wrong Answer | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K = map(int,readline().split())
m = map(int,read().split())
AB = list(zip(m,m))
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
def F(a,b,K):
INF = 1... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s679832296 | p04049 | Wrong Answer | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K = map(int,readline().split())
m = map(int,read().split())
AB = list(zip(m,m))
graph = [[] for _ in range(N+1)]
for a,b in AB:
graph[a].append(b)
graph[b].append(a)
def F(a,b,K):
INF = 1... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s195321694 | p04049 | Wrong Answer | N,K=map(int,input().split())
L=[[]for i in range(N+1)]
l=[]
for i in range(N-1):
a,b=map(int,input().split())
L[a].append(b)
L[b].append(a)
l.append([a,b])
ans=N
if K%2==0:
for i in range(1,N+1):
C=[10000 for i in range(N+1)]
Q=[[i,0]]
cnt=1
for q in range(10000):
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s529364832 | p04049 | Wrong Answer | N,K=map(int,input().split())
L=[[]for i in range(N+1)]
l=[]
for i in range(N-1):
a,b=map(int,input().split())
L[a].append(b)
L[b].append(a)
l.append([a,b])
ans=N
if K%2==0:
for i in range(1,N+1):
C=[10000 for i in range(N+1)]
Q=[[i,0]]
cnt=1
for q in range(10000):
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s393365562 | p04049 | Wrong Answer | N,K=map(int,input().split())
L=[[]for i in range(N+1)]
l=[]
for i in range(N-1):
a,b=map(int,input().split())
L[a].append(b)
L[b].append(a)
l.append([a,b])
ans=N
if K%2==0:
for i in range(1,N+1):
C=[-1 for i in range(N+1)]
Q=[[i,0]]
cnt=1
for q in range(10000):
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s477994685 | p04049 | Wrong Answer | from collections import deque
n,k = [int(i) for i in input().split()]
edges = [[int(i)-1 for i in input().split()] for j in range(n-1)]
node = [[] for i in range(n)]
for edge in edges:
node[edge[0]].append(edge[1])
node[edge[1]].append(edge[0])
M = 0
for i in range(n):
count = 1
que = deque()
new... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s887378058 | p04049 | Wrong Answer | from collections import deque
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = [int(i) for i in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
insides = 0
if k%2==0:
#各頂点始まり、で調べる
for i in range(n):
queue = deque([i])... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s393503281 | p04049 | Wrong Answer | from collections import deque
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for _ in range(n-1):
a,b = [int(i) for i in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
insides = 0
if k%2==0:
#各頂点始まり、で調べる
for i in range(n):
queue = deque([i])... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s190170676 | p04049 | Wrong Answer | import sys
input=sys.stdin.readline
N,K=map(int,input().split())
L=[[]for i in range(N+1)]
for i in range(N-1):
a,b=map(int,input().split())
L[a].append((b,a))
L[b].append((a,b))
#print(L)
def dfs(S):
C=[10**5 for i in range(N+1)]
C[S]=0
A=L[S]
for i in range(10**5):
#print(A)
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s915240473 | p04049 | Wrong Answer | n, k = [ int(v) for v in input().split() ]
node_list = [ [ int(v)-1 for v in input().split() ] for i in range(n-1) ]
node_type = [ 0 for i in range(n) ]
connect_list = [ [] for i in range(n) ]
for i in node_list:
a, b = i
connect_list[a].append(b)
connect_list[b].append(a)
node_type[a] += 1
node_ty... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s837151529 | p04049 | Wrong Answer | from collections import deque
n, k = map(int, input().split())
graph = [[] for _ in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
ans = 2000
max_distance = k // 2
if k % 2 == 0:
for i in range(1, n+1):
extra_node_cnt = 0
q = de... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s990822550 | p04049 | Wrong Answer | from collections import deque
n, k = map(int, input().split())
graph = [[] for _ in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
ans = float("inf")
max_distance = k // 2 if k % 2 == 0 else (k - 1) // 2
for i in range(1, n+1):
extra_node_cnt = ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s549402182 | p04049 | Wrong Answer | from collections import defaultdict
def computeDist(tree, nk, i):
visited = [0] * (nk[0] + 1)
queue = []
visited[i] = 1
queue.append(i)
dist = [0] * (nk[0] + 1)
dist[i] = 0
while queue:
s = queue.pop(0)
for u in tree[s]:
if not visited[u]:
queue.a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s289434738 | p04049 | Wrong Answer | import collections
def dfs(v,d):
if len(g[v])==0:
return 0
for u in g[v]:
if checked[u]==0:
checked[u]=1
dfs(u,d+1)
print(v,d)
n,k=map(int,input().split())
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)
ans=0
for i in range(1,... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s519749834 | p04049 | Wrong Answer | import sys
n, k = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def bfs(start, nxt):
vis = [-1 for _ in range(n)]
vis[start] = 0
vis[nxt] = 1
s = [nxt]
cnt = 1
while s:
l = s.pop()
cnt += 1
if vis[l]... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s930363966 | p04049 | Wrong Answer | import sys
def input():
return sys.stdin.readline()[:-1]
n, k = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
adj[a-1].append(b-1)
adj[b-1].append(a-1)
def bfs(start, nxt):
vis = [-1 for _ in range(n)]
vis[start] = 0
vis[nxt] = 1
s = [nxt]
cnt = 1... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s421830919 | p04049 | Wrong Answer | n,k = map(int,input().split())
import numpy as np
edges = [[] for i in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
a = a-1
b = b-1
edges[a].append(b)
edges[b].append(a)
def dfs(v):
visited = []
INF = float("inf")
d=[INF for i in range(n)]
q=[]
d[v]=0
q.... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s639190332 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append((a-1,b-1))
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s868402522 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append((a-1,b-1))
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s479691259 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s185345023 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s054333374 | p04049 | Wrong Answer | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append((a-1,b-1))
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s010352281 | p04049 | Wrong Answer | import copy
N, K = (int(i) for i in input().split())
G = [[] for i in range(N)]
E = []
for i in range(N-1):
A, B = (int(i) for i in input().split())
E.append((A-1, B-1))
G[A-1].append(B-1)
G[B-1].append(A-1)
def DFS(u, n, G):
q = [u]
v = [0]*N
d = [0]*N
while q:
u1 = q.pop()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s784697261 | p04049 | Wrong Answer | import copy
N, K = (int(i) for i in input().split())
G = [[] for i in range(N)]
E = []
for i in range(N-1):
A, B = (int(i) for i in input().split())
E.append((A-1, B-1))
G[A-1].append(B-1)
G[B-1].append(A-1)
def DFS(u, n, G):
q = [u]
v = [0]*N
d = [0]*N
while q:
u1 = q.pop()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s490476127 | p04049 | Wrong Answer | import copy
N, K = (int(i) for i in input().split())
G = [[] for i in range(N)]
E = []
for i in range(N-1):
A, B = (int(i) for i in input().split())
E.append((A-1, B-1))
G[A-1].append(B-1)
G[B-1].append(A-1)
def DFS(u, n, G):
q = [u]
v = [0]*N
d = [0]*N
while q:
u1 = q.pop()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s556514942 | p04049 | Wrong Answer | import copy
N, K = (int(i) for i in input().split())
G = [[] for i in range(N)]
E = []
for i in range(N-1):
A, B = (int(i) for i in input().split())
E.append((A-1, B-1))
G[A-1].append(B-1)
G[B-1].append(A-1)
def DFS(u, n, G):
q = [u]
v = [0]*N
d = [0]*N
while q:
u1 = q.pop()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s564126239 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[-1]*N
h=deque()
h.append(i)
visit[i]=0
num=0
a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s134954120 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[-1]*N
h=deque()
h.append(i)
visit[i]=0
num=0
a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s258340653 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[-1]*N
h=deque()
h.append(i)
visit[i]=0
num=0
a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s256824678 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[-1]*N
h=deque()
h.append(i)
visit[i]=0
num=0
a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s355481257 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[-1]*N
h=deque()
h.append(i)
visit[i]=0
num=0
a... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s823410799 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[False]*N
h=deque()
h.append((i,0))
visit[i]=True
nu... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s465179850 | p04049 | Wrong Answer | from collections import deque
import math
N,K=map(int,input().split())
table=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
a,b=a-1,b-1
table[a].append(b)
table[b].append(a)
t=K//2
s=K%2
def dfs(i):
visit=[False]*N
h=deque()
h.append((i,0))
visit[i]=True
nu... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s994126800 | p04049 | Wrong Answer | from collections import deque
n,k = (int(i) for i in input().split())
b = [[int(i)-1 for i in input().split()] for i in range(n-1)]
x,d,ans = [[] for i in range(n)],[[] for i in range(n)],n
for i,j in b:
x[i].append(j)
x[j].append(i)
def f(s):
for i in range(n):
q,v = deque(),[1]*n
v[i] = 0
for j in x[i]:
q... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s824673259 | p04049 | Wrong Answer | import collections
N,K=map(int,input().strip().split())
AB=[]
for _ in range(N-1):
t=list(map(int,input().strip().split()))
AB.append(t)
AB.sort()
ten=[]
kaku=AB[0][0]
for i in range(N-1):
for x in range(N-1):
if i==x:
continue
if AB[i][0]==AB[x][0]:
ten.append(AB[x][... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s369333350 | p04049 | Wrong Answer | n, k = map(int, input().split())
import sys
sys.setrecursionlimit(2000)
l = [[] for i in range(n)]
e = []
for i in range(n-1):
a, b = map(int, input().split())
l[a-1].append(b-1)
l[b-1].append(a-1)
e.append([a-1, b-1])
def first_search(first, depth):
record = 0
for i in l[first]:
tem... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s513940538 | p04049 | Wrong Answer | n, k = map(int, input().split())
import sys
sys.setrecursionlimit(20000)
l = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
l[a-1].append(b-1)
l[b-1].append(a-1)
def first_search(first, depth):
record = 0
for i in l[first]:
temp = search(first, i, depth-1)
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s332847110 | p04049 | Wrong Answer | import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s975693189 | p04049 | Wrong Answer | import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s630090640 | p04049 | Wrong Answer | import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s002511452 | p04049 | Wrong Answer | import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s859370317 | p04049 | Wrong Answer | import numpy as np
N, K = map(int, input().split())
E = np.zeros((N, N), dtype=int)
# Elist = []
for e in range(N-1):
i, o = map(int, input().split())
# Elist.append((i-1, o-1))
E[i-1][o-1] = 1
E[o-1][i-1] = 1
# print("N, K=", N, K)
# for e in Elist:
# print(e[0], e[1])
I = np.eye(N, dtype=int)... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s679372832 | p04049 | Wrong Answer | import numpy as np
N, K = map(int, input().split())
E = np.zeros((N, N), dtype=int)
# Elist = []
for e in range(N-1):
i, o = map(int, input().split())
# Elist.append((i-1, o-1))
E[i-1][o-1] = 1
E[o-1][i-1] = 1
exit(0)
# print("N, K=", N, K)
# for e in Elist:
# print(e[0], e[1])
I = np.eye(N, dt... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s289833241 | p04049 | Wrong Answer | from collections import deque
N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
a, b = map(int, input().split())
a, b = a-1, b-1
T[a].append(b)
T[b].append(a)
E.append((a, b))
def dfs(n):
visited = [False] * N
stack = [[n, 0]]
longest = [-1, -1]
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s417381187 | p04049 | Wrong Answer | N, K = map(int, input().split())
E = [set() for i in range(N+1)]
for i in range(N-1):
a, b = map(int, input().split())
E[a].add(b)
E[b].add(a)
ma = 0
for i in range(1, N+1):
L = [i]
Closed = {i}
for j in range(K-1):
S = []
for l in L:
S += E[l]
L = []
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s206569825 | p04049 | Wrong Answer | import sys
sys.setrecursionlimit(5000)
def get_diamiter(v, parent, dep, edge):
max_dep, cnt, cnt_prev, ret_v = dep, 1, 0, v
for e in edge[v]:
if e != parent:
cand_dep, cand_cnt, cand_prev, cand_v = get_diamiter(e, v, dep + 1, edge)
if cand_dep > max_dep:
max_dep,... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s228672511 | p04049 | Wrong Answer | import sys
sys.setrecursionlimit(5000)
def get_diamiter(v, parent, dep, edge):
max_dep, cnt, cnt_prev, ret_v = dep, 1, 0, v
for e in edge[v]:
if e != parent:
cand_dep, cand_cnt, cand_prev, cand_v = get_diamiter(e, v, dep + 1, edge)
if cand_dep > max_dep:
max_dep,... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s739806406 | p04049 | Wrong Answer | import sys
sys.setrecursionlimit(5000)
def get_diamiter(v, parent, dep, edge):
max_dep, cnt, cnt_prev, ret_v = dep, 1, 0, v
for e in edge[v]:
if e != parent:
cand_dep, cand_cnt, cand_prev, cand_v = get_diamiter(e, v, dep + 1, edge)
if cand_dep > max_dep:
max_dep,... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s173862854 | p04049 | Wrong Answer | import sys
sys.setrecursionlimit(5000)
def get_diamiter(v, parent, dep, edge):
max_dep, cnt, ret_v = dep, 1, v
for e in edge[v]:
if e != parent:
cand_dep, cand_cnt, cand_v = get_diamiter(e, v, dep + 1, edge)
if cand_dep > max_dep:
max_dep, cnt, ret_v = cand_dep, ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s952720489 | p04049 | Wrong Answer | from collections import deque
N, K = map(int, input().split())
G = [[] for i in range(N)]
E = []
for i in range(N-1):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
E.append((a-1, b-1))
def bfs0(s):
que = deque()
prev = [-1]*N
prev[s] = s
que.append(s)
while ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s494568946 | p04049 | Wrong Answer | from collections import deque
N, K = map(int, input().split())
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)
def bfs0(s):
que = deque()
prev = [-1]*N
prev[s] = s
que.append(s)
while que:
v = que.popleft()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s900344007 | p04049 | Wrong Answer | from collections import deque
N, K = map(int, input().split())
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)
def bfs0(s):
que = deque()
prev = [-1]*N
prev[s] = s
que.append(s)
while que:
v = que.popleft()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s577183325 | p04049 | Wrong Answer | from collections import deque
N, K = map(int, input().split())
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)
def bfs0(s):
que = deque()
prev = [-1]*N
prev[s] = s
que.append(s)
while que:
v = que.popleft()
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s159843090 | p04049 | Wrong Answer | def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
[n,k]=i2()
e=[[] for i in range(n)]
for i in range(n-1):
[a,b]=i2()
e[a-1].append(b-1)
e[b-1].append(a-1)
import sys
sys.setrecursionlimit(10000)
def dfs(v,d):
global c
for i in range(len(e[v])):
if d[e[v][i]]==-1:
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s383083592 | p04049 | Wrong Answer | n,k = map(int,input().split())
branch = dict()
for i in range(1,n+1):
branch[i] = []
a = []
b = []
for i in range(n-1):
atemp,btemp = map(int,input().split())
branch[atemp].append(btemp)
branch[btemp].append(atemp)
a.append(atemp)
b.append(btemp)
if k%2 == 0:
ans = []
for i in range(1,n+1):
q = [i]
arrival... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s223471727 | p04049 | Wrong Answer | o=lambda:map(int,raw_input().split());r=range;a=10**5
n,k=o()
e=[[]for _ in [0]*n]
for _ in [0]*(n-1):a,b=o();e[a-1]+=[b-1];e[b-1]+=[a-1]
def U(x,f):
if f>=0:l[f]=1
q=[(x,0)]
while len(q):
v,c=q.pop(0)
if c>k/2:break
l[v]=1
for w in e[v]:
if not l[w]:q+=[(w,c+1)]
return n-l.count(1)
if k%2:
for i in r(n... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s990482530 | p04049 | Wrong Answer | o=lambda:map(int,raw_input().split());r=range;a=10**5
n,k=o()
e=[[]for _ in [0]*n]
for _ in [0]*(n-1):a,b=o();e[a-1]+=[b-1];e[b-1]+=[a-1]
def U(x,f):
l[f]=1;q=[(x,0)]
while len(q):
v,c=q.pop(0)
if c>k/2:break
l[v]=1
for w in e[v]:
if not l[w]:q+=[(w,c+1)]
return n-l.count(1)
if k%2:
for i in r(n):
for ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s421202969 | p04049 | Wrong Answer | o=lambda:map(int,raw_input().split());T,F=True,False;r=range;a=10**5
n,k=o()
e=[[]for _ in [0]*n]
for _ in [0]*(n-1):a,b=o();e[a-1]+=[b-1];e[b-1]+=[a-1]
def U(x,f):
l[f]=T;q=[(x,0)]
while len(q):
v,c=q.pop(0)
if c>k/2:break
l[v]=T
for w in e[v]:
if not l[w]:q+=[(w,c+1)]
return n-l.count(T)
if k%2:
for i ... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s650676455 | p04049 | Wrong Answer | import sys
sys.setrecursionlimit(10**6)
def dfs1(s,c,cnt):
visited[s]=1
for i in v[s]:
if visited[i]==0:
d[c][i]=d[c][s]+1
if k%2==0 and d[c][i]>k/2:
cnt+=1
if k%2==1 and d[c][i]>(k-1)/2:
cnt+=1
cnt=dfs1(i,c,cnt)
return... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s260898636 | p04049 | Wrong Answer | from sys import setrecursionlimit
setrecursionlimit(100000)
def rad_reach(b,h,dist,E,rad,ne):
cnt = 1
for nxt in E[h]:
if nxt == b or nxt == ne:
continue
if dist + 1 == rad:
cnt += 1
else:
cnt += rad_reach(h,nxt,dist+1,E,rad,ne)
return cnt
def solve():
N,K = map(int,raw_input().split())
pairs = []
... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s188344538 | p04049 | Wrong Answer | from sys import setrecursionlimit
setrecursionlimit(100000)
def rad_reach(b,h,dist,E,rad,ne):
cnt = 1
for nxt in E[h]:
if nxt == b or nxt == ne:
continue
if dist < rad:
cnt += rad_reach(h,nxt,dist+1,E,rad,ne)
else:
cnt += 1
return cnt
def solve():
N,K = map(int,raw_input().split())
pairs = []
E = [... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s291463450 | p04049 | Wrong Answer | # -*- coding: utf-8 -*-
N, K = map(int, input().split())
tree = [[] for _ in range(N)]
edges = []
for n in range(1, N):
a, b = map(int, input().split())
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
edges.append((a - 1, b - 1))
def dfs(i, now_v):
dias[i] = now_v
for next_node in tree[i]:... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s315362321 | p04049 | Wrong Answer | def main(le=len):
n, k = map(int, raw_input().split())
a = []
g = [[] for _ in xrange(n)]
for _ in xrange(n - 1):
u, v = map(int, raw_input().split())
u -= 1
v -= 1
a.append((u, v))
g[u].append(v)
g[v].append(u)
st = []
pu = st.append
po = st.p... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s255412320 | p04049 | Wrong Answer | # -*- coding: utf-8 -*-
N, K = map(int, input().split())
tree = [[0 for n in range(N)] for _ in range(N)]
disj = [0 for n in range(N)]
for n in range(1, N):
a, b = map(int, input().split())
tree[a - 1][b - 1] = 1
tree[b - 1][a - 1] = 1
disj[a - 1] += 1
disj[b - 1] += 1
dias = [-1 for _ in range(N)]... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s691034648 | p04049 | Wrong Answer | # -*- coding: utf-8 -*-
N, K = map(int, input().split())
tree = [[0 for n in range(N)] for _ in range(N)]
disj = [0 for n in range(N)]
for n in range(1, N):
a, b = map(int, input().split())
tree[a - 1][b - 1] = 1
tree[b - 1][a - 1] = 1
disj[a - 1] += 1
disj[b - 1] += 1
dias = [-1 for _ in range(N)]... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s654851725 | p04049 | Time Limit Exceeded | import sys
from collections import deque
def bfs(links, s, limit, bits):
not_reachable = (1 << len(links)) - 1
q = deque([(0, s, -1)])
while q:
cost, v, p = q.popleft()
if cost > limit:
break
not_reachable ^= bits[v]
cost += 1
q.extend((cost, u, v) for u... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s920254795 | p04049 | Time Limit Exceeded | import sys
from collections import deque
def bfs(links, s, limit):
not_reachable = (1 << len(links)) - 1
q = deque([(0, s, -1)])
while q:
cost, v, p = q.popleft()
if cost > limit:
break
not_reachable ^= 1 << v
cost += 1
q.extend((cost, u, v) for u in lin... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s829062897 | p04049 | Time Limit Exceeded | import sys
from collections import deque
def bfs(links, s, limit):
not_reachable = [True] * len(links)
q = deque([(0, s, -1)])
while q:
cost, v, p = q.popleft()
if cost > limit:
break
not_reachable[v] = False
cost += 1
q.extend((cost, u, v) for u in link... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s464997249 | p04049 | Time Limit Exceeded | import sys
from collections import deque, defaultdict
def bfs(links, s=0):
ans = [0] * len(links)
q = deque([(0, s, -1)])
while q:
cost, v, p = q.popleft()
ans[v] = cost
cost += 1
q.extend((cost, u, v) for u in links[v] if u != p)
return ans
def solve(n, k, ab):
i... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s355921971 | p04049 | Time Limit Exceeded | import sys
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
n, k, *ab = map(int, sys.stdin.buffer.read().split())
aaa = np.array(ab[0::2], dtype=np.int64) - 1
bbb = np.array(ab[1::2], dtype=np.int64) - 1
ccc = np.ones(n - 1, dtype=np.int64)
graph = csr_matrix((ccc,... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s805598937 | p04049 | Time Limit Exceeded | n,k = map(int, input().split())
link = [[] for _ in range(n)]
ln = []
for i in range(n-1):
a,b = list(map(int,input().split()))
link[a-1].append(b-1)
link[b-1].append(a-1)
ln.append([a-1,b-1])
if k==1:
print(n-2)
exit()
from collections import deque
def get_v(node,dist):
Q = deque()
Q.... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s516507320 | p04049 | Time Limit Exceeded | # tree diameter if (currDia <= k) true else shorten() while (dia >= k) O(n) dia readjust
# multiple pairs . centroid of tree --> on largest path find centroid --> maintain a heap ?
from queue import Queue
def main():
n, d = map(int, input().split())
adj = [[] for i in range(n)]
edges = []
for i i... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s004564469 | p04049 | Time Limit Exceeded | # tree diameter if (currDia <= k) true else shorten() while (dia >= k) O(n) dia readjust
# multiple pairs . centroid of tree --> on largest path find centroid --> maintain a heap ?
from queue import Queue
def main():
n, d = [int(x) for x in input().split(" ")]
adj = []
edges = []
for i in range(n... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s127743502 | p04049 | Time Limit Exceeded | import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
T = [[] for _ in range(n)]
E = []
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
T[a].append(b)
T[b].append(a)
E.append((a, b))
d = k//2
def dfs(vs):
dist = [-1]*n
stack =... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
s241648386 | p04049 | Time Limit Exceeded | import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
T = [[] for _ in range(n)]
E = []
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
T[a].append(b)
T[b].append(a)
E.append((a, b))
d = k//2
def dfs(vs):
dist = [-1]*n
stack =... | 6 2
1 2
3 2
4 2
1 6
5 6
| 2
| <span class="lang-en">
<p>Score : <var>600</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Given an undirected tree, let the distance between vertices <var>u</var> and <var>v</var> be the
number of edges on the simple path from <var>u</var> to <var>v</var>.
The diameter of a tree is the maxim... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.