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 a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,835
13
171,670
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` import sys t=int(sys.stdin.readline()) for _ in range(t): n,l,r=map(int,sys.stdin.readline().split()) prev=0 cur=0 start=1 if l==r and l==n*(n-1)+1: print(1) else: ans=[] while(True): ...
output
1
85,835
13
171,671
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,836
13
171,672
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: ...
output
1
85,836
13
171,673
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,837
13
171,674
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` def solve(): n, l, r = [int(i) for i in input().split()] seq = [] i = 1 while l <= r: while l > 2 * n - 2: if l == 3: i = 1 break l -= 2 * n - 2 ...
output
1
85,837
13
171,675
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,838
13
171,676
Yes
output
1
85,838
13
171,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,839
13
171,678
Yes
output
1
85,839
13
171,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,840
13
171,680
Yes
output
1
85,840
13
171,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,841
13
171,682
Yes
output
1
85,841
13
171,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,842
13
171,684
No
output
1
85,842
13
171,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,843
13
171,686
No
output
1
85,843
13
171,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,844
13
171,688
No
output
1
85,844
13
171,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a complete directed graph K_n with n vertices: each pair of vertices u ≠ v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle...
instruction
0
85,845
13
171,690
No
output
1
85,845
13
171,691
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edg...
instruction
0
86,279
13
172,558
Tags: constructive algorithms, dfs and similar, dp, greedy, trees Correct Solution: ``` from collections import defaultdict,deque import sys import bisect import math input=sys.stdin.readline mod=1000000007 def bfs(root,count): q=deque([root]) vis.add(root) while q: vertex=q.popleft() for c...
output
1
86,279
13
172,559
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 (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex ha...
instruction
0
86,280
13
172,560
No
output
1
86,280
13
172,561
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 (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex ha...
instruction
0
86,281
13
172,562
No
output
1
86,281
13
172,563
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 (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex ha...
instruction
0
86,282
13
172,564
No
output
1
86,282
13
172,565
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 (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex ha...
instruction
0
86,283
13
172,566
No
output
1
86,283
13
172,567
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,802
13
173,604
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import deque def main(): t = int(input()) for _ in range(t): n, m = map(int, input().spl...
output
1
86,802
13
173,605
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,803
13
173,606
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` def solve(): n, m = map(int, input().split()) edges = [] adj = [[] for _ in range(n)] indeg = [0] * n for _ in range(m): t, x, y = map(int, input().split()) x -= 1 y -= 1 edges.append((x, y))...
output
1
86,803
13
173,607
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,804
13
173,608
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import math import time from collections import defaultdict, deque from sys import stdin, stdout from bisect import bisect_left, bisect_right import sys class Graph: def __init__(self, n): sys.setrecursionlimit(200005) se...
output
1
86,804
13
173,609
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,805
13
173,610
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import collections import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) for _ in range(t): n,m=map(int,input().split()) graph1=[] graph2=[] graph3=[0]*(n+1) undirected=[] for i in range(...
output
1
86,805
13
173,611
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,806
13
173,612
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import sys def toposort(graph): res = [] found = [0] * len(graph) stack = list(range(len(graph))) while stack: node = stack.pop() if node < 0: res.append(~node) elif not found[node]: ...
output
1
86,806
13
173,613
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,807
13
173,614
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import defaultdict,deque def kahns_topo(graph,in_degree,vertices): queue = deque() for i in range(vertices): if in_degree[i] == 0: queue.append(i...
output
1
86,807
13
173,615
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,808
13
173,616
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` from collections import deque def bfs(indegree): q = deque() for i in range(len(indegree)): if indegree[i] == 0: q.append(i) while q: curr = q.popleft() topo.append(curr) for neighbor in...
output
1
86,808
13
173,617
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some ...
instruction
0
86,809
13
173,618
Tags: constructive algorithms, dfs and similar, graphs Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import defaultdict def kahn_top_sort(g, n): # Returns the topological order. If graph of N vertices contains a cycle, then the order list will be of length < n. fro...
output
1
86,809
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,810
13
173,620
Yes
output
1
86,810
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,811
13
173,622
Yes
output
1
86,811
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,812
13
173,624
Yes
output
1
86,812
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,813
13
173,626
Yes
output
1
86,813
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,814
13
173,628
No
output
1
86,814
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,815
13
173,630
No
output
1
86,815
13
173,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,816
13
173,632
No
output
1
86,816
13
173,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 graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other ed...
instruction
0
86,817
13
173,634
No
output
1
86,817
13
173,635
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,033
13
174,066
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` #code by aanchaltiwari__ def dfs(x, y, color): visited = [False for i in range(n + 1)] visited[x] = True stack = [x] while stack: node = stack.pop() for child, childcolor in g[node]: if visited[child] == Fa...
output
1
87,033
13
174,067
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,034
13
174,068
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` def find(c, x): p = dsu[c] if x == p[x]: return x return find(c, p[x]) def union(c, x, y): x = find(c, x) y = find(c, y) if x == y: return p = dsu[c] p[x] = y n, m = map(int, input().split()) dsu = [[...
output
1
87,034
13
174,069
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,035
13
174,070
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` class CodeforcesTask505BSolution: def __init__(self): self.result = '' self.n_m = [] self.edges = [] self.q = 0 self.queries = [] def read_input(self): self.n_m = [int(x) for x in input().split...
output
1
87,035
13
174,071
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,036
13
174,072
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` class Union: def __init__(self, size): self.ancestor = [i for i in range(size+1)] def find(self, node): if self.ancestor[node] == node: return node self.ancestor[node] = self.find(self.ancestor[node]) ...
output
1
87,036
13
174,073
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,037
13
174,074
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 #def input(): return sys.stdin.readline().strip() input = iter(sys.s...
output
1
87,037
13
174,075
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,038
13
174,076
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` def main(): def dfs(index, color): visited[index] = True for p in adj[index]: if not visited[p[0]] and p[1] == color: dfs(p[0], color) n, m = map(int, input().split()) adj = [[] for _ in range(...
output
1
87,038
13
174,077
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,039
13
174,078
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` n,m=map(int,input().split()) g=[[] for _ in range(n)] for _ in range(m): a,b,c=map(int,input().split()) g[a-1].append((b-1,c-1)) g[b-1].append((a-1,c-1)) def dfs(x,c,t): if x==t:return True v[x]=1 for j in g[x]: if j[1...
output
1
87,039
13
174,079
Provide tags and a correct Python 3 solution for this coding contest problem. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the f...
instruction
0
87,040
13
174,080
Tags: brute force, dfs and similar, dsu, graphs Correct Solution: ``` from sys import stdin,stdout input = stdin.readline def main(): n, m = map(int,input().split()) sets = [list(range(n+1)) for i in range(m)] sizes = [[1]*(n+1) for i in range(m)] def get(a,ind): if sets[ind][a] != a: ...
output
1
87,040
13
174,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,041
13
174,082
Yes
output
1
87,041
13
174,083
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,042
13
174,084
Yes
output
1
87,042
13
174,085
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,043
13
174,086
Yes
output
1
87,043
13
174,087
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,044
13
174,088
Yes
output
1
87,044
13
174,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,045
13
174,090
No
output
1
87,045
13
174,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,046
13
174,092
No
output
1
87,046
13
174,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,047
13
174,094
No
output
1
87,047
13
174,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai a...
instruction
0
87,048
13
174,096
No
output
1
87,048
13
174,097
Provide a correct Python 3 solution for this coding contest problem. For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * The route must go through every edge at least once. Constr...
instruction
0
87,494
13
174,988
"Correct Solution: ``` #中国人郵便問題 import sys input = sys.stdin.readline INF = float('inf') v, e = map(int, input().split()) adj = [[INF]*v for _ in range(v)] for i in range(v): adj[i][i] = 0 odd_vertices = [0]*v total_d = 0 for _ in range(e): s, t, d = map(int, input().split()) adj[s][t] = adj[t][s] = min...
output
1
87,494
13
174,989
Provide a correct Python 3 solution for this coding contest problem. For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * The route must go through every edge at least once. Constr...
instruction
0
87,495
13
174,990
"Correct Solution: ``` def warshall_floyd(distance_table, point_size): for k in range(point_size): for i in range(point_size): for j in range(point_size): if distance_table[i][j] > distance_table[i][k] + distance_table[k][j]: distance_table[i][j] = distance_ta...
output
1
87,495
13
174,991