message
stringlengths
2
49.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
446
108k
cluster
float64
13
13
__index_level_0__
int64
892
217k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add the length of the simple path between them to ...
instruction
0
56,900
13
113,800
Tags: constructive algorithms, dfs and similar, graphs, greedy, trees Correct Solution: ``` # optimal answer must be to choose the diameter then remove leaves not on # the diameter then remove the diameter # for every leaf removed, the answer is maximal since otherwise we did not choose # the diameter. When removing th...
output
1
56,900
13
113,801
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add the length of the simple path between them to ...
instruction
0
56,901
13
113,802
Tags: constructive algorithms, dfs and similar, graphs, greedy, trees Correct Solution: ``` import sys n = int(sys.stdin.buffer.readline().decode('utf-8')) adj = [[] for _ in range(n)] deg = [0]*n for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): adj[u-1].append(v-1) adj[v-1].a...
output
1
56,901
13
113,803
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add the length of the simple path between them to ...
instruction
0
56,902
13
113,804
Tags: constructive algorithms, dfs and similar, graphs, greedy, trees Correct Solution: ``` import sys n = int(sys.stdin.buffer.readline().decode('utf-8')) adj = [[] for _ in range(n)] deg = [0]*n for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): adj[u-1].append(v-1) adj[v-1].a...
output
1
56,902
13
113,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add...
instruction
0
56,903
13
113,806
No
output
1
56,903
13
113,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add...
instruction
0
56,904
13
113,808
No
output
1
56,904
13
113,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add...
instruction
0
56,905
13
113,810
No
output
1
56,905
13
113,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps: 1. choose two leaves; 2. add...
instruction
0
56,906
13
113,812
No
output
1
56,906
13
113,813
Provide tags and a correct Python 3 solution for this coding contest problem. Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is...
instruction
0
57,474
13
114,948
Tags: dfs and similar, graphs Correct Solution: ``` import sys input = sys.stdin.readline print = sys.stdout.write def get_input(): n, m = [int(x) for x in input().split(' ')] graph = [[] for _ in range(n + 1)] for _ in range(m): c1, c2 = [int(x) for x in input().split(' ')] graph[c1].ap...
output
1
57,474
13
114,949
Provide tags and a correct Python 3 solution for this coding contest problem. Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is...
instruction
0
57,475
13
114,950
Tags: dfs and similar, graphs Correct Solution: ``` import sys input = sys.stdin.readline print = sys.stdout.write def get_input(): n, m = [int(x) for x in input().split(' ')] graph = [[] for _ in range(n + 1)] for _ in range(m): c1, c2 = [int(x) for x in input().split(' ')] graph[c1].ap...
output
1
57,475
13
114,951
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights ...
instruction
0
57,649
13
115,298
Tags: binary search, constructive algorithms, graphs, shortest paths Correct Solution: ``` import heapq from collections import defaultdict class Graph: def __init__(self, n): self.nodes = set(range(n)) self.edges = defaultdict(list) self.distances = {} def add_edge(self, from_node, t...
output
1
57,649
13
115,299
Provide tags and a correct Python 3 solution for this coding contest problem. ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights ...
instruction
0
57,650
13
115,300
Tags: binary search, constructive algorithms, graphs, shortest paths Correct Solution: ``` import heapq from collections import defaultdict class Graph: def __init__(self, n): self.nodes = set(range(n)) self.edges = defaultdict(list) self.distances = {} def add_edge(self, from_node, t...
output
1
57,650
13
115,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ...
instruction
0
57,651
13
115,302
No
output
1
57,651
13
115,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ...
instruction
0
57,652
13
115,304
No
output
1
57,652
13
115,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ...
instruction
0
57,653
13
115,306
No
output
1
57,653
13
115,307
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,725
13
115,450
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` import sys, math, os.path FILE_INPUT = "e.in" DEBUG = os.path.isfile(FILE_INPUT) if DEBUG: sys.stdin = open(FILE_INPUT) def ni(): return map(int, input().split()) def nia(): return list(map(int,input().split())) def log(x): ...
output
1
57,725
13
115,451
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,726
13
115,452
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy,copy mod = 10**9+7 INF = float('inf') def inp(...
output
1
57,726
13
115,453
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,727
13
115,454
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` import sys, math, os.path FILE_INPUT = "e.in" DEBUG = os.path.isfile(FILE_INPUT) if DEBUG: sys.stdin = open(FILE_INPUT) def ni(): return map(int, input().split()) def nia(): return list(map(int,input().split())) def log(x): ...
output
1
57,727
13
115,455
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,728
13
115,456
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` n,m = map(int,input().split()) ae = [[] for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) ae[a-1].append(b-1) ae[b-1].append(a-1) mn = -1 nbr = n for i in range(n): if len(ae[i])<nbr: mn = i nbr ...
output
1
57,728
13
115,457
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,729
13
115,458
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` import sys, math, os.path FILE_INPUT = "e.in" DEBUG = os.path.isfile(FILE_INPUT) if DEBUG: sys.stdin = open(FILE_INPUT) def ni(): return map(int, input().split()) def nia(): return list(map(int,input().split())) def log(x): ...
output
1
57,729
13
115,459
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,730
13
115,460
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` import sys from collections import deque n, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split()) adj = [set() for _ in range(n)] for u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer): adj[u-1].add(v-1...
output
1
57,730
13
115,461
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,731
13
115,462
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` N,M = map(int,input().split()) nE = [{i} for i in range(N)] for _ in range(M): u,v = map(int,input().split()) u,v = u-1,v-1 nE[u].add(v) nE[v].add(u) unvisited = set(range(N)) res = [] while unvisited: t = len(unvisited) s = next(i...
output
1
57,731
13
115,463
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of verti...
instruction
0
57,732
13
115,464
Tags: data structures, dfs and similar, dsu, graphs Correct Solution: ``` n, m = map(int, input().split()) bar = [{i} for i in range(n)] for i in range(m): u, v = map(int, input().split()) u, v = u - 1, v - 1 bar[u].add(v) bar[v].add(u) nodes = set(range(n)) ans = [] while (nodes): u = next(iter(nodes)) nodes....
output
1
57,732
13
115,465
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,733
13
115,466
Yes
output
1
57,733
13
115,467
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,734
13
115,468
Yes
output
1
57,734
13
115,469
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,735
13
115,470
Yes
output
1
57,735
13
115,471
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,736
13
115,472
Yes
output
1
57,736
13
115,473
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,737
13
115,474
No
output
1
57,737
13
115,475
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,738
13
115,476
No
output
1
57,738
13
115,477
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,739
13
115,478
No
output
1
57,739
13
115,479
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 and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no ...
instruction
0
57,740
13
115,480
No
output
1
57,740
13
115,481
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i...
instruction
0
57,816
13
115,632
No
output
1
57,816
13
115,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Edge i connects Vertex a_i and b_i...
instruction
0
57,817
13
115,634
No
output
1
57,817
13
115,635
Provide a correct Python 3 solution for this coding contest problem. Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i-th edge connects Vertices a_i and b_i, and it costs c_i ye...
instruction
0
57,866
13
115,732
"Correct Solution: ``` n, m = map(int, input().split()) g = [[0 for j in range(n)] for i in range(n)] for i in range(m): u, v, w = map(int, input().split()) g[u - 1][v - 1] = g[v - 1][u - 1] = w e = [sum(g[i][j] for i in range(n) if S >> i & 1 for j in range(i + 1, n) if S >> j & 1) for S in range(1 << n)] ...
output
1
57,866
13
115,733
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,072
13
116,144
Tags: dfs and similar, graphs Correct Solution: ``` from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd from collections import deque from bisect import bisect_left def dfs(x,c): global flag stack=deque([[x,c]]) while stack: # print(graph,l) x,c=stack.pop() if...
output
1
58,072
13
116,145
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,073
13
116,146
Tags: dfs and similar, graphs Correct Solution: ``` # Author : raj1307 - Raj Singh # Date : 23.05.2020 from __future__ import print_function import itertools,os,sys,threading # input=raw_input # range=xrange def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" "...
output
1
58,073
13
116,147
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,074
13
116,148
Tags: dfs and similar, graphs Correct Solution: ``` import sys from typing import List, Tuple, Dict # **Note: To enable DEBUG, just add argument "-d" to the binary**. I.e.: # `python solution.py -d` DEBUG = len(sys.argv) > 1 and sys.argv[1] == '-d' # Sample usage: `LOG("a =", 1,"b =", 2)`. def LOG(*argv): if (DEBUG...
output
1
58,074
13
116,149
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,075
13
116,150
Tags: dfs and similar, graphs Correct Solution: ``` import os from io import BytesIO #input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def input_as_list(): return list(map(int, input().split())) def array_of(f, *dim): return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f() def main(): ...
output
1
58,075
13
116,151
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,076
13
116,152
Tags: dfs and similar, graphs Correct Solution: ``` from collections import defaultdict ,deque def bfs(): q = deque([1]) color[1] = 1 while q : v = q.popleft() for i in g[v]: if color[i] == 0 : color[i] = - color[v] q.append(i) elif c...
output
1
58,076
13
116,153
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,077
13
116,154
Tags: dfs and similar, graphs Correct Solution: ``` # lista doble enlazada o(1) operaciones en los bordes es mejor que si se implementa en el propio lenguaje from collections import deque def bfs_2k(graph, initVertex, color): queue = deque() queue.append(initVertex) color[initVertex] = 0 while queue: ...
output
1
58,077
13
116,155
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,078
13
116,156
Tags: dfs and similar, graphs Correct Solution: ``` def dostuff(d, q): while q: v,inc = q.pop() for e in c[v]: oth = e[1] if e[0]==v else e[0] if e in d: if (d[e]!=v if inc else d[e]==v): return False, d else: d[e]=v if inc else oth q.append((oth, not inc)) return True,d def s(o, d,l=[]): fo...
output
1
58,078
13
116,157
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any ...
instruction
0
58,079
13
116,158
Tags: dfs and similar, graphs Correct Solution: ``` from collections import deque n, m = map(int, input().split()) g = [[] for _ in range(n)] e = [] for _ in range(m): u, v = map(lambda _: int(_) - 1, input().split()) e.append((u, v)) g[u].append(v); g[v].append(u) p = [-1 for _ in range(n)] p[0] = True ok = True ...
output
1
58,079
13
116,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,080
13
116,160
Yes
output
1
58,080
13
116,161
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,081
13
116,162
Yes
output
1
58,081
13
116,163
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,082
13
116,164
Yes
output
1
58,082
13
116,165
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,083
13
116,166
Yes
output
1
58,083
13
116,167
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,084
13
116,168
No
output
1
58,084
13
116,169
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,085
13
116,170
No
output
1
58,085
13
116,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,086
13
116,172
No
output
1
58,086
13
116,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that th...
instruction
0
58,087
13
116,174
No
output
1
58,087
13
116,175
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 and m edges. Initially there is a single integer written on every vertex: the vertex i has p_i written on it. All p_i are distinct inte...
instruction
0
58,217
13
116,434
No
output
1
58,217
13
116,435