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 connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertex...
instruction
0
11,022
13
22,044
Tags: dfs and similar, dsu, graphs, sortings Correct Solution: ``` from sys import stdin from math import inf from collections import defaultdict class disjoinSet(object): def __init__(self,n): self.father = [x for x in range(0,n+1)] self.rank = [0 for x in range(0,n+1)] def setOf(self, x...
output
1
11,022
13
22,045
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertex...
instruction
0
11,023
13
22,046
Tags: dfs and similar, dsu, graphs, sortings Correct Solution: ``` from sys import stdin from math import inf from collections import defaultdict class disjoinSet(object): def __init__(self,n): self.father = [x for x in range(0,n+1)] self.rank = [0 for x in range(0,n+1)] def setOf(self, x...
output
1
11,023
13
22,047
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertex...
instruction
0
11,024
13
22,048
Tags: dfs and similar, dsu, graphs, sortings Correct Solution: ``` from sys import stdin from math import inf from collections import defaultdict class disjoinSet(object): def __init__(self,n): self.father = [x for x in range(0,n+1)] self.rank = [0 for x in range(0,n+1)] def setOf(self, x...
output
1
11,024
13
22,049
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertex...
instruction
0
11,025
13
22,050
Tags: dfs and similar, dsu, graphs, sortings Correct Solution: ``` import sys from math import inf from collections import defaultdict class disjoinSet(object): def __init__(self,n): self.father = [x for x in range(0,n+1)] self.rank = [0 for x in range(0,n+1)] def setOf(self, x): ...
output
1
11,025
13
22,051
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a connected weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the given graph that includes all of the graph's vertex...
instruction
0
11,026
13
22,052
Tags: dfs and similar, dsu, graphs, sortings Correct Solution: ``` from math import inf import operator from collections import defaultdict import sys time = 0 edges = [] ans = {} orig_edges = [] l = {} d = {} f = {} pi = {} visited = {} def process_edges(l, ds): if len(l) == 1: u,v = l[0] b = d...
output
1
11,026
13
22,053
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 weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the give...
instruction
0
11,027
13
22,054
No
output
1
11,027
13
22,055
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 weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the give...
instruction
0
11,028
13
22,056
No
output
1
11,028
13
22,057
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 weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the give...
instruction
0
11,029
13
22,058
No
output
1
11,029
13
22,059
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 weighted undirected graph without any loops and multiple edges. Let us remind you that a graph's spanning tree is defined as an acyclic connected subgraph of the give...
instruction
0
11,030
13
22,060
No
output
1
11,030
13
22,061
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. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or re...
instruction
0
11,314
13
22,628
No
output
1
11,314
13
22,629
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. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or re...
instruction
0
11,315
13
22,630
No
output
1
11,315
13
22,631
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. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or re...
instruction
0
11,316
13
22,632
No
output
1
11,316
13
22,633
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,504
13
23,008
"Correct Solution: ``` n, m = map(int, input().split()) edges = [None] * m for i in range(m): a, b, c = map(int, input().split()) edges[i] = (a-1, b-1, -c) INF = float("inf") d = [INF] * n d[0] = 0 for i in range(n-1): for f, t, c in edges: if d[f] == INF: continue d[t] = min(d[t], d[f] +...
output
1
11,504
13
23,009
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,505
13
23,010
"Correct Solution: ``` N, M = map(int, input().split()) edge = [] for i in range(M): a, b, c = map(int, input().split()) edge.append([a, b, c*-1]) d = [float('inf')] * (N+1) d[1] = 0 for i in range(1, N+1): for e in edge: if (d[e[0]] != float('inf')) & (d[e[1]] > d[e[0]] + e[2]): d[e[1]...
output
1
11,505
13
23,011
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,506
13
23,012
"Correct Solution: ``` n, m = map(int, input().split()) edges = [] for _ in range(m): a, b, c = map(int, input().split()) edges.append((a-1, b-1, -c)) def shortest_path(v, s, edges, inf): d = [inf] * v d[s] = 0 for i in range(2 * n): update = False for frm, to, cost in edges: ...
output
1
11,506
13
23,013
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,507
13
23,014
"Correct Solution: ``` n,m=map(int,input().split()) abc=[tuple(map(int,input().split())) for _ in range(m)] Inf=float('inf') dist=[Inf]*n dist[0]=0 for i in range(n): for a,b,c in abc: a,b,c=a-1,b-1,-c if dist[b] >dist[a]+c: dist[b]=dist[a]+c if i==n-1 and b==n-1: ...
output
1
11,507
13
23,015
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,508
13
23,016
"Correct Solution: ``` # ABC061 D - Score Attack import sys N, M = map(int, input().split()) edge = [list(map(int, input().split())) for _ in range(M)] INF = 1 << 60 cost = [- INF] * (N + 1) cost[1] = 0 for i in range(N): for n, nn, c in edge: if cost[nn] < cost[n] + c: # ベルマンフォード法の性質より、N回目に更新...
output
1
11,508
13
23,017
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,509
13
23,018
"Correct Solution: ``` (n,m),*l=[list(map(int,s.split()))for s in open(0)];d=[0]*2+[9e99]*n for i in range(n*2): for a,b,c in l: if d[b]>d[a]-c:d[b]=[d[a]-c,-9e99][i>n] if i==n:x=d[n] print([-x,'inf'][d[n]!=x]) ```
output
1
11,509
13
23,019
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,510
13
23,020
"Correct Solution: ``` n,m = map(int , input().split()) e = [] for i in range(m): a,b,c = map(int , input().split()) e.append((a-1,b-1,c)) maxdis = [-float('inf') for i in range(n)] maxdis[0] = 0 mugen = False for i in range(2*n): for j in e: st,gl,cost = j if (maxdis[gl] < maxdis[st]+...
output
1
11,510
13
23,021
Provide a correct Python 3 solution for this coding contest problem. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at ve...
instruction
0
11,511
13
23,022
"Correct Solution: ``` def shortest_path(edge,num_v,start): inf = float("inf") d = [-inf for f in range(num_v)] d[start] = 0; for i in range(3000): update = False for e in edge: if (d[e[0]-1] != -inf and d[e[1]-1] < d[e[0]-1] + e[2]): d[e[1]-1] = d[e[0]-1] + e...
output
1
11,511
13
23,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,512
13
23,024
Yes
output
1
11,512
13
23,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,513
13
23,026
Yes
output
1
11,513
13
23,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,514
13
23,028
Yes
output
1
11,514
13
23,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,515
13
23,030
Yes
output
1
11,515
13
23,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,516
13
23,032
No
output
1
11,516
13
23,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,517
13
23,034
No
output
1
11,517
13
23,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,518
13
23,036
No
output
1
11,518
13
23,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this ...
instruction
0
11,519
13
23,038
No
output
1
11,519
13
23,039
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,602
13
23,204
"Correct Solution: ``` import sys,collections N,E,r = tuple(map(int,sys.stdin.readline().split())) # single line with multi param sdw = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(E)) # multi line with multi param #sdw = [[src1 dist1 d1][src1 dist1 d1]...]# vect source1 -> distance1 dista...
output
1
11,602
13
23,205
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,603
13
23,206
"Correct Solution: ``` import sys fin = sys.stdin.readline MAX_NUM = float('inf') def initialize_int(adj, s): """ assume that all vertex in {0, 1, 2, ..., N - 1} """ N = len(adj) d = [MAX_NUM] * N d[s] = 0 parent = [None] * N return d, parent def relax(d, w, source_v, target_v, pare...
output
1
11,603
13
23,207
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,604
13
23,208
"Correct Solution: ``` N,E,r=map(int,input().split()) G=[] for i in range(E): s,t,d=map(int,input().split()) G.append([d,s,t]) def bellman_ford(G,s): INF=10**9 d=[INF]*N d[s]=0 j=0 while(True): update=False for i in range(E): cost,fro,to=G[i] if d[fro]...
output
1
11,604
13
23,209
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,605
13
23,210
"Correct Solution: ``` v,e,r=map(int,input().split()) d=[float("INF")]*v edges=[[] for i in range(v)] for i in range(e): a,*s=map(int,input().split()) edges[a].append(s) d[r]=0 from collections import deque #pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす) for i in range(v+2): f=False ...
output
1
11,605
13
23,211
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,606
13
23,212
"Correct Solution: ``` INF = float("inf") def bellman_ford(edges, num_v, sv): #グラフの初期化 dist = [INF for i in range(num_v)] dist[sv]=0 #辺の緩和 for i in range(num_v): for edge in edges: s, t, d = edge[0], edge[1], edge[2] if dist[s] != INF and dist[t] > dist[s] + d:...
output
1
11,606
13
23,213
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,607
13
23,214
"Correct Solution: ``` def main(): nvertices, nedges, s = map(int, input().split()) E = [] for i in range(nedges): u, v, w = map(int, input().split()) E.append((u, v, w)) INF = 1000000000 d = [INF] * nvertices d[s] = 0 for i in range(nvertices - 1): for u, v, w in E:...
output
1
11,607
13
23,215
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,608
13
23,216
"Correct Solution: ``` # !/usr/bin/env python # -*- coding: utf-8 -*- """ input: 4 5 1 0 1 2 0 2 3 1 2 -5 1 3 1 2 3 2 output: INF 0 -5 -3 OR input: 4 6 0 0 1 2 0 2 3 1 2 -5 1 3 1 2 3 2 3 1 0 output: NEGATIVE CYCLE """ import sys from math import isinf def generate_adj_table(_v_info): for each in _v_info: ...
output
1
11,608
13
23,217
Provide a correct Python 3 solution for this coding contest problem. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the n...
instruction
0
11,609
13
23,218
"Correct Solution: ``` V,E,r = map(int,input().split()) # adj_list = [ [] for _ in range(V)] INF = float('inf') edges = [] for _ in range(E): s,d,c = map(int, input().split()) edges.append([s,d,c]) dist = [INF] * V dist[r] = 0 for _ in range(V-1): for s,d,c in edges: # import pdb; pdb.set_trace() if di...
output
1
11,609
13
23,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,610
13
23,220
Yes
output
1
11,610
13
23,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,611
13
23,222
Yes
output
1
11,611
13
23,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,612
13
23,224
Yes
output
1
11,612
13
23,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,613
13
23,226
Yes
output
1
11,613
13
23,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,614
13
23,228
No
output
1
11,614
13
23,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,615
13
23,230
No
output
1
11,615
13
23,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,616
13
23,232
No
output
1
11,616
13
23,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Constraints * 1 ≤ |V| ≤ 1000 * 0 ≤ |E| ≤ 2000 * -10000 ≤ di ≤ 10000 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E) and the source r. |V| |E| r...
instruction
0
11,617
13
23,234
No
output
1
11,617
13
23,235
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,618
13
23,236
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` from math import gcd n, m = [int(x) for x in input().strip().split()] if n-1 > m: print('Impossible') exit() edges = [] for i in range(1, n+1): for j in range(i+1, n+1): if gcd(i, j) == 1: edges.app...
output
1
11,618
13
23,237
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,619
13
23,238
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` from math import gcd n,m=map(int,input().split()) l=[] cnt=0 if n>=m+2: print("Impossible") else: for i in range(1,n): l.append([i,i+1]) cnt=cnt+1 if cnt==m: break for i in range(1,n+1)...
output
1
11,619
13
23,239
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,620
13
23,240
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` from array import array from sys import stdin import bisect from bisect import * import itertools from itertools import * def scan_gen(): for line in stdin: yield from iter(line.split()) scan = scan_gen() def nint(): return int(...
output
1
11,620
13
23,241
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,621
13
23,242
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` from math import gcd n,m = map(int,input().split()) if m<n-1: print ("Impossible") exit() ans = [] for i in range(1,n+1): for j in range(i+1,n+1): if gcd(i,j)==1: m -= 1 ans.append((i,j)) if m==0: break if m==0: ...
output
1
11,621
13
23,243
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,622
13
23,244
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` n,m=map(int,input().split()) import math if m<n-1 or m>(n-1)*n//2:print("Impossible");exit() ans=[[1,i] for i in range(2,n+1)] m-=n-1 i=0 b=2 k=b+1 while i<m and b<n: if math.gcd(b,k)==1: i+=1 ans.append([b,k]) k+=1 if k==n+1...
output
1
11,622
13
23,245
Provide tags and a correct Python 3 solution for this coding contest problem. Let's call an undirected graph G = (V, E) relatively prime if and only if for each edge (v, u) ∈ E GCD(v, u) = 1 (the greatest common divisor of v and u is 1). If there is no edge between some pair of vertices v and u then the value of GCD(v...
instruction
0
11,623
13
23,246
Tags: brute force, constructive algorithms, graphs, greedy, math Correct Solution: ``` def gcd(n1,n2): if n2 > n1: return gcd(n2,n1) if n2 == 0: return n1 return gcd(n2,n1%n2) def main(): n,m = map(int,input().split()) if m < n-1: print('Impossible') return ans =...
output
1
11,623
13
23,247