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
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 with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected c...
instruction
0
37,505
13
75,010
No
output
1
37,505
13
75,011
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 with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected c...
instruction
0
37,506
13
75,012
No
output
1
37,506
13
75,013
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,555
13
75,110
"Correct Solution: ``` n=int(input()) ans=[] for i in range(1,n): for j in range(i+1,n+1): ans.append([i,j]) if(n%2==1): m=(n-1)**2//2 for i in range(1,n//2+1): ans.remove([i,n-i]) else: m=n*(n-2)//2 for i in range(1,n//2+1): ans.remove([i,n+1-i]) print(m) for i in ans: print(str(i[0])+" "+str(i...
output
1
37,555
13
75,111
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,556
13
75,112
"Correct Solution: ``` N = int(input()) M = N * (N - 1) // 2 - N // 2 S = N // 2 * 2 + 1 print(M) for i in range(1, N): for j in range(i + 1, N + 1): if i + j == S: continue print(i, j) ```
output
1
37,556
13
75,113
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,557
13
75,114
"Correct Solution: ``` N = int(input()) ans = [] M = N + 1 * (N % 2 == 0) for i in range(1, N + 1): for j in range(i + 1, N + 1): if i + j == M: continue ans.append('{} {}'.format(i, j)) print(len(ans)) print('\n'.join(ans)) ```
output
1
37,557
13
75,115
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,558
13
75,116
"Correct Solution: ``` from itertools import combinations n=int(input()) A=[] num=n if n%2==1 else n+1 for a,b in combinations([j+1 for j in range(n)],2): if a+b!=num:A.append([a,b]) print(len(A)) for i in A:print(*i) ```
output
1
37,558
13
75,117
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,559
13
75,118
"Correct Solution: ``` N = int(input()) cnt = 0 A = [] for u in range(1, N) : for v in range(u+1, N+1) : if u + v == N + (N % 2 != 1) : continue else : cnt += 1 A.append((u, v)) print(cnt) for i in range(cnt) : print(*A[i]) ```
output
1
37,559
13
75,119
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,560
13
75,120
"Correct Solution: ``` N = int(input()) ban = N if N%2 else N+1 ans = [] for i in range(1,N): for j in range(i+1,N+1): if i+j == ban: continue ans.append(str(i) + ' ' + str(j)) print(len(ans)) print(*ans, sep='\n') ```
output
1
37,560
13
75,121
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,561
13
75,122
"Correct Solution: ``` N=int(input()) if N%2==0: print(N*(N-2)//2) for i in range(1,N+1): for j in range(i+1,N+1): if i+j!=N+1: print(i,j) else: print(((N-1)*(N-3))//2+N-1) for i in range(1,N+1): for j in range(i+1,N+1): if i+j!=N: print(i,j) ```
output
1
37,561
13
75,123
Provide a correct Python 3 solution for this coding contest problem. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indic...
instruction
0
37,562
13
75,124
"Correct Solution: ``` N = int(input()) print(N*(N-1)//2 - N//2) if(N%2 == 0): for i in range(1,N): for j in range(i+1,N+1): if(i+j != N+1): print(*[i,j]) else: for i in range(1,N): for j in range(i+1,N+1): if(i+j != N): print(*[i,j]) ```
output
1
37,562
13
75,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,563
13
75,126
Yes
output
1
37,563
13
75,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,564
13
75,128
Yes
output
1
37,564
13
75,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,565
13
75,130
Yes
output
1
37,565
13
75,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,566
13
75,132
Yes
output
1
37,566
13
75,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,567
13
75,134
No
output
1
37,567
13
75,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,568
13
75,136
No
output
1
37,568
13
75,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,569
13
75,138
No
output
1
37,569
13
75,139
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an int...
instruction
0
37,570
13
75,140
No
output
1
37,570
13
75,141
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,784
13
75,568
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` import sys answer = 1 z = True primes = [] for i in range (2, 5 * 10 ** 2): v = True for p in primes: if i % p == 0: v = False if v == True: primes.append(i) n = int(sys.stdin.readline().stri...
output
1
37,784
13
75,569
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,785
13
75,570
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import defaultdict, deque, Counter, OrderedDict import threading def main(): ans = 1 flag = True primes = [] for i in range(2, 500): v =...
output
1
37,785
13
75,571
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,786
13
75,572
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` import math import sys def get_primes(n): result = set() while n % 2 == 0: result.add(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: result.add(i) ...
output
1
37,786
13
75,573
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,787
13
75,574
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` from collections import deque import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def get_primes(n: int): from itertools impor...
output
1
37,787
13
75,575
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,788
13
75,576
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` from sys import stdin, stdout from math import * from heapq import * from collections import * dv=list(range(200002)) for i in range(2,200002): if ((i*i)>=200002): break if (dv[i]==i): j=i while ((i*...
output
1
37,788
13
75,577
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a tree consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of the numbers written on the vertices belonging to ...
instruction
0
37,789
13
75,578
Tags: data structures, dfs and similar, dp, number theory, trees Correct Solution: ``` from collections import deque # from time import time # tt = time() n = int(input()) a = [0] + list(map(int, input().split())) e = [[] for i in range(n + 1)] for i in range(n - 1): u, v = map(int, input().split()) e[u].append(v) ...
output
1
37,789
13
75,579
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 consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of th...
instruction
0
37,790
13
75,580
No
output
1
37,790
13
75,581
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 consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of th...
instruction
0
37,791
13
75,582
No
output
1
37,791
13
75,583
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 consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of th...
instruction
0
37,792
13
75,584
No
output
1
37,792
13
75,585
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 consisting of n vertices. A number is written on each vertex; the number on vertex i is equal to a_i. Let's denote the function g(x, y) as the greatest common divisor of th...
instruction
0
37,793
13
75,586
No
output
1
37,793
13
75,587
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,191
13
76,382
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` #dfs and similar, dsu, graphs, interactive, trees from collections import defaultdict class Graph: def __init__(self): self.graph = defaultdict(list) def addEdge(self, fr, to): self.graph[fr].append(to) self.gra...
output
1
38,191
13
76,383
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,192
13
76,384
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` from collections import defaultdict class Graph: def __init__(self): self.graph=defaultdict(list) def addedge(self,u,v): self.graph[u].append(v) self.graph[v].append(u) def dfs(self,s): stack=[] ...
output
1
38,192
13
76,385
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,193
13
76,386
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` n = int(input()) v = [None] + [int(k) for k in input().split()] p = [k for k in range(n + 1)] ans = n def anc(i): if i == p[i]: return p[i] p[i] = anc(p[i]) return p[i] def join(x, y): global ans px = anc(x) p...
output
1
38,193
13
76,387
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,194
13
76,388
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` visited = [] def dfs(adj,s): visited[s] = True for i in adj[s]: if not visited[i]: dfs(adj,i) n = int(input()) a = list(map(int,input().split())) adj = [] for i in range(n+5): adj.append([]) visited.append(False) for i in range(n): a...
output
1
38,194
13
76,389
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,195
13
76,390
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` n = int(input()) tree = list(range(n+1)) arr = list(map(int,input().split())) def find(st): if tree[st]!=st: tree[st]= find(tree[st]) return tree[st] for i in range(n): tree[find(i+1)] = find(arr[i]) ans = 0 for i in r...
output
1
38,195
13
76,391
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,196
13
76,392
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` #!/usr/bin/python3 n = int(input()) p = list(map(int, input().split())) for i in range(n): p[i] -= 1 ans = 0 for i in range(n): if p[i] == i: ans += 2 elif p[p[i]] == i: ans += 1 print(ans // 2) print(ans, file=__i...
output
1
38,196
13
76,393
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,197
13
76,394
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` def main(): MAXN = int(1e4 + 7) par = [] for i in range(MAXN): par.append(i) def find(i): if i == par[i]: return i return find(par[i]) def union(i, j): p = find(i) q = fin...
output
1
38,197
13
76,395
Provide tags and a correct Python 3 solution for this coding contest problem. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vertex is a valid tree. There is exactly one relat...
instruction
0
38,198
13
76,396
Tags: dfs and similar, dsu, graphs, interactive, trees Correct Solution: ``` #https://codeforces.com/problemset/problem/755/C import sys import math try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass class DisjointSet(): def __init__(self,n): self.pa...
output
1
38,198
13
76,397
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,199
13
76,398
Yes
output
1
38,199
13
76,399
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,200
13
76,400
Yes
output
1
38,200
13
76,401
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,201
13
76,402
Yes
output
1
38,201
13
76,403
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,202
13
76,404
Yes
output
1
38,202
13
76,405
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,203
13
76,406
No
output
1
38,203
13
76,407
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,204
13
76,408
No
output
1
38,204
13
76,409
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,205
13
76,410
No
output
1
38,205
13
76,411
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 edges, where k is some integer. Note that one vert...
instruction
0
38,206
13
76,412
No
output
1
38,206
13
76,413
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,289
13
76,578
Tags: dfs and similar, graphs Correct Solution: ``` import sys input = sys.stdin.readline def get_input(): n, m = [int(x) for x in input().split(' ')] digraph = [[] for _ in range(n + 1)] for _ in range(m): c1, c2 = [int(x) for x in input().split(' ')] digraph[c1].append(c2) return d...
output
1
38,289
13
76,579
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,290
13
76,580
Tags: dfs and similar, graphs Correct Solution: ``` import sys def prepare(): stack = [i for i in range(n) if deg[i] == 0] cnt = 0 while stack: v = stack.pop() cnt += 1 for dest in adj[v]: deg[dest] -= 1 if deg[dest] == 0: stack.append(dest) ...
output
1
38,290
13
76,581
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,291
13
76,582
Tags: dfs and similar, graphs Correct Solution: ``` def dfs(g, u, visited, call_stack): visited[u] = True call_stack.add(u) for v in g[u]: if v in call_stack: return [u, v] if not visited[v]: d = dfs(g, v, visited, call_stack) call_stack.discard(v) ...
output
1
38,291
13
76,583
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,292
13
76,584
Tags: dfs and similar, graphs Correct Solution: ``` have = False cycle_begin, block_u, block_v = -1, -1, -1 g, mark, cycle = [], [], [] def dfs(u): global have, cycle_begin mark[u] = 1 for v in g[u]: if u == block_u and v == block_v: continue if mark[v] == 0: if dfs...
output
1
38,292
13
76,585
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,293
13
76,586
Tags: dfs and similar, graphs Correct Solution: ``` n, m = [int(x) for x in input().split()] a = [[] for i in range(n)] for i in range(m): u, v = [int(x) for x in input().split()] a[u - 1].append(v - 1) color = [0] * n # 0 - white, 1 - grey, 2 - black cycle = [] blocked_u, blocked_v = -1, -1 def dfs(u): g...
output
1
38,293
13
76,587
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. C...
instruction
0
38,294
13
76,588
Tags: dfs and similar, graphs Correct Solution: ``` cycle_begin, block_u, block_v = -1, -1, -1 g, mark, prev, cycle = [], [], [], [] def dfs(u): global cycle_begin mark[u] = 1 for v in g[u]: if u == block_u and v == block_v: continue if mark[v] == 0: prev[v] = u ...
output
1
38,294
13
76,589