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 a correct Python 3 solution for this coding contest problem. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X. Find the number of ways to paint each edge in this gr...
instruction
0
34,105
13
68,210
"Correct Solution: ``` class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) return self._parent[x] de...
output
1
34,105
13
68,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,106
13
68,212
Yes
output
1
34,106
13
68,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,107
13
68,214
Yes
output
1
34,107
13
68,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,108
13
68,216
No
output
1
34,108
13
68,217
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,109
13
68,218
No
output
1
34,109
13
68,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,110
13
68,220
No
output
1
34,110
13
68,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have an undirected weighted graph with N vertices and M edges. The i-th edge in the graph connects Vertex U_i and Vertex V_i, and has a weight of W_i. Additionally, you are given an integer X...
instruction
0
34,111
13
68,222
No
output
1
34,111
13
68,223
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,225
13
68,450
"Correct Solution: ``` import sys def w_f(dp): for k in range(v): for i in range(v): for j in range(v): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) for i in range(v): for j in range(v): if dp[i][i] < 0: print('NEGATIVE CYCLE') ...
output
1
34,225
13
68,451
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,226
13
68,452
"Correct Solution: ``` INF = 1e12 v, e = map(int, input().split()) cost = [[INF] * v for i in range(v)] for i in range(v): cost[i][i] = 0 for i in range(e): si, ti, di = map(int, input().split()) cost[si][ti] = di for k in range(v): for i in range(v): for j in range(v): if cost[i]...
output
1
34,226
13
68,453
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,227
13
68,454
"Correct Solution: ``` nv, ne = map(int, input().split()) costs = [[None] * nv for _ in range(nv)] for i in range(nv): costs[i][i] = 0 while ne: s, t, d = map(int, input().split()) costs[s][t] = d ne -= 1 def loop(): for k in range(nv): for i in range(nv): for j in range(nv):...
output
1
34,227
13
68,455
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,228
13
68,456
"Correct Solution: ``` v,e = map(int,input().split()) cost = [] for i in range(v): T = [float('inf')]*v T[i] = 0 cost.append(T) for i in range(e): a,b,c = map(int,input().split()) cost[a][b] = c for k in range(v): for i in range(v): for j in range(v): cost[i][j] = min(cost[i]...
output
1
34,228
13
68,457
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,229
13
68,458
"Correct Solution: ``` v, e = map(int, input().split()) G = [[float('inf') for _ in range(v)] for i in range(v)] for i in range(v): G[i][i] = 0 # print(G) dist = [[float('inf') for i in range(v)] for j in range(v)] for _ in range(e): s, t, d = map(int, input().split()) dist[s][t] = d for i in range(v): ...
output
1
34,229
13
68,459
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,230
13
68,460
"Correct Solution: ``` def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): if (d[i][k] != float("INF")) and (d[k][j] != float("INF")): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) #print(d) return d #####...
output
1
34,230
13
68,461
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,231
13
68,462
"Correct Solution: ``` import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 8) from itertools import accumulate from itertools import permutations from itertools import combinations from collections import defaultdict from collections import Counter import fractions import math from collections import deque ...
output
1
34,231
13
68,463
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertice...
instruction
0
34,232
13
68,464
"Correct Solution: ``` def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d ############################## n,w = map(int,input().split()) #n:頂点数 w:辺の数 d = [[float("inf") fo...
output
1
34,232
13
68,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,233
13
68,466
Yes
output
1
34,233
13
68,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,234
13
68,468
Yes
output
1
34,234
13
68,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,235
13
68,470
Yes
output
1
34,235
13
68,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,236
13
68,472
Yes
output
1
34,236
13
68,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,237
13
68,474
No
output
1
34,237
13
68,475
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,238
13
68,476
No
output
1
34,238
13
68,477
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,239
13
68,478
No
output
1
34,239
13
68,479
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 ...
instruction
0
34,240
13
68,480
No
output
1
34,240
13
68,481
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinc...
instruction
0
34,262
13
68,524
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` n=int(input()) degs=[0]*n neighbors=[0]*n children=[0]*n useless=[0]*n for i in range(n): neighbors[i]=[] children[i]=[] for i in range(n-1): a,b=map(int,input().split()) degs[a-1]+=1 degs[b-1]+=1 neighbors[a-1].append(b-1) neigh...
output
1
34,262
13
68,525
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinc...
instruction
0
34,263
13
68,526
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` import sys n = int(sys.stdin.readline()) edges = [[] for _ in range(n)] for _ in range(n - 1): i, j = tuple(int(k) for k in sys.stdin.readline().split()) i -= 1 j -= 1 edges[i].append(j) edges[j].append(i) # Prunes the graph starting f...
output
1
34,263
13
68,527
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinc...
instruction
0
34,264
13
68,528
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` import sys n = int(sys.stdin.readline()) edges = [[] for _ in range(n)] for _ in range(n - 1): i, j = tuple(int(k) for k in sys.stdin.readline().split()) i -= 1 j -= 1 edges[i].append(j) edges[j].append(i) # Prunes the graph starting f...
output
1
34,264
13
68,529
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 tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this ...
instruction
0
34,265
13
68,530
No
output
1
34,265
13
68,531
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 tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this ...
instruction
0
34,266
13
68,532
No
output
1
34,266
13
68,533
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 tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this ...
instruction
0
34,267
13
68,534
No
output
1
34,267
13
68,535
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 tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this ...
instruction
0
34,268
13
68,536
No
output
1
34,268
13
68,537
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,269
13
68,538
Tags: dsu, graphs, greedy Correct Solution: ``` def Find(x, par): if par[x] < 0: return x else: par[x] = Find(par[x], par) return par[x] def Unite(x, y, par, rank): x = Find(x, par) y = Find(y, par) if x != y: if rank[x] < rank[y]: par[y] += par[x] ...
output
1
34,269
13
68,539
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,270
13
68,540
Tags: dsu, graphs, greedy Correct Solution: ``` import sys from io import StringIO n, spec = map(int, input().split()) p = list(range(n + 1)) def isconnected(x, y): return find(x) == find(y) def find(x): global p if p[x] != x: p[x] = find(p[x]) return p[x] def connect(x, y): global p p[find(x)] = find(y) e...
output
1
34,270
13
68,541
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,271
13
68,542
Tags: dsu, graphs, greedy Correct Solution: ``` class UnionFind: def __init__(self, n): self.par = [-1]*n self.rank = [0]*n def Find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.Find(self.par[x]) return self.par[x] def ...
output
1
34,271
13
68,543
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,272
13
68,544
Tags: dsu, graphs, greedy Correct Solution: ``` n, m = map(int, input().split()) a = list(map(int, input().split())) e = [] for _ in range(m) : u, v, w = map(int, input().split()) e.append((u-1, v-1, w)) a = sorted(zip(a, range(n)), key = lambda x : x[0]) for i in range(1, n) : e.append((a[0][1], a[i][1],...
output
1
34,272
13
68,545
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,273
13
68,546
Tags: dsu, graphs, greedy Correct Solution: ``` def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = [tuple(map(int, input().split())) for i in range(m)] rt = a.index(min(a)) e = [(a[i] + a[rt], rt, i) for i in range(n) if i != rt] + [(w, u - 1, v - 1) for u, v, w in...
output
1
34,273
13
68,547
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,274
13
68,548
Tags: dsu, graphs, greedy Correct Solution: ``` def read_nums(): return [int(x) for x in input().split()] class UnionFind: def __init__(self, size): self._parents = list(range(size)) # number of elements rooted at i self._sizes = [1 for _ in range(size)] def _root(self, a): ...
output
1
34,274
13
68,549
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,275
13
68,550
Tags: dsu, graphs, greedy Correct Solution: ``` class UnionFind: def __init__(self, n): self.par = [-1]*n self.rank = [0]*n def Find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.Find(self.par[x]) return self.par[x] def ...
output
1
34,275
13
68,551
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges to this graph, but you have to pay for them. Th...
instruction
0
34,276
13
68,552
Tags: dsu, graphs, greedy Correct Solution: ``` import sys from io import StringIO def main(): def find_set(v): tmp = [] while v != parent[v]: tmp.append(v) v = parent[v] for i in tmp: parent[i] = v return v sys.stdin = StringIO(sys.stdin....
output
1
34,276
13
68,553
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,277
13
68,554
Yes
output
1
34,277
13
68,555
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,278
13
68,556
Yes
output
1
34,278
13
68,557
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,279
13
68,558
Yes
output
1
34,279
13
68,559
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,280
13
68,560
Yes
output
1
34,280
13
68,561
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,281
13
68,562
No
output
1
34,281
13
68,563
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,282
13
68,564
No
output
1
34,282
13
68,565
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,283
13
68,566
No
output
1
34,283
13
68,567
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 graph consisting of n vertices. A number is written on each vertex; the number on vertex i is a_i. Initially there are no edges in the graph. You may add some edges ...
instruction
0
34,284
13
68,568
No
output
1
34,284
13
68,569
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex i are all vertices on the path from the root to the vertex i...
instruction
0
34,301
13
68,602
Tags: dfs and similar, trees Correct Solution: ``` def main(): n = int(input()) par = {} chi = {i: 0 for i in range(1, n + 1)} fl = 0 uvaj = {} for i in range(n): p, c = map(int, input().split()) if p != -1: par[i + 1] = p chi[p] += 1 - c uvaj[i + ...
output
1
34,301
13
68,603
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex i are all vertices on the path from the root to the vertex i...
instruction
0
34,302
13
68,604
Tags: dfs and similar, trees Correct Solution: ``` def chk(node): global g,p,c temp=0 g[node].remove(p[node]) for i in g[node]: temp+=c[i] if temp==len(g[node]): g[node].append(p[node]) return 1 g[node].append(p[node]) ...
output
1
34,302
13
68,605
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex i are all vertices on the path from the root to the vertex i...
instruction
0
34,303
13
68,606
Tags: dfs and similar, trees Correct Solution: ``` import os from io import BytesIO, StringIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) dels = [] cof = [0] * n G = [list() for _ in range(n)] for v in range(n): p, c = map(int, input().split()) if p == -1: root = v ...
output
1
34,303
13
68,607
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rooted tree with vertices numerated from 1 to n. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex i are all vertices on the path from the root to the vertex i...
instruction
0
34,304
13
68,608
Tags: dfs and similar, trees Correct Solution: ``` from sys import stdin,stdout from math import gcd,sqrt from collections import deque input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') P=lambda x:stdout.write(x) hg=lambda x,y:((y+x-1)//x)*x pw=lambda x:1 if x==1...
output
1
34,304
13
68,609