submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s308118789
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...
s808680052
p04049
Time Limit Exceeded
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 = [] cnt = 0 for v in vs: stack.append(v) dist[v] = 0 while 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...
s644859872
p04049
Time Limit Exceeded
#!/usr/bin/env python3 import sys input = sys.stdin.readline from collections import deque n, k = map(int, input().split()) radius = k // 2 edge = [[] for _ in range(n)] uv = [] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1; b -= 1 edge[a].append(b) edge[b].append(a) uv.append((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...
s954425719
p04049
Time Limit Exceeded
import sys from collections import defaultdict as dd from collections import deque as dq input = sys.stdin.readline N, K = map(int, input().split()) e = dd(list) for _ in range(N - 1): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) d = [[N for _ in range(N + 1)] for _ in range(N + 1)] for s in ran...
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...
s423436289
p04049
Time Limit Exceeded
import sys from collections import defaultdict as dd from collections import deque as dq input = sys.stdin.readline N, K = map(int, input().split()) e = dd(list) for _ in range(N - 1): a, b = map(int, input().split()) e[a].append(b) e[b].append(a) d = [[N for _ in range(N + 1)] for _ in range(N + 1)] for s in ran...
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...
s590765428
p04049
Time Limit Exceeded
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 _ 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 = [] check = [False]*n if k%2==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...
s729496429
p04049
Time Limit Exceeded
import sys input = sys.stdin.readline 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 = [] ...
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...
s243620914
p04049
Time Limit Exceeded
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 = [] newque = [] check = [False for i in...
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...
s253510799
p04049
Time Limit Exceeded
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...
s440258571
p04049
Time Limit Exceeded
import collections n,k=map(int,input().split()) g=[[] for _ in range(n+1)] e=[] for _ in range(n-1): a,b=map(int,input().split()) g[a].append(b) g[b].append(a) e.append((a,b)) ans=0 if k%2==0: for i in range(1,n+1): tmp=0 checked=[0]*(n+1) checked[i]=1 q=collections.deque() q.append((i,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...
s754287392
p04049
Time Limit Exceeded
N, K = map(int, input().split()) # 横に2個 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) #print(graph) dis = [[] for _ in range(N)] for i in range(N): d = 0 checked = [False for _ in range(N)] checked[i] = True ...
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...
s582994160
p04049
Time Limit Exceeded
# coding:utf-8 import sys from collections import defaultdict, deque INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): re...
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...
s351572521
p04049
Time Limit Exceeded
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)) def f(x,y,c): global tmp c += 1 for e in edge[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...
s515788976
p04049
Time Limit Exceeded
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...
s334561614
p04049
Time Limit Exceeded
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...
s008057845
p04049
Time Limit Exceeded
import sys sys.setrecursionlimit(5000000) 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 ...
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...
s029596429
p04049
Time Limit Exceeded
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,c = [[] for i in range(n)],[[] for i in range(n)],n,0 for i,j in b: x[i].append(j) x[j].append(i) for i in x: c = max(len(i),c) if n-c+1<=k: ans = 0 elif k==1: ans = n-2 else: f...
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...
s991677900
p04049
Time Limit Exceeded
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...
s027490480
p04049
Time Limit Exceeded
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)],[[None]*n for i in range(n)],n for i,j in b: x[i].append(j) x[j].append(i) for i in range(n): q,v,d[i][i] = [],[1]*n,(0,-1) v[i] = 0 for j in x[i]: q.append((j,1,j)) d[i][j],v[...
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...
s696276840
p04049
Time Limit Exceeded
from bisect import bisect_left 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)],[[None]*n for i in range(n)],n for i,j in b: x[i].append(j) x[j].append(i) for i in range(n): q,v,d[i][i] = [],[1]*n,(0,-1) v[i] = 0 for j in x[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...
s289601341
p04049
Time Limit Exceeded
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...
s691147826
p04049
Time Limit Exceeded
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...
s265269213
p04049
Time Limit Exceeded
N,K=map(int,input().split()) G=[[] for i in range(N)] a=[0 for i in range(N-1)] b=[0 for i in range(N-1)] for i in range(N-1): a[i],b[i]=map(int,input().split()) a[i]-=1;b[i]-=1 G[a[i]].append(b[i]) G[b[i]].append(a[i]) P=[-1 for i in range(N)] rnk=[-1 for i in range(N)] q=[0] rnk[0]=0 while(len(q)>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...
s501876519
p04049
Time Limit Exceeded
N,K=map(int,input().split()) G=[[] for i in range(N)] a=[0 for i in range(N-1)] b=[0 for i in range(N-1)] for i in range(N-1): a[i],b[i]=map(int,input().split()) a[i]-=1;b[i]-=1 G[a[i]].append(b[i]) G[b[i]].append(a[i]) P=[-1 for i in range(N)] rnk=[-1 for i in range(N)] q=[0] rnk[0]=0 while(len(q)>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...
s860403732
p04049
Time Limit Exceeded
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 bfs(n): visited = [False] * N dist = [0] * N queue = deque([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...
s380088946
p04049
Time Limit Exceeded
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 bfs(n): visited = [False] * N dist = [0] * N queue = deque([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...
s723801958
p04049
Time Limit Exceeded
N, K = map(int, input().split()) E = [set() for i in range(N+1)] Er = [] for i in range(N-1): a, b = map(int, input().split()) E[a].add(b) E[b].add(a) Er.append({a, b}) ma = 0 Start = [] if K&1 == 1: Start = Er else: Start = [{i} for i in range(1, N+1)] for st in Start: L = list(st) Clos...
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...
s894233622
p04049
Time Limit Exceeded
import sys sys.setrecursionlimit(5000) def dfs(v, parent, rest, edge): ret = 0 for c in edge[v]: if c != parent: ret += dfs(c, v, rest - 1, edge) return ret + (rest <= 0) def main(N, K, edge): ans = N if K % 2 == 0: for v in range(N): ans = min(ans, sum(df...
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...
s199073669
p04049
Time Limit Exceeded
o=lambda:map(int,raw_input().split()) T,F=True,False 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] a=10**5 def dfs(x,f): if f>=0: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 ~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...
s144068762
p04049
Time Limit Exceeded
o=lambda:map(int,raw_input().split()) T,F=True,False n,k=o() e=[[] for _ in [0]*n] exec('a,b=o();e[a-1]+=[b-1];e[b-1]+=[a-1];'*(n-1)) a=10**5 def dfs(x,f): if f>=0: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 ~l[w]:q+=[(w,c+1)] return n-l.count(T) if k%2: for i in ...
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...
s888980912
p04049
Time Limit Exceeded
ii=lambda:map(int,raw_input().split()) n,k=ii() e=[[] for _ in range(n)] for _ in range(n-1): a,b=ii() e[a-1]+=[b-1];e[b-1]+=[a-1] cost=[0]*n ans=10**5 def dfs(x,f): if f>=0:vis[f]=True q=[(x,0)] while len(q): v,c=q.pop(0) if c>k/2:break cost[v]=c;vis[v]=True for w in...
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...
s305401795
p04049
Time Limit Exceeded
ii=lambda:map(int,raw_input().split()) n,k=ii() e=[[] for _ in range(n)] for _ in range(n-1): a,b=ii() e[a-1]+=[b-1];e[b-1]+=[a-1] cost=[0]*n ans=10**5 visit=[0] def dfs(x,f): global visit del visit[:] visit+=[f] q=[(x,0)] while len(q): v,c=q.pop(0);cost[v]=c;visit+=[v] for w...
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...
s057601498
p04049
Time Limit Exceeded
from sys import setrecursionlimit setrecursionlimit(100000) def rad_reach(b,h,dist,E,rad): cnt = 1 if dist < rad: for nxt in E[h]: if nxt == b: continue cnt += rad_reach(h,nxt,dist+1,E,rad) return cnt def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [[] for i in xrange(N)] for i in xra...
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...
s876381549
p04049
Time Limit Exceeded
import sys sys.setrecursionlimit(1000000) n, k = map(int,input().split()) d = [0] * n e = [[-1 for i in range(n)] for j in range(n)] def dfs(i): for j in e[i]: if j < 0: continue if d[j] < 0: d[j] = d[i] + 1 dfs(j) for i in range(n-1): a, b = map(int,input...
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...
s193167998
p04049
Time Limit Exceeded
from collections import deque import sys sys.setrecursionlimit(10**6) def bfs1(c): visited[c]=1 q=deque([c]) while len(q)>0: p=q.popleft() for i in v[p]: if visited[i]==0: q.append(i) visited[i]=1 d[c][i]=d[c][p]+1 def bfs2(c1,c2)...
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...
s670043003
p04049
Time Limit Exceeded
import sys sys.setrecursionlimit(10**6) def dfs1(s,c): visited[s]=1 for i in v[s]: if visited[i]==0: d[c][i]=d[c][s]+1 dfs1(i,c) return def dfs2(c1,c2): visited[c2]=1 dfs1(c1,c1) dfs1(c2,c2) return n,k=map(int,raw_input().split()) d=[[0]*n for _ in xrange(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...
s219266930
p04049
Time Limit Exceeded
#!/usr/bin/env pypy3 # 参考:https://agc001.contest.atcoder.jp/data/agc/001/editorial.pdf # 参考:http://yambe2002.hatenablog.com/entry/2016/07/17/050852 import sys REC_LIMIT = 10000 UNDEF = -1 def min_vertices_to_remove(n, k, adj_edges): def count_dfs(current, previous, distance): result = int(distance > k ...
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...
s823772579
p04049
Time Limit Exceeded
from sys import setrecursionlimit setrecursionlimit(100000) def rad_reach(bfr,h,dist,E,rad,ne): cnt = 1 if dist < rad: for nxt in E[h]: if nxt == bfr: continue cnt += rad_reach(h,nxt,dist+1,E,rad,ne) return cnt def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [set() for i in xrange(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...
s194132137
p04049
Time Limit Exceeded
#!/usr/bin/env pypy3 # 参考:http://yambe2002.hatenablog.com/entry/2016/07/17/050852 import sys REC_LIMIT = 10000 UNDEF = -1 def min_vertices_to_remove(n, k, adj_edges): def count_dfs(current, previous, distance): result = int(distance > k // 2) for next_vertex in adj_edges[current]: 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...
s916871810
p04049
Time Limit Exceeded
from sys import setrecursionlimit setrecursionlimit(100000) def rad_reach(b,h,dist,E,rad,ne): cnt = 1 if dist < rad: for nxt in E[h]: if nxt == b or nxt == ne: continue cnt += rad_reach(h,nxt,dist+1,E,rad,ne) return cnt def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [[] for i in xrang...
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...
s986115216
p04049
Time Limit Exceeded
def calc_dist(b,h,dist,E,D,ne): D[dist] += 1 for nxt in E[h]: if nxt == b or nxt == ne: continue calc_dist(h,nxt,dist+1,E,D,ne) def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [[] for i in xrange(N)] for i in xrange(N-1): a,b = map(lambda x:int(x)-1,raw_input().split()) E[a].append(b) ...
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...
s328238417
p04049
Time Limit Exceeded
# -*- coding: utf-8 -*- N, K = map(int, input().split()) tree = [[] for _ in range(N + 1)] for n in range(1, N): a, b = map(int, input().split()) tree[a].append(b) tree[b].append(a) def dfs(x, fa, d): if d > K: return 0 sz = 1 for v in tree[x]: if v != fa: sz += dfs...
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...
s514364551
p04049
Time Limit Exceeded
# -*- 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...
s067873792
p04049
Time Limit Exceeded
# -*- 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...
s463515946
p04049
Time Limit Exceeded
# -*- 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...
s931686518
p04049
Time Limit Exceeded
# -*- coding: utf-8 -*- N, K = map(int, input().split()) tree = [[0 for n in range(N)] for _ in range(N)] edges = [] for n in range(1, N): a, b = map(int, input().split()) tree[a - 1][b - 1] = 1 tree[b - 1][a - 1] = 1 edges.append((a - 1, b - 1)) dias = [-1 for _ in range(N)] def dfs(i, now_v): d...
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...
s448258594
p04049
Time Limit Exceeded
# -*- 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...
s436598609
p04049
Time Limit Exceeded
def main(): 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.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...
s191376932
p04049
Time Limit Exceeded
def main(): 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.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...
s277558352
p04049
Time Limit Exceeded
import numpy as np import matplotlib.pyplot as plt import pandas as pd from pandas import DataFrame n = raw_input() a = [int(i) for i in n.split()] list1 = [] sum = 0 arr = np.zeros([a[0]-1,3]) print arr for i in range(int(a[0]-1)): x = raw_input() list1.append(x) print list1
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...
s990130705
p04049
Accepted
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...
s600268083
p04049
Accepted
import sys import numpy as np 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()) G = [[] for _ in range(N + 1)] for a, b in zip(m, m): G[a].append(b) G[b].append(a) def dfs_order(G, root=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...
s222618469
p04049
Accepted
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,-1] for _ in range(n+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...
s159783548
p04049
Accepted
#参考コード #https://atcoder.jp/contests/agc001/submissions/4594416 from collections import defaultdict,deque N,K=map(int,input().split()) tree=[] Graph=defaultdict(list) for _ in range(N-1): edge=list(map(int,input().split())) Graph[edge[0]].append(edge[1]) Graph[edge[1]].append(edge[0]) tree.append(edge) 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...
s578647380
p04049
Accepted
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 for u in links[v]: ...
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...
s021652616
p04049
Accepted
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...
s004303402
p04049
Accepted
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...
s385319060
p04049
Accepted
# 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 collections import deque def main(): n, d = map(int, input().split()) adj = [[] for i in range(n)] edges = [] f...
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...
s607655075
p04049
Accepted
""" Writer: SPD_9X2 https://atcoder.jp/contests/agc001/tasks/agc001_c 今度こそ通すぞ!! 制約が小さいので、各頂点に関して最短距離探索するぐらいはできる 直径の中央で全探索する? →距離K//2以内の頂点の数を数え、残りを取り除けばよい →その点を通らない長さK以上のパスは存在しえない Kが偶数なら、1点を中心(深さ0)とし探索 Kが奇数なら、隣接する2点を深さ0とすればよい 計算量はO(N**2) """ from collections import deque N,K = map(int,input().split()) AB = [] li...
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...
s093002090
p04049
Accepted
#!/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)] uv = [] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1; b -= 1 edge[a].append(b) edge[b]...
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...
s936861287
p04049
Accepted
# #    ⋀_⋀  #   (・ω・) # ./ 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...
s491482207
p04049
Accepted
from collections import deque N, K, *AB = map(int, open(0).read().split()) E = [[] for _ in range(N + 1)] for a, b in zip(*[iter(AB)] * 2): E[a].append(b) E[b].append(a) def solve(a, b): D = [-1] * (N + 1) if a == b: Q = deque([a]) r = K // 2 D[a] = 0 else: 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...
s320802157
p04049
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque 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].appen...
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...
s879188984
p04049
Accepted
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=0 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...
s575011442
p04049
Accepted
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ sys.setrecursionlimit(10**9) n,k = map(int, input().split()) G = [[] for i in range(n)] edges = [] for i in range(n-1): a,b = map(int, input().split()) a,b = a-1,b-1 G[a].append(b) G[b].append(a) edges.append((a,b)) 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...
s988403881
p04049
Accepted
from collections import deque n, k = map(int, input().split()) graph = [[] for _ in range(n+1)] ab_list = [] for i in range(n-1): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) ab_list.append((a, b)) ans = 2000 max_distance = k // 2 if k % 2 == 0: for i in range(1, n+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...
s576764163
p04049
Accepted
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N,K = map(int,input().split()) AB = [[int(x) for x in input().split()] for _ in range(N-1)] graph = [[] for _ in range(N+1)] for a,b in AB: graph[a].append(b) graph[b].append(a) def count_nbd(x,R,parent): # parentを含まない部分木 # xを含む、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...
s718191855
p04049
Accepted
import collections n,k=map(int,input().split()) g=[[] for _ in range(n+1)] e=[] for _ in range(n-1): a,b=map(int,input().split()) g[a].append(b) g[b].append(a) e.append((a,b)) ans=0 if k%2==0: for i in range(1,n+1): tmp=0 checked=[0]*(n+1) checked[i]=1 q=collections.deque() q.append((i,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...
s782776092
p04049
Accepted
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, x): vis = [-1 for _ in range(n)] vis[start] = 0 s = [start] cnt = 0 while s: l = s.pop() cnt += 1 if vis[l] < x: for c in adj[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...
s951866574
p04049
Accepted
# coding:utf-8 import sys from collections import defaultdict, deque INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): re...
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...
s377776494
p04049
Accepted
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)) def f(x,y,c): global tmp c += 1 for e in edge[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...
s269572606
p04049
Accepted
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...
s589681725
p04049
Accepted
from collections import deque N,K=map(int,input().split()) node=[0]*N edge={} G=[[] for i in range(N)] for i in range(N-1): a,b=map(int,input().split()) edge[(a-1,b-1)]=0 G[a-1].append(b-1) G[b-1].append(a-1) if K%2: for a,b in edge.keys(): visited=[False]*N stack=deque([(a,0),(b,0)]) visited[a],v...
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...
s002964151
p04049
Accepted
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...
s397252240
p04049
Accepted
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,c = [[] for i in range(n)],[[] for i in range(n)],n,0 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]: ...
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...
s200992865
p04049
Accepted
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...
s754814119
p04049
Accepted
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...
s308954100
p04049
Accepted
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...
s067221399
p04049
Accepted
from collections import deque N,K = map(int,input().split()) es = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(N-1)] tr = [[] for i in range(N)] for a,b in es: tr[a].append(b) tr[b].append(a) def reachable_points(root_v, cant_visit_v): visited = [0] * N visited[root_v] = visited[cant_v...
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...
s023189898
p04049
Accepted
from collections import deque N,K = map(int,input().split()) es = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(N-1)] tr = [[] for i in range(N)] for i,(a,b) in enumerate(es): tr[a].append((b,i)) tr[b].append((a,i)) def reachable_points(root_v, cant_visit_v): visited = [0] * N visited[r...
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...
s508913083
p04049
Accepted
N,K=map(int,input().split()) G=[[] for i in range(N)] a=[0 for i in range(N-1)] b=[0 for i in range(N-1)] for i in range(N-1): a[i],b[i]=map(int,input().split()) a[i]-=1;b[i]-=1 G[a[i]].append(b[i]) G[b[i]].append(a[i]) d=[[-1 for i in range(N)] for j in range(N)] for i in range(N): q=[i] d[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...
s846800651
p04049
Accepted
from collections import deque INF = float('inf') N, K = map(int, input().split()) edges = [list(map(lambda x: int(x) - 1, input().split())) for e in range(N - 1)] adjL = [[] for v in range(N)] for a, b in edges: adjL[a].append(b) adjL[b].append(a) # 頂点の集合VCenterから距離radius以内にある頂点の数を求める def bfs(adjList, VCent...
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...
s176796857
p04049
Accepted
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 bfs(n): visited = [False] * N dist = [0] * N queue = deque([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...
s203445479
p04049
Accepted
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 bfs(n): visited = [False] * N dist = [0] * N queue = deque([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...
s271128839
p04049
Accepted
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...
s478477929
p04049
Accepted
# seishin.py 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(...
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...
s557163790
p04049
Accepted
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 gosa = 1.0 / 10**10 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def 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...
s841191279
p04049
Accepted
def dfs(now, d): visited[now] = True if d == k / 2 : return for nx in g[now]: if not visited[nx]: dfs(nx, d + 1) n, k = map(int, raw_input().split()) g = [[] for _ in xrange(n)] for i in xrange(n - 1): a, b = map(int, raw_input().split()) a -= 1; b -= 1; g[a].append(b) ...
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...
s529579515
p04049
Accepted
o=lambda:map(int,raw_input().split());s=9999 n,k=o();r=range(n) 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<n:l[f]=0 q=[(x,0)] while len(q): v,c=q.pop(0) if c>k/2:break l[v]=0 for w in e[v]: if l[w]:q+=[(w,c+1)] return n-l.count(0) if k%2: for i in r: f...
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...
s951208942
p04049
Accepted
o=lambda:map(int,raw_input().split());s=10**5 n,k=o();r=range(n) 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 ...
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...
s429413576
p04049
Accepted
o=lambda:map(int,raw_input().split()) T,F=True,False 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] a=10**5 def dfs(x,f): if f>=0: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: fo...
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...
s976551616
p04049
Accepted
ii=lambda:map(int,raw_input().split()) n,k=ii() T,F=True,False e=[[] for _ in range(n)] for _ in range(n-1): a,b=ii() e[a-1]+=[b-1];e[b-1]+=[a-1] cost=[0]*n ans=10**5 def dfs(x,f): if f>=0:vis[f]=T q=[(x,0)] while len(q): v,c=q.pop(0) if c>k/2:break cost[v]=c;vis[v]=T ...
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...
s232989972
p04049
Accepted
from collections import deque import sys sys.setrecursionlimit(10**6) def bfs1(c): visited[c]=1 q=deque([c]) while len(q)>0: p=q.popleft() for i in v[p]: if visited[i]==0: q.append(i) visited[i]=1 d[c][i]=d[c][p]+1 def bfs2(c1,c2)...
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...
s769783107
p04049
Accepted
from collections import deque def rad_reach(bfr,h,rest,E): cnt = 0 Q = deque([(bfr,h,rest)]) while Q: cnt += 1 bfr,h,rest = Q.popleft() if rest > 0: for nxt in E[h]: if nxt == bfr: continue Q.append((h,nxt,rest-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...
s477256091
p04049
Accepted
from sys import setrecursionlimit setrecursionlimit(1000000) def calc_dist(b,h,dist,E,D,ne): D[dist] += 1 for nxt in E[h]: if nxt == b or nxt == ne: continue calc_dist(h,nxt,dist+1,E,D,ne) def solve(): N,K = map(int,raw_input().split()) pairs = [] E = [[] for i in xrange(N)] for i in xrange(N-1): a,b =...
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...
s751658323
p04049
Accepted
from sys import stdin def main(le=len): n, k = map(int, raw_input().split()) a = [] g = [[] for _ in xrange(n)] dat = map(int, stdin.read().split(), [10] * 2 * (n - 1)) for i in xrange(n - 1): u, v = dat[i*2] - 1, dat[i*2+1] - 1 a.append((u, v)) g[u].append(v) g[v].ap...
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...
s240968537
p04049
Accepted
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...
s315910061
p04049
Runtime Error
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...
s994436547
p04049
Runtime Error
import sys from collections import deque def bfs(links, s, limit): not_reachable = (1 << len(links)) - 1 q = deque([(0, s, -1)]) pop = q.popleft extend = q.extend while q: cost, v, p = pop() if cost > limit: break not_reachable ^= 1 << v cost += 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...
s748681090
p04049
Runtime Error
import sys from collections import deque def bfs(links, s, limit): not_reachable = (1 << len(links)) - 1 q = deque([(0, s, -1)]) pop = q.popleft extend = q.extend while q: cost, v, p = pop() if cost > limit: break not_reachable ^= 1 << v cost += 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...