message
stringlengths
2
49.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
446
108k
cluster
float64
13
13
__index_level_0__
int64
892
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,005
13
98,010
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` from heapq import * # import sys # input = sys.stdin.readline for _ in range(int(input())): n,s = map(int, input().split()) edges = [ list(map(int, input().split())) for _ in range(n-1)] dic = [[] for _ in range(n+1)] gress,cou...
output
1
49,005
13
98,011
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,006
13
98,012
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` from heapq import * import sys input = sys.stdin.readline for _ in range(int(input())): n,s = map(int, input().split()) edges = [ list(map(int, input().split())) for _ in range(n-1)] dic = [[] for _ in range(n+1)] gress,count,f...
output
1
49,006
13
98,013
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,007
13
98,014
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` import sys,bisect from collections import deque input=sys.stdin.buffer.readline t=1 t=int(input()) for _ in range(t): n,S=map(int,input().split()) edge=[[] for i in range(n)] for i in range(n-1): u,v,w,c=map(int,input().sp...
output
1
49,007
13
98,015
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,008
13
98,016
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.std...
output
1
49,008
13
98,017
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,009
13
98,018
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` from heapq import heappush, heappop from collections import deque mark = [0] * (200002) vw = [0] * (200002) # def dfs(s): # if vw[s]: # return 1 # c = 0 # for i in adj[s]: # if mark[i] == 0: # mark[i] = 1 # c += dfs(i) # vw[s] = ...
output
1
49,009
13
98,019
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree ...
instruction
0
49,010
13
98,020
Tags: data structures, dfs and similar, greedy, trees Correct Solution: ``` # Fast IO (only use in integer input) import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import heapq t = int(input()) for _ in range(t): n,s = map(int,input().split()) vertexScore = [] # number of leaves mot...
output
1
49,010
13
98,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,011
13
98,022
Yes
output
1
49,011
13
98,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,012
13
98,024
Yes
output
1
49,012
13
98,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,013
13
98,026
Yes
output
1
49,013
13
98,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,014
13
98,028
Yes
output
1
49,014
13
98,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,015
13
98,030
No
output
1
49,015
13
98,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,016
13
98,032
No
output
1
49,016
13
98,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,017
13
98,034
No
output
1
49,017
13
98,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a...
instruction
0
49,018
13
98,036
No
output
1
49,018
13
98,037
Provide tags and a correct Python 3 solution for this coding contest problem. There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The...
instruction
0
49,202
13
98,404
Tags: dfs and similar, dsu, shortest paths, trees Correct Solution: ``` # Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase def main(): n=int(input()) arr=[] for _ in range(n): arr.append(list(map(int,input()....
output
1
49,202
13
98,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original p...
instruction
0
49,203
13
98,406
No
output
1
49,203
13
98,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original p...
instruction
0
49,204
13
98,408
No
output
1
49,204
13
98,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original p...
instruction
0
49,205
13
98,410
No
output
1
49,205
13
98,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original p...
instruction
0
49,206
13
98,412
No
output
1
49,206
13
98,413
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To your surprise, Jamie is the final boss! Ehehehe. Jamie has given you a tree with n vertices, numbered from 1 to n. Initially, the root of the tree is the vertex with number 1. Also, each ver...
instruction
0
49,361
13
98,722
No
output
1
49,361
13
98,723
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. To your surprise, Jamie is the final boss! Ehehehe. Jamie has given you a tree with n vertices, numbered from 1 to n. Initially, the root of the tree is the vertex with number 1. Also, each ver...
instruction
0
49,362
13
98,724
No
output
1
49,362
13
98,725
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,461
13
98,922
"Correct Solution: ``` import sys sys.setrecursionlimit(1000000) input = sys.stdin.readline n,m = map(int,input().split()) e = [[] for i in range(n)] for i in range(m): a,b = map(int,input().split()) e[a-1].append(b-1) dis = [0]*n def dfs(x): num = 0 for nex in e[x]: if dis[nex] < 0: ...
output
1
49,461
13
98,923
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,462
13
98,924
"Correct Solution: ``` N,M=map(int,input().split()) graph=[[]for _ in range(N)] deg=[0]*N for i in range(M): xx,yy=map(int,input().split()) graph[xx-1].append(yy-1) deg[yy-1]+=1 que=[] dp=[0]*N for i in range(N): if deg[i]==0: que.append(i) while len(que)>0: k=que.pop(0) for x in graph...
output
1
49,462
13
98,925
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,463
13
98,926
"Correct Solution: ``` import sys sys.setrecursionlimit(10**9) n,m=map(int,input().split()) g=[[] for i in range(n)] for i in range(m): v1,v2=map(int,input().split()) v1-=1;v2-=1 g[v1].append(v2) dp=[-1]*n def dfs(i): if dp[i]!=-1: return dp[i] temp=0 for nv in g[i]: temp=max(temp,dfs(nv)+1)...
output
1
49,463
13
98,927
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,464
13
98,928
"Correct Solution: ``` import sys sys.setrecursionlimit(10**9) n,m = map(int,input().split()) graph = [[] for _ in range(n)] for i in range(m): x,y = map(int,input().split()) graph[x-1].append(y-1) dp = [-1]*(n) def dfs(i): if dp[i] != -1: return dp[i] else: res = 0 for j in graph[...
output
1
49,464
13
98,929
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,465
13
98,930
"Correct Solution: ``` import sys sys.setrecursionlimit(10 ** 9) def rec(n): if dp[n] != -1: return dp[n] else: max_n = 0 for i in graph[n]: max_n = max(max_n, rec(i)+1) dp[n] = max_n return dp[n] N, M = list(map(int, input().split())) dp = [-1]*N # nを始点としたときの最大値 graph = [[] for _ in...
output
1
49,465
13
98,931
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,466
13
98,932
"Correct Solution: ``` import sys from collections import defaultdict sys.setrecursionlimit(10 ** 5 + 100) def rec(v, dp, E): if dp[v] != -1: return dp[v] x = 0 for w in E[v]: x = max(x, rec(w, dp, E) + 1) dp[v] = x return x n, m = map(int, input().split()) E = defaultdict(list) f...
output
1
49,466
13
98,933
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,467
13
98,934
"Correct Solution: ``` import sys sys.setrecursionlimit(10**6) N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): x, y = map(int, input().split()) G[x-1].append(y-1) memo = [-1]*N def dfs(v): if memo[v] != -1: return memo[v] memo[v] = r = max(dfs(w) for w in G[v]) +...
output
1
49,467
13
98,935
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles. Find the length of the long...
instruction
0
49,468
13
98,936
"Correct Solution: ``` import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) N, M = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) G[a-1].append(b-1) dp = [-1]*N def dfs(n): global dp if dp[n] >= 0: return dp[n] ma = ...
output
1
49,468
13
98,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,469
13
98,938
Yes
output
1
49,469
13
98,939
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,470
13
98,940
Yes
output
1
49,470
13
98,941
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,471
13
98,942
Yes
output
1
49,471
13
98,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,472
13
98,944
Yes
output
1
49,472
13
98,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,473
13
98,946
No
output
1
49,473
13
98,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,474
13
98,948
No
output
1
49,474
13
98,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,475
13
98,950
No
output
1
49,475
13
98,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does n...
instruction
0
49,476
13
98,952
No
output
1
49,476
13
98,953
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,635
13
99,270
Tags: dfs and similar, interactive, trees Correct Solution: ``` from collections import deque import sys t = int(input()) for i in range(t): n = int(input()) edge = {} for j in range(1,n+1): a = set() edge[j] = a for k in range(n-1): a,b = map(int,input().split()) edge[a]...
output
1
49,635
13
99,271
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,636
13
99,272
Tags: dfs and similar, interactive, trees Correct Solution: ``` import sys from math import * from random import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() e = [[] for i in range(n+1)] p = [None]*(n+1) ...
output
1
49,636
13
99,273
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,637
13
99,274
Tags: dfs and similar, interactive, trees Correct Solution: ``` import sys from collections import deque t=int(sys.stdin.readline()) for i in range(t): n=int(sys.stdin.readline())#node EDGE=[list(map(int,sys.stdin.readline().split())) for i in range(n-1)] k1=int(sys.stdin.readline()) X=list(map(int...
output
1
49,637
13
99,275
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,638
13
99,276
Tags: dfs and similar, interactive, trees Correct Solution: ``` import sys def ask(u, t): if t == 0: print('A', u) else: print('B', u) sys.stdout.flush() return int(input()) def solve(): n = int(input()) e = [[] for _ in range(n + 1)] p = [0] * (n + 1) inA = [False] * (...
output
1
49,638
13
99,277
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,639
13
99,278
Tags: dfs and similar, interactive, trees Correct Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() ...
output
1
49,639
13
99,279
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,640
13
99,280
Tags: dfs and similar, interactive, trees Correct Solution: ``` from collections import defaultdict from math import log2 from bisect import bisect_left import os import sys from io import BytesIO, IOBase from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, f...
output
1
49,640
13
99,281
Provide tags and a correct Python 3 solution for this coding contest problem. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices from 1 to n. Neither of you know the other's lab...
instruction
0
49,641
13
99,282
Tags: dfs and similar, interactive, trees Correct Solution: ``` def add(child,path): copy=path[:] return(copy+[child]) def dfs(tree,start,end,path): if start==end: return path for child in tree[start]: if child in path: continue else: x=dfs(tree,child,end,...
output
1
49,641
13
99,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices f...
instruction
0
49,642
13
99,284
No
output
1
49,642
13
99,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices f...
instruction
0
49,643
13
99,286
No
output
1
49,643
13
99,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices f...
instruction
0
49,644
13
99,288
No
output
1
49,644
13
99,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are playing a strange game with Li Chen. You have a tree with n nodes drawn on a piece of paper. All nodes are unlabeled and distinguishable. Each of you independently labeled the vertices f...
instruction
0
49,645
13
99,290
No
output
1
49,645
13
99,291
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i. You are given m queries. The i-th query is given as an integer q_...
instruction
0
49,736
13
99,472
Tags: divide and conquer, dsu, graphs, sortings, trees Correct Solution: ``` import sys sys.setrecursionlimit(10**9) def find(a): if par[a]==a: return a par[a]=find(par[a]) return par[a] n,m=map(int,input().split()) ed=[] par=[i for i in range(n)] size=[1 for i in range(n)] for _ in range(n-1): ...
output
1
49,736
13
99,473
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a weighted tree consisting of n vertices. Recall that a tree is a connected graph without cycles. Vertices u_i and v_i are connected by an edge with weight w_i. You are given m queries. The i-th query is given as an integer q_...
instruction
0
49,737
13
99,474
Tags: divide and conquer, dsu, graphs, sortings, trees Correct Solution: ``` def find(u): if parent[u] == u: return u parent[u] = find(parent[u]) return parent[u] def union(a, b): u = parent[a] v = parent[b] p=size[u] q=size[v] if size[u] > size[v]: parent[v] = u ...
output
1
49,737
13
99,475