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. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,402
13
14,804
"Correct Solution: ``` n,m = map(int,input().split()) INF = 10**18 d = [[INF]*n for _ in range(n)] nd = [[INF]*n for _ in range(n)] for i in range(n): d[i][i] = 0 nd[i][i] = 0 for _ in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 d[a][b] = c d[b][a] = c nd[a][b] = c nd[b]...
output
1
7,402
13
14,805
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,403
13
14,806
"Correct Solution: ``` INF = float("inf") def WarshallFloyd(M): N = len(M) for k in range(N): for j in range(N): for i in range(N): M[i][j] = min(M[i][j], M[i][k] + M[k][j]) return M N, M, *ABC = map(int, open(0).read().split()) E = [[INF] * (N + 1) for _ in range(N +...
output
1
7,403
13
14,807
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,404
13
14,808
"Correct Solution: ``` N, M = list(map(int, input().split())) abc = [list(map(int, input().split())) for _ in range(M)] inf = 1000000 L = [[0] * N for _ in range(N)] C = [[inf] * N for _ in range(N)] for i in range(M): a, b, c = abc[i] a -= 1 b -= 1 C[a][b] = c C[b][a] = c for i in range(N): C[i][i] = 0 ...
output
1
7,404
13
14,809
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,405
13
14,810
"Correct Solution: ``` N, M = map(int, input().split()) inf = 10**6 abc = [] d = [[inf]*N for i in range(N)] for i in range(M): a, b, c = map(int, input().split()) d[a-1][b-1] = c d[b-1][a-1] = c abc.append((a-1,b-1,c)) for k in range(N): for i in range(N): for j in range(N): d[i][j] = min(d[i][k]+d[k][j], d...
output
1
7,405
13
14,811
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,406
13
14,812
"Correct Solution: ``` def warshall_floyd(d): 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, M = map(int, input().split()) d = [[float('inf') for i in range(N)] for i in range(N)] edges = [] for i in range(M):...
output
1
7,406
13
14,813
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,407
13
14,814
"Correct Solution: ``` n,m=[int(x) for x in input().split()] path=[] d=[[float("inf") for _ in [0]*n] for _2 in [0]*n] for _ in [0]*m: a,b,c=[int(x) for x in input().split()] path.append((a-1,b-1,c)) d[a-1][b-1]=d[b-1][a-1]=c from itertools import product for k,i,j in product(range(n),range(n),range(n)): ...
output
1
7,407
13
14,815
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,408
13
14,816
"Correct Solution: ``` # -*- coding: utf-8 -*- def inpl(): return map(int, input().split()) N, M = inpl() INF = float("inf") G = [[INF]*(N) for _ in range(N)] E = [] for _ in range(M): a, b, c = inpl() G[a-1][b-1] = c G[b-1][a-1] = c E.append([a-1, b-1, c]) for k in range(N): for i in range(N): ...
output
1
7,408
13
14,817
Provide a correct Python 3 solution for this coding contest problem. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_...
instruction
0
7,409
13
14,818
"Correct Solution: ``` n,m=map(int,input().split()) inf=float("inf") data=[[inf]*(n+1) for i in range(n+1)] for i in range(1,n+1): data[i][i]=0 lst=[] for u in range(m): a,b,c=map(int,input().split()) data[a][b]=c data[b][a]=c lst.append([a,b,c]) for k in range(1,n+1): for i in range(1,n+1): ...
output
1
7,409
13
14,819
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,410
13
14,820
Yes
output
1
7,410
13
14,821
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,411
13
14,822
Yes
output
1
7,411
13
14,823
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,412
13
14,824
Yes
output
1
7,412
13
14,825
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,413
13
14,826
Yes
output
1
7,413
13
14,827
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,414
13
14,828
No
output
1
7,414
13
14,829
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,415
13
14,830
No
output
1
7,415
13
14,831
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,416
13
14,832
No
output
1
7,416
13
14,833
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 connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with ...
instruction
0
7,417
13
14,834
No
output
1
7,417
13
14,835
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,582
13
15,164
Tags: dfs and similar, graphs Correct Solution: ``` import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import defaultdict def dfs(node): vis[node]=1 colour[node]=0 arr[0]+=1 stack=[node] while stack: cur=stack.pop() for j in edge[cur]: ...
output
1
7,582
13
15,165
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,583
13
15,166
Tags: dfs and similar, graphs Correct Solution: ``` from sys import stdin,stdout from collections import defaultdict import sys, threading sys.setrecursionlimit(10**6) # max depth of recursion threading.stack_size(2**25) def main(): def power(x, p): re = 1 mode= 998244353 while p: ...
output
1
7,583
13
15,167
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,584
13
15,168
Tags: dfs and similar, graphs Correct Solution: ``` # aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys from heapq import * mod = 998244353 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())...
output
1
7,584
13
15,169
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,585
13
15,170
Tags: dfs and similar, graphs Correct Solution: ``` # einlesen # dfs für jede cc # Zählen, wie viele w/r # wenn cooring nicht möglich -> Ergebnis 0 # sonst 2^w+2^r M=998244353 t=int(input()) n,m=0,0 g=[] v=[] def dfs(r): s=[r] v[r]=1 c=[0,1] while s: x=s.pop() for j in g[x]...
output
1
7,585
13
15,171
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,586
13
15,172
Tags: dfs and similar, graphs Correct Solution: ``` ###pyrival template for fast IO import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writab...
output
1
7,586
13
15,173
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,587
13
15,174
Tags: dfs and similar, graphs Correct Solution: ``` M=998244353 t=int(input()) n,m=0,0 g=[] v=[] def dfs(r): s=[r] v[r]=1 c=[0,1] while s: x=s.pop() for j in g[x]: if v[j]==v[x]:return 0 if v[j]==-1: v[j]=v[x]^1 c[v[j]]+=1 ...
output
1
7,587
13
15,175
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,588
13
15,176
Tags: dfs and similar, graphs Correct Solution: ``` from collections import defaultdict from collections import deque import sys input = sys.stdin.readline mod = 998244353 def bfs(node,v,p): ans=1 q=deque() q.append(node) v[node]=1 a,b=0,0 while q: i=q.popleft() if p[i]==1: ...
output
1
7,588
13
15,177
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on v...
instruction
0
7,589
13
15,178
Tags: dfs and similar, graphs Correct Solution: ``` from sys import stdin,stdout from collections import defaultdict import sys, threading sys.setrecursionlimit(10**5) # max depth of recursion threading.stack_size(2**25) def main(): def power(x, p): re = 1 mode= 998244353 while p: ...
output
1
7,589
13
15,179
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,590
13
15,180
Yes
output
1
7,590
13
15,181
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,591
13
15,182
Yes
output
1
7,591
13
15,183
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,592
13
15,184
Yes
output
1
7,592
13
15,185
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,593
13
15,186
Yes
output
1
7,593
13
15,187
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,594
13
15,188
No
output
1
7,594
13
15,189
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,595
13
15,190
No
output
1
7,595
13
15,191
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,596
13
15,192
No
output
1
7,596
13
15,193
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 graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes bea...
instruction
0
7,597
13
15,194
No
output
1
7,597
13
15,195
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,800
13
15,600
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys from collections import deque input = sys.stdin.readline def solve(): n = int(input()) G = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) G[a].append(b) G[b...
output
1
7,800
13
15,601
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,801
13
15,602
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys;from collections import Counter;input = sys.stdin.readline def tree_dfs(g, root=0): s = [root];d = [1] * len(g);order = [] while s:p = s.pop();d[p] = 0;order.append(p);s += [node for node in g[p] if d[node]] r...
output
1
7,801
13
15,603
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,802
13
15,604
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys from collections import Counter input = sys.stdin.readline def tree_dfs(g, root=0): s = [root] d = [1] * len(g) order = [] while s: p = s.pop() d[p] = 0 order.append(p) for...
output
1
7,802
13
15,605
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,803
13
15,606
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` def divisors(M): d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d def popcount(x): x = x - ((x >> 1) & 0x55555555)...
output
1
7,803
13
15,607
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,804
13
15,608
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys from sys import stdin from collections import deque def NC_Dij(lis,start): N = len(lis) ret = [float("inf")] * len(lis) ret[start] = 0 chnum = [1] * N q = deque([start]) plis = [i for i in ...
output
1
7,804
13
15,609
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,805
13
15,610
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys def putin(): return map(int, sys.stdin.readline().split()) def sol(): n = int(sys.stdin.readline()) G = [] for i in range(n): G.append([]) for i in range(n - 1): u, v = putin() ...
output
1
7,805
13
15,611
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,806
13
15,612
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` import sys from collections import Counter input = sys.stdin.readline def tree_dfs(g, root=0): s = [root] d = [1] * len(g) order = [] while s: p = s.pop() d[p] = 0 order.append(p) for...
output
1
7,806
13
15,613
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (inclu...
instruction
0
7,807
13
15,614
Tags: combinatorics, dfs and similar, implementation, math, trees Correct Solution: ``` #CF1527D from bisect import bisect,bisect_left from collections import * from heapq import * from math import gcd,ceil,sqrt,floor,inf from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools im...
output
1
7,807
13
15,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,808
13
15,616
Yes
output
1
7,808
13
15,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,809
13
15,618
Yes
output
1
7,809
13
15,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,810
13
15,620
Yes
output
1
7,810
13
15,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,811
13
15,622
Yes
output
1
7,811
13
15,623
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,812
13
15,624
No
output
1
7,812
13
15,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,813
13
15,626
No
output
1
7,813
13
15,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,814
13
15,628
No
output
1
7,814
13
15,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node...
instruction
0
7,815
13
15,630
No
output
1
7,815
13
15,631
Provide tags and a correct Python 3 solution for this coding contest problem. You're given a tree with n vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. Input The first line contains an intege...
instruction
0
8,152
13
16,304
Tags: dfs and similar, dp, graphs, greedy, trees Correct Solution: ``` from sys import stdin inp = stdin.readline n, ans = int(inp()), 0 if n & 1: print(-1) exit() g = {i: [set(), 0] for i in range(1, n + 1)} visited = [0] * (n + 1) for _ in range(n - 1): a, b = map(int, inp().split()) g[a][0].add(b) ...
output
1
8,152
13
16,305
Provide tags and a correct Python 3 solution for this coding contest problem. You're given a tree with n vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. Input The first line contains an intege...
instruction
0
8,153
13
16,306
Tags: dfs and similar, dp, graphs, greedy, trees Correct Solution: ``` from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque n=int(input()) d={i:set() for i in range(1,n+1)} for i in range(n-1): a,b=map(int,input().split()) d[a].add(b) d[...
output
1
8,153
13
16,307