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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to ...
instruction
0
105,303
13
210,606
No
output
1
105,303
13
210,607
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to ...
instruction
0
105,304
13
210,608
No
output
1
105,304
13
210,609
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,403
13
210,806
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` import sys n, *ab = map(int, sys.stdin.read().split()) graph = [[] for _ in range(n)] for a, b in zip(*[iter(ab)] * 2): a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) def main(): rank = [None] * n; rank[...
output
1
105,403
13
210,807
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,404
13
210,808
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` import sys import math from collections import deque def solve(): #f = open("b.txt") f = sys.stdin n = int(f.readline()) edges = [[] for i in range(n)] for i in range(n - 1): s = f.readline...
output
1
105,404
13
210,809
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,405
13
210,810
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` I=lambda:list(map(int,input().split())) n,=I() g=[[] for i in range(n+1)] for i in range(n-1): x,y=I() g[x].append(y) g[y].append(x) leaf=[] for i in range(1,n+1): if len(g[i])==1: leaf.append(i) ...
output
1
105,405
13
210,811
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,406
13
210,812
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` import collections,sys n = int(sys.stdin.readline()) g = [] sys.setrecursionlimit(2**20) for i in range(n+1): g.append([]) for i in range(n-1): a,b = list(map(int,sys.stdin.readline().split(' '))) g[a].appe...
output
1
105,406
13
210,813
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,407
13
210,814
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` from sys import stdin from collections import deque input=stdin.readline n=int(input()) graph=[set() for i in range(n+1)] visited2=[False]*(n+2) for i in range(n - 1): a,b=map(int,input().split()) graph[a].add(b...
output
1
105,407
13
210,815
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,408
13
210,816
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` import io, os, collections input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) nb = [[] for _ in range(n)] for i in range(n-1): u, v = [int(s)-1 for s in input().split()] nb[u].append(...
output
1
105,408
13
210,817
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,409
13
210,818
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` # -*- coding: utf-8 -*- import sys from collections import defaultdict # sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list...
output
1
105,409
13
210,819
Provide tags and a correct Python 3 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,410
13
210,820
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` import sys readline = sys.stdin.readline def parorder(Edge, p): N = len(Edge) par = [0]*N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append w...
output
1
105,410
13
210,821
Provide tags and a correct Python 2 solution for this coding contest problem. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this tree, [bitwise XOR](https://en.wikipedia.org/wi...
instruction
0
105,411
13
210,822
Tags: bitmasks, constructive algorithms, dfs and similar, greedy, math, trees Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_num(): return int(raw_input()) def i...
output
1
105,411
13
210,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,412
13
210,824
Yes
output
1
105,412
13
210,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,413
13
210,826
Yes
output
1
105,413
13
210,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,414
13
210,828
Yes
output
1
105,414
13
210,829
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,415
13
210,830
Yes
output
1
105,415
13
210,831
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,416
13
210,832
No
output
1
105,416
13
210,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,417
13
210,834
No
output
1
105,417
13
210,835
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,418
13
210,836
No
output
1
105,418
13
210,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,419
13
210,838
No
output
1
105,419
13
210,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You have unweighted tree of n vertices. You have to assign a positive weight to each edge so that the following condition would hold: * For every two different leaves v_{1} and v_{2} of this ...
instruction
0
105,420
13
210,840
No
output
1
105,420
13
210,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tre...
instruction
0
105,720
13
211,440
No
output
1
105,720
13
211,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi got tired of deciphering the prophecy hidden in the Tree of Life and decided to go back to her headquarters, rest a little and try there. Of course, she cannot uproot the Tree and take it ...
instruction
0
105,746
13
211,492
No
output
1
105,746
13
211,493
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two rooted trees, each with N vertices. The vertices of each tree are numbered 1 through N. In the first tree, the parent of Vertex i is Vertex A_i. Here, A_i=-1 if Vertex i is the roo...
instruction
0
105,994
13
211,988
No
output
1
105,994
13
211,989
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
105,995
13
211,990
"Correct Solution: ``` import sys input = sys.stdin.readline from collections import deque n = int(input()) stone = [0]+list(map(int,input().split())) ab = [list(map(int,input().split())) for i in range(n-1)] graph = [[] for i in range(n+1)] deg = [0]*(n+1) for a,b in ab: if stone[a] < stone[b]: graph[a].append(b...
output
1
105,995
13
211,991
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
105,996
13
211,992
"Correct Solution: ``` import sys input=sys.stdin.readline sys.setrecursionlimit(2*10**5) N=int(input()) A=list(map(int,input().split())) edge=[[] for i in range(N)] for i in range(N-1): a,b=map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) grundy=[-1]*N def dfs(v): if grundy[v]!=...
output
1
105,996
13
211,993
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
105,997
13
211,994
"Correct Solution: ``` """ Writer : SPD_9X2 https://atcoder.jp/contests/agc010/tasks/agc010_f Nが小さいので、各頂点に関して木を探索できる つまり、この頂点に置いた時勝てるか?がわかれば解ける まず2頂点で考えると、Aがもう片方以上の方に置けばかつ →値の大小が重要そう 置いた点から小さい方に下っていくのが最適。 ●→高橋 〇→青木とする ●-〇-●-〇 小さい方に下って行って、周囲に自分より小さいノードが無かったら 先っぽのノードの持ち主が負けになる 複数小さいノードがある場合、一つでも勝ちがある場合勝てるノードになる 一つ...
output
1
105,997
13
211,995
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
105,998
13
211,996
"Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- from fractions import gcd def readln(): _res = list(map(int,str(input()).split(' '))) return _res def calc(x,line): if line == 0: for l in v[x]: if e[l][0] == x: son = e[l][1] else: son = e[l][0] ...
output
1
105,998
13
211,997
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
105,999
13
211,998
"Correct Solution: ``` import copy, sys sys.setrecursionlimit(10 ** 6) n = int(input()) A = [int(i) for i in input().split()] edge = [[] for i in range(n)] grundy = [-1] * n for i in range(n-1): a, b = [int(i) for i in input().split()] edge[a-1].append(b-1) edge[b-1].append(a-1) def dfs(v): if grund...
output
1
105,999
13
211,999
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
106,000
13
212,000
"Correct Solution: ``` import sys input=sys.stdin.readline sys.setrecursionlimit(10000000) n=int(input()) a=list(map(int,input().split())) edge=[[]for _ in range(n)] for x,y in[list(map(int,input().split()))for _ in range(n-1)]: edge[x-1].append(y-1) edge[y-1].append(x-1) def bfs(r,v): for i in edge[v]: if(r!...
output
1
106,000
13
212,001
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
106,001
13
212,002
"Correct Solution: ``` import copy, sys sys.setrecursionlimit(10 ** 6) n = int(input()) A = [int(i) for i in input().split()] edge = [[] for i in range(n)] grundy = [-1] * n for i in range(n-1): a, b = [int(i) for i in input().split()] edge[a-1].append(b-1) edge[b-1].append(a-1) def dfs(v): if grund...
output
1
106,001
13
212,003
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a ...
instruction
0
106,002
13
212,004
"Correct Solution: ``` n=int(input());a=list(map(int,input().split()));e=[[]for _ in[0]*n] for x,y in[map(int,input().split())for _ in[0]*(n-1)]:e[x-1].append(y-1);e[y-1].append(x-1) def b(r,v):return sum((r!=i)and(a[v]>a[i])and(not(b(v,i)))for i in e[v]) print(*[i+1for i in range(n)if b(n,i)]) ```
output
1
106,002
13
212,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play ...
instruction
0
106,003
13
212,006
No
output
1
106,003
13
212,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play ...
instruction
0
106,004
13
212,008
No
output
1
106,004
13
212,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play ...
instruction
0
106,005
13
212,010
No
output
1
106,005
13
212,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play ...
instruction
0
106,006
13
212,012
No
output
1
106,006
13
212,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You a...
instruction
0
106,253
13
212,506
No
output
1
106,253
13
212,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You a...
instruction
0
106,254
13
212,508
No
output
1
106,254
13
212,509
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You a...
instruction
0
106,255
13
212,510
No
output
1
106,255
13
212,511
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let G be a simple graph. Let W be a non-empty subset of vertices. Then W is almost-k-uniform if for each pair of distinct vertices u,v ∈ W the distance between u and v is either k or k+1. You a...
instruction
0
106,256
13
212,512
No
output
1
106,256
13
212,513
Provide tags and a correct Python 3 solution for this coding contest problem. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number writt...
instruction
0
106,677
13
213,354
Tags: data structures, dfs and similar Correct Solution: ``` from collections import deque nodes = [] parents = [] values = [] broken = [] upperBound = [] lowerBound = [] n = int(input()) for _ in range(n): v, l, r = map(int, input().split()) nodes.append((v, l - 1, r - 1)) parents.append(-1) values....
output
1
106,677
13
213,355
Provide tags and a correct Python 3 solution for this coding contest problem. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number writt...
instruction
0
106,678
13
213,356
Tags: data structures, dfs and similar Correct Solution: ``` #!/usr/bin/env python3 # solution after hint:( # though it was not necessary # reduced recursion version n = int(input().strip()) vlrs = [tuple(map(int, input().strip().split())) for _ in range(n)] # shift numeration vlrs = [(v, l - (0 if l < 0 else 1), r ...
output
1
106,678
13
213,357
Provide tags and a correct Python 3 solution for this coding contest problem. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number writt...
instruction
0
106,679
13
213,358
Tags: data structures, dfs and similar Correct Solution: ``` import sys from collections import Counter n = int(sys.stdin.buffer.readline().decode('utf-8')) parent = [-1]*n value = [0]*n left, right = [-1]*n, [-1]*n for i, (v, l, r) in enumerate(map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): ...
output
1
106,679
13
213,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a...
instruction
0
106,680
13
213,360
No
output
1
106,680
13
213,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a...
instruction
0
106,681
13
213,362
No
output
1
106,681
13
213,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a...
instruction
0
106,682
13
213,364
No
output
1
106,682
13
213,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a...
instruction
0
106,683
13
213,366
No
output
1
106,683
13
213,367
Provide a correct Python 3 solution for this coding contest problem. Escape An undirected graph with positive values ​​at the vertices is given. The vertices are numbered from 1 to N, and the i-th vertex has a value of w_i. You can start from the first vertex and move on the graph with the constraint that you cannot ...
instruction
0
106,978
13
213,956
"Correct Solution: ``` # 前の提出は1が葉のときまずかったので再提出。 import sys input = sys.stdin.readline n,m=map(int,input().split()) W=[0]+list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(m)] S=1 ELIST=[[] for i in range(n+1)] EW=[0]*(n+1) for x,y in E: ELIST[x].append(y) ELIST[y].append(x) ...
output
1
106,978
13
213,957
Provide a correct Python 3 solution for this coding contest problem. Escape An undirected graph with positive values ​​at the vertices is given. The vertices are numbered from 1 to N, and the i-th vertex has a value of w_i. You can start from the first vertex and move on the graph with the constraint that you cannot ...
instruction
0
106,979
13
213,958
"Correct Solution: ``` import sys sys.setrecursionlimit(10**6) def solve(): readline = sys.stdin.readline write = sys.stdout.write N, M = map(int, readline().split()) *W, = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) ...
output
1
106,979
13
213,959
Provide a correct Python 3 solution for this coding contest problem. Escape An undirected graph with positive values ​​at the vertices is given. The vertices are numbered from 1 to N, and the i-th vertex has a value of w_i. You can start from the first vertex and move on the graph with the constraint that you cannot ...
instruction
0
106,980
13
213,960
"Correct Solution: ``` def find(x): if par[x] == x: return x else: par[x] = find(par[x]) return par[x] def union(x, y): par_x = find(x) par_y = find(y) if rank[par_x] < rank[par_y]: par[par_x] = par_y w[par_y]+=w[par_x] else: par[par_y] = par_x w[par_x]+=w[par_y] if rank[par...
output
1
106,980
13
213,961
Provide a correct Python 3 solution for this coding contest problem. Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $vi...
instruction
0
106,981
13
213,962
"Correct Solution: ``` from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) G[u-1].append(v-1) G[v-1].append(u...
output
1
106,981
13
213,963