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. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,994
13
213,988
"Correct Solution: ``` n = int(input()) M = [[0 for i in range(n)] for j in range(n)] for i in range(n): _ = list(map(int, input().split())) u = _[0] - 1 # 0オリジンに変換 degree = _[1] for j in range(degree): v = _[j+2] - 1 # 0オリジンに変換 M[u][v] = 1 for row in M: print(' '.join(map(str,...
output
1
106,994
13
213,989
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,995
13
213,990
"Correct Solution: ``` n = int(input()) dic = {} for _ in range(n): datum = list(map(int, input().split())) status = ["0"]*n for i in datum[2:]: status[i-1] = "1" print(" ".join(status)) ```
output
1
106,995
13
213,991
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,996
13
213,992
"Correct Solution: ``` def main(): n = int(input()) rows = [] for i in range(n): rows.append([int(x) for x in input().split()]) for row in rows: u,k = row[0],row[1] ul = [0]*n for j in range(k): ul[row[j+2]-1] = 1 print(' '.join([str(u) for u in ul])) ...
output
1
106,996
13
213,993
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,997
13
213,994
"Correct Solution: ``` # -*- coding: utf-8 -*- N = int(input()) adj = [["0"]*N for _ in range(N)] for _ in range(N): inp = list(map(int, input().split())) for i in inp[2:]: adj[inp[0]-1][i-1] = "1" for a in adj: print(" ".join(a)) ```
output
1
106,997
13
213,995
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,998
13
213,996
"Correct Solution: ``` n=int(input()) da=[[0 for i in range(n)] for i in range(n)] for i in range(n): se=list(map(int,input().split())) for j in se[2:]: da[i][j-1]=1 for i in range(n): for j in range(n): if j==n-1: print(da[i][j]) else: print(da[i][j],end=' ')...
output
1
106,998
13
213,997
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
106,999
13
213,998
"Correct Solution: ``` n = int(input()) mat = [[0]*n for _ in range(n)] for _ in range(n): In = list(map(int, input().split())) u, k, vs = In[0], In[1], In[2:] for v in vs: mat[u - 1][v - 1] = 1 for i in range(n): print(*mat[i]) ```
output
1
106,999
13
213,999
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
107,000
13
214,000
"Correct Solution: ``` n = int(input()) m = [[0 for _ in range(n)] for _ in range(n)] for i in range(n): u, k, *v = map(int, input().split()) for j in v: m[u-1][j-1] = 1 for i in range(n): print(" ".join(map(str,m[i]))) ```
output
1
107,000
13
214,001
Provide a correct Python 3 solution for this coding contest problem. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V...
instruction
0
107,001
13
214,002
"Correct Solution: ``` def adjmatrices(): n = int(input()) for i in range(n): node_list = list(map(int, input().split())) matrix = [0]*n for j in node_list[2:]: matrix[j-1] = 1 print(*matrix) if __name__ == '__main__': adjmatrices() ```
output
1
107,001
13
214,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,002
13
214,004
Yes
output
1
107,002
13
214,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,003
13
214,006
Yes
output
1
107,003
13
214,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,004
13
214,008
Yes
output
1
107,004
13
214,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,005
13
214,010
Yes
output
1
107,005
13
214,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,006
13
214,012
No
output
1
107,006
13
214,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,007
13
214,014
No
output
1
107,007
13
214,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,008
13
214,016
No
output
1
107,008
13
214,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An ad...
instruction
0
107,009
13
214,018
No
output
1
107,009
13
214,019
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,275
13
214,550
Tags: dp Correct Solution: ``` def dfs(v, pr = -1): dp[v][1] = 1 sz[v] = 1 for to in g[v]: if to == pr: continue dfs(to, v) for x in range(sz[v], 0, -1): for y in range(sz[to], -1, -1): #print(v, x, y, dp[v][x], dp[to][y]) dp[v]...
output
1
107,275
13
214,551
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,276
13
214,552
Tags: dp Correct Solution: ``` from fractions import Fraction n = int(input()) adj = [list() for x in range(n)] H = [0] * n F = [0] * n FoH = [list() for x in range(n)] sz = 0 order = [0] * n pi = [-1] * n def dfs(u, p = -1): global pi, order, sz pi[u] = p for v in adj[u]: if v != p: dfs(v, u) orde...
output
1
107,276
13
214,553
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,277
13
214,554
Tags: dp Correct Solution: ``` n=int(input()) w=[[] for i in range(n+1)] sz=[0]*(n+1) f=[[0]*(n+1) for i in range(n+1)] def dfs(u,p): f[u][1]=sz[u]=1 for v in w[u]: if v!=p: dfs(v,u) for j in range(sz[u],-1,-1): for k in range(sz[v],-1,-1):f[u][j+k]=max(f[u][j+k],f[u][j]*f[v][k]) sz[u]+=sz[v] for i in...
output
1
107,277
13
214,555
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,278
13
214,556
Tags: dp Correct Solution: ``` maxn = 710 to = [[] for i in range(maxn)] dp = [[0 for i in range(maxn)] for i in range(maxn)] size = [0 for i in range(maxn)] n = int(input()) def dfs(now, f): size[now] = 1 dp[now][1] = 1 for i in to[now]: if i != f: dfs(i, now) size[now] += s...
output
1
107,278
13
214,557
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,279
13
214,558
Tags: dp Correct Solution: ``` n = int(input()) edges = [[] for i in range(n)] ch = [[] for i in range(n)] for i in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) dp = [1 for i in range(n)] prod = [1 for i in range(n)] def dfs(v, pr): prod[v] = 1 for to...
output
1
107,279
13
214,559
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,280
13
214,560
Tags: dp Correct Solution: ``` n=int(input()) sz=[0]*(n+1) g=[[] for _ in range(n+1)] dp=[[0]*(n+1) for _ in range(n+1)] def dfs(u,pr): sz[u]=dp[u][1]=1 for v in g[u]: if(v==pr):continue dfs(v,u) for i in range(sz[u],-1,-1): for j in range(sz[v],-1,-1): dp[u][...
output
1
107,280
13
214,561
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,281
13
214,562
Tags: dp Correct Solution: ``` from fractions import Fraction n = int(input()) G = [[] for i in range(n)] for i in range(n-1): a, b = (int(x)-1 for x in input().split()) G[a].append(b) G[b].append(a) f, g, h = [1]*n, [1]*n, [1]*n def dfs(v, p): if p != -1: G[v].remove(p) for e in G[v]: ...
output
1
107,281
13
214,563
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components le...
instruction
0
107,282
13
214,564
Tags: dp Correct Solution: ``` def dfs(u,pa,gr): szz[u]=1 for i in gr[u]: if i ==pa: continue dfs(i,u,gr) szz[u]+=szz[i] first=True n=szz[u] temp=[0 for i in range(0,n)] cs=0 for it in gr[u]: if it==pa: continue if first: first=False for i in range(0,szz[it]+1): temp[i]=dp[it][i] i...
output
1
107,282
13
214,565
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,283
13
214,566
Yes
output
1
107,283
13
214,567
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,284
13
214,568
Yes
output
1
107,284
13
214,569
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,285
13
214,570
Yes
output
1
107,285
13
214,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,286
13
214,572
Yes
output
1
107,286
13
214,573
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,287
13
214,574
No
output
1
107,287
13
214,575
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,288
13
214,576
No
output
1
107,288
13
214,577
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,289
13
214,578
No
output
1
107,289
13
214,579
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the ...
instruction
0
107,290
13
214,580
No
output
1
107,290
13
214,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ksenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve. How many distinct trees are there consisting of n vertices, each with t...
instruction
0
107,327
13
214,654
No
output
1
107,327
13
214,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ksenia has her winter exams. Today she is learning combinatorics. Here's one of the problems she needs to learn to solve. How many distinct trees are there consisting of n vertices, each with t...
instruction
0
107,328
13
214,656
No
output
1
107,328
13
214,657
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,391
13
214,782
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` def read_data(): n = int(input()) ps = list(map(int, input().split())) return n, ps def solve(n, ps): ps = [p - 1 for p in ps] cycles = [0] * n roots = [] has_odd_cycle = False for i in range(n): ...
output
1
107,391
13
214,783
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,392
13
214,784
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` n = int(input()) a = list(map(lambda x: int(x) - 1, input().split())) p = q = -1 for i in range(n): if a[a[i]] == i: p, q = i, a[i] if a[i] == i: print('YES') [print(i + 1, j + 1) for j in range(n) if i != j] ...
output
1
107,392
13
214,785
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,393
13
214,786
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` def main(): n = int(input()) a = list(map(lambda x: int(x) - 1, input().split())) p = -1 q = -1 for i in range(n): if a[a[i]] == i: p, q = i, a[i] if a[i] == i: print('YES') ...
output
1
107,393
13
214,787
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,394
13
214,788
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` n = int(input()) a = [0] + list(map(int, input().split())) vis = [False] * (n + 1) lp = [] for i in range(1, n + 1): if vis[i]: continue cur = i q = [] while not vis[cur]: vis[cur] = True q.append...
output
1
107,394
13
214,789
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,395
13
214,790
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` m = int(input()) L = list(map(int, input().split())) for i in range(len(L)): L[i] -= 1 temp = [] d = set() flag1 = 0 flag2 = 0 flag3 = 0 for index, num in enumerate(L): if num not in d: t = 1 d.add(num) ...
output
1
107,395
13
214,791
Provide tags and a correct Python 3 solution for this coding contest problem. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, if for any two vertices of the tree u and v the ...
instruction
0
107,396
13
214,792
Tags: constructive algorithms, dfs and similar, greedy, trees Correct Solution: ``` import sys readline = sys.stdin.readline N = int(readline()) P = list(map(lambda x: int(x)-1, readline().split())) PP = [] used = set() for i in range(N): if i not in used: res = [] while i not in used: ...
output
1
107,396
13
214,793
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, i...
instruction
0
107,397
13
214,794
No
output
1
107,397
13
214,795
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, i...
instruction
0
107,398
13
214,796
No
output
1
107,398
13
214,797
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, i...
instruction
0
107,399
13
214,798
No
output
1
107,399
13
214,799
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree of size n is an undirected connected graph consisting of n vertices without cycles. Consider some tree with n vertices. We call a tree invariant relative to permutation p = p1p2... pn, i...
instruction
0
107,400
13
214,800
No
output
1
107,400
13
214,801
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,686
13
215,372
"Correct Solution: ``` def main(): import sys input = sys.stdin.readline N, mod = map(int, input().split()) adj = [[] for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) adj[a].append(b) adj[b].append(a) """ここから変更""" # op: 普通に根を固定した木DPで子の情報を親に...
output
1
107,686
13
215,373
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,687
13
215,374
"Correct Solution: ``` from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from bisect import bisect_right, bisect_left import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right f...
output
1
107,687
13
215,375
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,688
13
215,376
"Correct Solution: ``` import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() def resolve(): n, MOD = map(int,input().split()) E = [[] for _ in range(n)] nv_to_idx = [{} for _ in range(n)] for _ in range(n - 1): u, v = map...
output
1
107,688
13
215,377
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,689
13
215,378
"Correct Solution: ``` # -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache...
output
1
107,689
13
215,379
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,690
13
215,380
"Correct Solution: ``` import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline n, mod = map(int, input().split()) graph = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) ele_id = 1 # dp[v][i] = (頂点vから出るi番...
output
1
107,690
13
215,381
Provide a correct Python 3 solution for this coding contest problem. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other b...
instruction
0
107,691
13
215,382
"Correct Solution: ``` from collections import deque N, M = map(int, input().split()) d = [list() for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) d[a].append(b) d[b].append(a) queue=deque([1]) vs = set([1]) vs_bfs = list() parents = [0] * (N+1) while queue: v = queue.popleft(...
output
1
107,691
13
215,383