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. Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to le...
instruction
0
40,052
13
80,104
Tags: constructive algorithms, data structures, graphs Correct Solution: ``` def graph(e): e = [(w, i, b) for i, (w, b) in enumerate(e)] e.sort() g = [None]*len(e) mst = [(w, i) for w, i, b in e if b] for n, (w, i) in enumerate(mst, 2): g[i] = 1, n cm = 0 available = [] for w...
output
1
40,052
13
80,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real ...
instruction
0
40,053
13
80,106
No
output
1
40,053
13
80,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real ...
instruction
0
40,054
13
80,108
No
output
1
40,054
13
80,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real ...
instruction
0
40,055
13
80,110
No
output
1
40,055
13
80,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real ...
instruction
0
40,056
13
80,112
No
output
1
40,056
13
80,113
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through...
instruction
0
40,088
13
80,176
Tags: dfs and similar, dp, trees Correct Solution: ``` import sys input = sys.stdin.buffer.readline from collections import deque n, k = map(int, input().split()) tot_dist = 0 vis = [0]*(n+1) dist = [[[0]*2 for j in range(k)] for i in range(n+1)] adj = [[]for i in range(n+1)] for i in range(n-1): u,v = map(int,inp...
output
1
40,088
13
80,177
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through...
instruction
0
40,089
13
80,178
Tags: dfs and similar, dp, trees Correct Solution: ``` """ #If FastIO not needed, used this and don't forget to strip #import sys, math #input = sys.stdin.readline """ import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left, bisect_right from types import GeneratorType BU...
output
1
40,089
13
80,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree ...
instruction
0
40,090
13
80,180
No
output
1
40,090
13
80,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree ...
instruction
0
40,091
13
80,182
No
output
1
40,091
13
80,183
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree ...
instruction
0
40,092
13
80,184
No
output
1
40,092
13
80,185
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree ...
instruction
0
40,093
13
80,186
No
output
1
40,093
13
80,187
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,429
13
80,858
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` n = int(input()) d = {} for i in range(n-1): u,v = map(int,input().split()) try: d[u].append(v) except: d[u] = [v] try: d[v].append(u) except: d[v] = [u] l = list(map(int,input().split())) f = ...
output
1
40,429
13
80,859
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,430
13
80,860
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` import sys from collections import defaultdict def out(s):return sys.stdout.write(s) n=int(sys.stdin.readline()) dic = defaultdict(set) for i in range(n-1): a,b=map(int,sys.stdin.readline().split()) dic[a].add(b) dic[b].add(a) c=list...
output
1
40,430
13
80,861
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,431
13
80,862
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` import sys from array import array # noqa: F401 from collections import deque def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) adj = [[] for _ in range(n)] for u, v in (map(int, input().split()) for _ in ...
output
1
40,431
13
80,863
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,432
13
80,864
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` import math,sys from collections import Counter,defaultdict def li(): return list(map(int,sys.stdin.readline().split())) def ls(): return list(map(int,list(input()))) def la(): return list(input()) def ii(): return int(input()) def dic(x): retu...
output
1
40,432
13
80,865
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,433
13
80,866
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` """ We can store the neighbors of the nodes in their adjacency lists. After that, we can sort the adjacency lists of all the nodes in the order in which they are present in the input BFS Sequence. Now we can do the standard BFS traversal star...
output
1
40,433
13
80,867
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,434
13
80,868
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` from collections import deque n = int(input()) graph = [set()for i in range(n+1)] for i in range(n-1): x,y =map(int,input().split()) graph[x].add(y) graph[y].add(x) l = list(map(int,input().split())) if(l[0]!=1): print('No') ...
output
1
40,434
13
80,869
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,435
13
80,870
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` n = int(input()) d = {} for i in range(n-1): a,b = map(int,input().split()) try: d[a].append(b); except: d[a] = [b] try: d[b].append(a); except: d[b] = [a] array = list(map(int,input().split())) flag=0; if array[0]==1: i = 1;...
output
1
40,435
13
80,871
Provide tags and a correct Python 3 solution for this coding contest problem. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue](http://gg.gg/queue_en) containing only vertex...
instruction
0
40,436
13
80,872
Tags: dfs and similar, graphs, shortest paths, trees Correct Solution: ``` import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) ...
output
1
40,436
13
80,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,437
13
80,874
Yes
output
1
40,437
13
80,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,438
13
80,876
Yes
output
1
40,438
13
80,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,439
13
80,878
Yes
output
1
40,439
13
80,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,440
13
80,880
Yes
output
1
40,440
13
80,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,441
13
80,882
No
output
1
40,441
13
80,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,442
13
80,884
No
output
1
40,442
13
80,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,443
13
80,886
No
output
1
40,443
13
80,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The [BFS](https://en.wikipedia.org/wiki/Breadth-first_search) algorithm is defined as follows. 1. Consider an undirected graph with vertices numbered from 1 to n. Initialize q as a new [queue...
instruction
0
40,444
13
80,888
No
output
1
40,444
13
80,889
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,543
13
81,086
Tags: brute force, constructive algorithms, trees Correct Solution: ``` # 3/2/2020, 8:23 PM # edited to just edit the parent array import math import sys import operator # note that we will only increase the depth of a node, never decrease def raise_d(parent): # find the deepest depth that has more than one...
output
1
40,543
13
81,087
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,544
13
81,088
Tags: brute force, constructive algorithms, trees Correct Solution: ``` t = int(input()) for T in range(t): n, d = map(int, input().strip().split()) u = (n-1) * n // 2 if d > u: print("NO"); continue l = t = 0 for i in range(1, 1+n): l += t if not i & i+1: t += 1 if d < l: print(...
output
1
40,544
13
81,089
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,545
13
81,090
Tags: brute force, constructive algorithms, trees Correct Solution: ``` for tests in range(int(input())): n, d = map(int,input().split()) upper_bound, lower_bound, lv = n * (n - 1) // 2, 0, 0 for i in range(1, n + 1): if not(i & (i - 1)): lv += 1 lower_bound += lv - 1 if not(...
output
1
40,545
13
81,091
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,546
13
81,092
Tags: brute force, constructive algorithms, trees Correct Solution: ``` from math import ceil,floor,log t=int(input()) for i2 in range(t): n,d=map(int,input().split()) p,dad=0,[0]*(n+1) c=(n*(n-1))//2 for i in range(1,n+1): p+=floor(log(i,2)) if p>d or c<d: print("NO") contin...
output
1
40,546
13
81,093
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,547
13
81,094
Tags: brute force, constructive algorithms, trees Correct Solution: ``` t=int(input()) import math as m def print_tree(l): t=[{'p':None, 'c':[]} for i in range(sum(l))] l2={i:[] for i in range(len(l))} j=0 for i in range(sum(l)): l2[j].append(i+1) if len(l2[j])==l[j]: j+=1 ...
output
1
40,547
13
81,095
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,548
13
81,096
Tags: brute force, constructive algorithms, trees Correct Solution: ``` for tests in range(int(input())): n, d = map(int,input().split()) upper_bound, lower_bound, lv = n * (n - 1) // 2, 0, 0 for i in range(1, n + 1): if not(i & (i - 1)): lv += 1 lower_bound += lv - 1 if not(...
output
1
40,548
13
81,097
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,549
13
81,098
Tags: brute force, constructive algorithms, trees Correct Solution: ``` #Pye from os import path from sys import stdin, stdout if path.exists('inp.txt'): stdin = open("inp.txt", "r") maxn = 5005 q = int(stdin.readline()) for _ in range(q): n, d = map(int, stdin.readline().split()) a = [0 for i in range(maxn)] ...
output
1
40,549
13
81,099
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is a connected graph without cycles. A rooted tree...
instruction
0
40,550
13
81,100
Tags: brute force, constructive algorithms, trees Correct Solution: ``` t=int(input()) pows=[2**i for i in range(21)] for _ in range(t): n,d=map(int,input().split()) mins=0 for k in range(20): if pows[k+1]<=n: mins+=k*pows[k] else: mins+=k*(n-(pows[k]-1)) break maxs=n*(n-1)//2 if d<m...
output
1
40,550
13
81,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,551
13
81,102
Yes
output
1
40,551
13
81,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,552
13
81,104
Yes
output
1
40,552
13
81,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,553
13
81,106
Yes
output
1
40,553
13
81,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,554
13
81,108
Yes
output
1
40,554
13
81,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,555
13
81,110
No
output
1
40,555
13
81,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,556
13
81,112
No
output
1
40,556
13
81,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,557
13
81,114
No
output
1
40,557
13
81,115
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d. A tree is ...
instruction
0
40,558
13
81,116
No
output
1
40,558
13
81,117
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,575
13
81,150
Tags: dfs and similar, dp, graphs Correct Solution: ``` n,m = map(int, input().split()) x, y, z = map(int, input().split()) ed = [] for _ in range(n): ed.append([]) for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 ed[a].append(b) ed[b].append(a) cl = [0] * n def bfs(v, c): ...
output
1
40,575
13
81,151
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,576
13
81,152
Tags: dfs and similar, dp, graphs Correct Solution: ``` import sys;input=sys.stdin.readline N, M = map(int, input().split()) n1, n2, n3 = map(int, input().split()) G = [set() for _ in range(N+1)] for _ in range(M): u, v = map(int, input().split()) G[u].add(v) G[v].add(u) cl = [-1 for _ in range(N+1)] vs = ...
output
1
40,576
13
81,153
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,577
13
81,154
Tags: dfs and similar, dp, graphs Correct Solution: ``` import sys input = sys.stdin.buffer.readline N, M = map(int, input().split()) n1, n2, n3 = map(int, input().split()) graph = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) de...
output
1
40,577
13
81,155
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,578
13
81,156
Tags: dfs and similar, dp, graphs Correct Solution: ``` from sys import stdin, gettrace from collections import deque if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): n,m = map(int, input().split()) n1, n2, n3 = map(int, input...
output
1
40,578
13
81,157
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,579
13
81,158
Tags: dfs and similar, dp, graphs Correct Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys from collections import deque input = sys.stdin.buffer.readline N, M = map(int, input().split()) n1, n2, n3 = map(int, input().split()) adj = [[] for _ in range(N+1)] for _ in rang...
output
1
40,579
13
81,159
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,580
13
81,160
Tags: dfs and similar, dp, graphs Correct Solution: ``` import sys input = sys.stdin.readline from collections import * def bfs(s): color[s] = 1 q = deque([s]) d[s][1].append(s) while q: v = q.popleft() for nv in G[v]: if color[nv]==0: color[nv]...
output
1
40,580
13
81,161
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an undirected graph without self-loops or multiple edges which consists of n vertices and m edges. Also you are given three integers n_1, n_2 and n_3. Can you label each vertex with one of three numbers 1, 2 or 3 in such way, ...
instruction
0
40,581
13
81,162
Tags: dfs and similar, dp, graphs Correct Solution: ``` import os import sys if os.path.exists('/mnt/c/Users/Square/square/codeforces'): f = iter(open('E.txt').readlines()) def input(): return next(f).strip() # input = lambda: sys.stdin.readline().strip() else: input = lambda: sys.stdin.readli...
output
1
40,581
13
81,163