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. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,500
13
135,000
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` # coding: utf-8 from math import log2 def dfs (a): if len(a) == 1: return 1 mask = 1 << int(log2(a[0] ^ a[-1])) for i, v in enumerate(a): if v & mask: break return max(dfs(a[0 : i]), ...
output
1
67,500
13
135,001
Provide tags and a correct Python 3 solution for this coding contest problem. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,501
13
135,002
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` # according to editorial import math # def binary_search(l, target): // this has not been tested # # returns index i such that l[j] < target iff j < i # if l[0] >= target: # return 0 # if l[-1] < t...
output
1
67,501
13
135,003
Provide tags and a correct Python 3 solution for this coding contest problem. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,502
13
135,004
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) def rec(s, i): if len(s) in (0, 1, 2): return len(s) mask = 1 << i a = [] b = [] for one in s: if one & mask: a.appe...
output
1
67,502
13
135,005
Provide tags and a correct Python 3 solution for this coding contest problem. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,503
13
135,006
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` import io import os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def costs(l, bit = 32): if len(l) <= 2: return 0 left = [] right = [] for el in l: if el & (1<<bit):...
output
1
67,503
13
135,007
Provide tags and a correct Python 3 solution for this coding contest problem. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,504
13
135,008
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` n = int(input());a = sorted([int(x) for x in input().split()]) def solve(l, bit): if len(l) <= 1: return 0 if bit == 0: return 0 high = [x ^ (1 << bit) for x in l if x & (1 << bit)];low = [x for x in l if not x & (1...
output
1
67,504
13
135,009
Provide tags and a correct Python 3 solution for this coding contest problem. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find su...
instruction
0
67,505
13
135,010
Tags: binary search, bitmasks, data structures, divide and conquer, dp, trees Correct Solution: ``` class Trie: class TrieNode: def __init__(self) -> None: self.left = None self.right = None self.leaves = 0 self.ends = False def __init__(self, n...
output
1
67,505
13
135,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,506
13
135,012
Yes
output
1
67,506
13
135,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,507
13
135,014
Yes
output
1
67,507
13
135,015
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,508
13
135,016
Yes
output
1
67,508
13
135,017
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,509
13
135,018
No
output
1
67,509
13
135,019
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,510
13
135,020
No
output
1
67,510
13
135,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,511
13
135,022
No
output
1
67,511
13
135,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k writte...
instruction
0
67,512
13
135,024
No
output
1
67,512
13
135,025
Provide tags and a correct Python 3 solution for this coding contest problem. Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node. Before beginning the game...
instruction
0
67,529
13
135,058
Tags: bitmasks, data structures, dfs and similar, dp, games, math, trees Correct Solution: ``` import sys from sys import stdin from collections import deque n,k = map(int,stdin.readline().split()) N,K = n,k lis = [ [] for i in range(N) ] for i in range(N-1): x,y = map(int,stdin.readline().split()) x -= 1 ...
output
1
67,529
13
135,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging...
instruction
0
67,530
13
135,060
No
output
1
67,530
13
135,061
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,642
13
135,284
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` from collections import deque n = int(input()) process = deque() vs = [] for i in range(n): d, s = map(int, input().split()) if d == 1: process.append(i) vs.append((d, s)) edges = [] while process: a = process.popleft() ...
output
1
67,642
13
135,285
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,643
13
135,286
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` n = int(input()) ss = [0] * n degs = [0] * n leaves = [] for i in range(n): degs[i], ss[i] = list(map(int, input().split())) if degs[i] == 1: leaves.append(i) edges = [] while len(leaves) != 0: leaf = leav...
output
1
67,643
13
135,287
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,644
13
135,288
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` def fastio(): import sys from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(la...
output
1
67,644
13
135,289
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,645
13
135,290
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` from sys import stdin,stdout,setrecursionlimit stdin.readline def mp(): return list(map(int, stdin.readline().strip().split())) def it():return int(stdin.readline().strip()) from collections import defaultdict as dd,Counter as...
output
1
67,645
13
135,291
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,646
13
135,292
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` def main(): n, l, ones, j = int(input()), [], [], 0 for i in range(n): degree, s = map(int, input().split()) l.append((degree, s)) j += degree if degree == 1: ones.append(i) ...
output
1
67,646
13
135,293
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,647
13
135,294
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` def main(): n = int(input()) ones, l = set(), [] for i in range(n): degree, s = map(int, input().split()) if degree == 1: ones.add(i) l.append((degree, s)) res = [] while...
output
1
67,647
13
135,295
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,648
13
135,296
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` n=int(input()) l=[] stack=[] for i in range(n): d,s=map(int,input().split()) if d==1: stack.append(i) l.append([d,s]) c=0 edges='' while stack: i=stack.pop(0) d,s=l[i] if d==0: continue ...
output
1
67,648
13
135,297
Provide tags and a correct Python 3 solution for this coding contest problem. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were ...
instruction
0
67,649
13
135,298
Tags: constructive algorithms, data structures, greedy, sortings, trees Correct Solution: ``` n = int(input()) d = [] v = [] for i in range(n): (a, b) = map(int, input().split()) v.append([a, b, i]) g = dict() for i in range(n+20): g[i] = set() for i in v: if i[0] in g: g[i[0]].add(i[2]) el...
output
1
67,649
13
135,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,650
13
135,300
Yes
output
1
67,650
13
135,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,651
13
135,302
Yes
output
1
67,651
13
135,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,652
13
135,304
Yes
output
1
67,652
13
135,305
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,653
13
135,306
Yes
output
1
67,653
13
135,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,654
13
135,308
No
output
1
67,654
13
135,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,655
13
135,310
No
output
1
67,655
13
135,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,656
13
135,312
No
output
1
67,656
13
135,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he...
instruction
0
67,657
13
135,314
No
output
1
67,657
13
135,315
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,752
13
135,504
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` from itertools import accumulate from math import * import os, sys import threading from io import BytesIO from bisect import bisect_left input = BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = list(map...
output
1
67,752
13
135,505
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,753
13
135,506
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` #!/usr/bin/env python3 import sys import threading from bisect import * from itertools import * #def ri(): # return map(int, input().split()) def dfs(v): global d d += 1 dist[d] = w[v] + dist[d-1] add[d] =...
output
1
67,753
13
135,507
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,754
13
135,508
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` #!/usr/bin/env python3 import sys import threading from bisect import * def ri(): return map(int, input().split()) def dfs(v, d, c, w): d += 1 dist[d] = w[v] + dist[d-1] add[d] = 0 for i in c[v]: df...
output
1
67,754
13
135,509
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,755
13
135,510
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` import sys import threading from bisect import * from itertools import * from collections import defaultdict from math import log2 from bisect import bisect_left import os import sys from io import BytesIO, IOBase from types imp...
output
1
67,755
13
135,511
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,756
13
135,512
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` #!/usr/bin/env python3 import sys import threading from bisect import * from itertools import * #def ri(): # return map(int, input().split()) def dfs(v): global d d += 1 dist.append(w[v] + dist[d-1]) add[d...
output
1
67,756
13
135,513
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,757
13
135,514
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` #!/usr/bin/env python3 import sys import threading from bisect import * #def ri(): # return map(int, input().split()) def dfs(v, d, c, w): d += 1 dist[d] = w[v] + dist[d-1] add[d] = 0 for i in c[v]: ...
output
1
67,757
13
135,515
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,758
13
135,516
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` import sys import threading from bisect import * from itertools import * #def ri(): # return map(int, input().split()) def dfs(v): global d d += 1 dist[d] = w[v] + dist[d-1] add[d] = 0 for i in c[v]...
output
1
67,758
13
135,517
Provide tags and a correct Python 3 solution for this coding contest problem. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, differen...
instruction
0
67,759
13
135,518
Tags: binary search, data structures, dfs and similar, graphs, trees Correct Solution: ``` #!/usr/bin/env python3 import sys import threading from bisect import * #def ri(): # return map(int, input().split()) def dfs(v): global d d += 1 dist[d] = w[v] + dist[d-1] add[d] = 0 for i in c[v]: ...
output
1
67,759
13
135,519
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive intege...
instruction
0
67,760
13
135,520
Yes
output
1
67,760
13
135,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive intege...
instruction
0
67,761
13
135,522
No
output
1
67,761
13
135,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive intege...
instruction
0
67,762
13
135,524
No
output
1
67,762
13
135,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive intege...
instruction
0
67,763
13
135,526
No
output
1
67,763
13
135,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive intege...
instruction
0
67,764
13
135,528
No
output
1
67,764
13
135,529
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,160
13
136,320
Tags: dfs and similar, dsu, graphs Correct Solution: ``` inp = input().split() n = int(inp[0]) m = int(inp[1]) def dfs(x): visited.add(x) for y in e[x]: if not y in visited: dfs(y) if n >= 3 and n == m: visited = set() e = [[] for i in range(n + 1)] for i in range(...
output
1
68,160
13
136,321
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,161
13
136,322
Tags: dfs and similar, dsu, graphs Correct Solution: ``` def dfs (num,av): global res; b.add(num) for v in g[num]: if v!=av: if v in b: res += 1; g[v].remove(num) else:b.add(v); dfs(v,num) n,m = map (int,input().split()) g,b,res = [[] for _ in range(n)], set(),0 for _ in range(m)...
output
1
68,161
13
136,323
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,162
13
136,324
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n, m = [int(i) for i in input().split()] c = [int(i) for i in range(n+1)] def find (u): if u == c[u]: return u c[u] = find(c[u]) return c[u] ciclos = 0 for i in range(m): x, y = [int(j) for j in input().split()] x = find(x) y = f...
output
1
68,162
13
136,325
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,163
13
136,326
Tags: dfs and similar, dsu, graphs Correct Solution: ``` from collections import * from sys import stdin def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return list(stdin.readline()[...
output
1
68,163
13
136,327
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,164
13
136,328
Tags: dfs and similar, dsu, graphs Correct Solution: ``` import sys def getroot(lab, u): if lab[u] == -1: return u lab[u] = getroot(lab, lab[u]) return lab[u] def union(lab, cou, a, b): if cou[a] > cou[b]: cou[a] += cou[b] lab[b] = a else: cou[b] += cou[a] l...
output
1
68,164
13
136,329
Provide tags and a correct Python 3 solution for this coding contest problem. ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting info...
instruction
0
68,165
13
136,330
Tags: dfs and similar, dsu, graphs Correct Solution: ``` n,m=map(int,input().split()) a=[[] for _ in range(n+1)] vis=[] for _ in range(m): x,y=map(int,input().split()) a[x].append(y) a[y].append(x) def dfs(x): vis.append(x) for z in a[x]: if not(z in vis): dfs(z) dfs(1) if n<3 o...
output
1
68,165
13
136,331