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. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at the node 1 and he records 1 on his notebook. He c...
instruction
0
85,049
13
170,098
Tags: data structures, dfs and similar, graphs, greedy, shortest paths Correct Solution: ``` from sys import stdin,stdout from itertools import combinations from collections import defaultdict,OrderedDict import math import heapq def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringLi...
output
1
85,049
13
170,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,050
13
170,100
Yes
output
1
85,050
13
170,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,051
13
170,102
Yes
output
1
85,051
13
170,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,052
13
170,104
Yes
output
1
85,052
13
170,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,053
13
170,106
Yes
output
1
85,053
13
170,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,054
13
170,108
No
output
1
85,054
13
170,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,055
13
170,110
No
output
1
85,055
13
170,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,056
13
170,112
No
output
1
85,056
13
170,113
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be represented as a connected graph with n nodes and m bidirectional edges. Initially Bob is at th...
instruction
0
85,057
13
170,114
No
output
1
85,057
13
170,115
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,392
13
170,784
"Correct Solution: ``` # Test ##################################################################################################################### def main(): tree_sLength = int(input()) - 1 tree = {} for i in range(tree_sLength): v1, v2 = map(int, input().split()) tree[v1] = tree.get(v1, ...
output
1
85,392
13
170,785
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,393
13
170,786
"Correct Solution: ``` n = int(input()) t = [0] * n for _ in range(n-1): a, b = input().split(' ') a, b = [int(a), int(b)] t[a-1] += 1 t[b-1] += 1 out = [(e * (e-1)) / 2 for e in t] print(int(sum(out))) ```
output
1
85,393
13
170,787
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,394
13
170,788
"Correct Solution: ``` I=input d=[0]*10010 for _ in '0'*(int(I())-1):x,y=map(int,I().split());d[x]+=1;d[y]+=1 print(sum(i*(i-1)for i in d)//2) ```
output
1
85,394
13
170,789
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,395
13
170,790
"Correct Solution: ``` def computeDegrees(n): degrees = [0 for vertex in range(n)] for edge in range(n-1): v1, v2 = map(int, input().split()) degrees[v1-1] += 1 degrees[v2-1] += 1 return degrees def computeNumberOfLength2Paths(degrees, n): return int(sum(d**2 for d in degrees)/2...
output
1
85,395
13
170,791
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,396
13
170,792
"Correct Solution: ``` def main(): n = int(input()) l = [0] * (n + 1) for _ in range(n - 1): a, b = map(int, input().split()) l[a] += 1 l[b] += 1 res = 0 for x in l: res += x * (x - 1) print(res // 2) if __name__ == '__main__': main() ```
output
1
85,396
13
170,793
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,397
13
170,794
"Correct Solution: ``` n=int(input()) L=[] S=0 for k in range(n): L.append(0) for k in range(n-1): a,b=map(int,input().split()) L[a-1]+=1 L[b-1]+=1 for k in range(n): S+=L[k]*(L[k]-1)/2 print(int(S)) ```
output
1
85,397
13
170,795
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,398
13
170,796
"Correct Solution: ``` def main(): n = int(input()) l = [-1] * (n + 1) for _ in range(n - 1): a, b = map(int, input().split()) l[a] += 1 l[b] += 1 res = 0 for x in filter(None, l): res += x * (x + 1) print(res // 2) if __name__ == '__main__': main() ```
output
1
85,398
13
170,797
Provide a correct Python 3 solution for this coding contest problem. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tree of Life is just a regular undirected tree well-known f...
instruction
0
85,399
13
170,798
"Correct Solution: ``` n = int(input()) d = n * [0] for i in range(n - 1): a, b = map(int, input().split()) d[a - 1] += 1 d[b - 1] += 1 cnt = 0 for i in d: cnt += (i * (i - 1)) // 2 print(cnt) ```
output
1
85,399
13
170,799
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,400
13
170,800
Yes
output
1
85,400
13
170,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,401
13
170,802
Yes
output
1
85,401
13
170,803
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,402
13
170,804
Yes
output
1
85,402
13
170,805
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,403
13
170,806
Yes
output
1
85,403
13
170,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,404
13
170,808
No
output
1
85,404
13
170,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,405
13
170,810
No
output
1
85,405
13
170,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,406
13
170,812
No
output
1
85,406
13
170,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies. On the surface, the Tre...
instruction
0
85,407
13
170,814
No
output
1
85,407
13
170,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. ZS the Coder has a large tree. It can be represented as an undirected connected graph of n vertices numbered from 0 to n - 1 and n - 1 edges between them. There is a single nonzero digit written...
instruction
0
85,408
13
170,816
No
output
1
85,408
13
170,817
Provide tags and a correct Python 3 solution for this coding contest problem. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black su...
instruction
0
85,409
13
170,818
Tags: dp, trees Correct Solution: ``` def main(): n, k = map(int, input().split()) cnt = [[[0] * 21 for _ in (0, 1)] for _ in range(n + 1)] edges, mod = [[] for _ in range(n + 1)], 1000000007 for _ in range(n - 1): u, v = map(int, input().split()) edges[u].append(v) edges[v].appe...
output
1
85,409
13
170,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wa...
instruction
0
85,410
13
170,820
No
output
1
85,410
13
170,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wa...
instruction
0
85,411
13
170,822
No
output
1
85,411
13
170,823
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,759
13
171,518
Tags: trees Correct Solution: ``` import sys input = sys.stdin.readline def getN(): return int(input()) def getList(): return list(map(int, input().split())) from sys import exit n = getN() vertex = [[] for i in range(n)] for i in range(n-1): a, b = getList() vertex[a-1].append(b-1) vertex[b - 1]...
output
1
85,759
13
171,519
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,760
13
171,520
Tags: trees Correct Solution: ``` n = int(input()) deg = [0]*n for i in range(n-1): u, v = map(int, input().split()) deg[u-1] += 1 deg[v-1] += 1 if all(i != 2 for i in deg): print("YES") else: print("NO") # cnt = sum(1 for i in deg if i == 1) # if cnt*(cnt-1)//2 >= n - 1: # print("YES") # els...
output
1
85,760
13
171,521
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,761
13
171,522
Tags: trees Correct Solution: ``` n = int(input()) a = [] for i in range(0,n+9): a.append(0) for i in range(1,n): u,v = map(int,input().split()) a[u] = a[u]+1 a[v] = a[v]+1 flag = 1; for i in range(1,n+1): if a[i]==2: flag = 0 if flag==0: print("NO") else: print("YES") ```
output
1
85,761
13
171,523
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,762
13
171,524
Tags: trees Correct Solution: ``` import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write ...
output
1
85,762
13
171,525
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,763
13
171,526
Tags: trees Correct Solution: ``` n = int(input()) g = [[] for i in range(n+1)] d = [0]*100001 for i in range(n-1): u, v = [int(i) for i in input().split()] g[u].append(v) g[v].append(u) d[u] += 1 d[v] += 1 for i in d: if i == 2: print("NO") break else: print("YES") ```
output
1
85,763
13
171,527
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,764
13
171,528
Tags: trees Correct Solution: ``` n=int(input()) deg=[0]*n for i in range(n-1): u,v=map(int,input().split()) u-=1 v-=1 deg[u]+=1 deg[v]+=1 for d in deg: if d==2: print("NO") exit(0) print("YES") ```
output
1
85,764
13
171,529
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,765
13
171,530
Tags: trees Correct Solution: ``` from sys import stdin input = stdin.readline n = int(input()) degree = [0 for i in range(n+1)] for _ in range(n-1): i, j = [int(i) for i in input().split()] degree[i] += 1 degree[j] += 1 res = False for i in range(1, n+1): if degree[i] == 2: res = True ...
output
1
85,765
13
171,531
Provide tags and a correct Python 3 solution for this coding contest problem. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any...
instruction
0
85,766
13
171,532
Tags: trees Correct Solution: ``` # https://codeforces.com/contest/1189/problem/D1 n = int(input()) g = {} p = {} path = {} flg = True for _ in range(n-1): u,v = map(int, input().split()) if u not in g: g[u] = [] g[u].append(v) if v not in g: g[v] = [] g[v].append(u) ...
output
1
85,766
13
171,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,767
13
171,534
Yes
output
1
85,767
13
171,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,768
13
171,536
Yes
output
1
85,768
13
171,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,769
13
171,538
Yes
output
1
85,769
13
171,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,770
13
171,540
Yes
output
1
85,770
13
171,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,771
13
171,542
No
output
1
85,771
13
171,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,772
13
171,544
No
output
1
85,772
13
171,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,773
13
171,546
No
output
1
85,773
13
171,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is written on ...
instruction
0
85,774
13
171,548
No
output
1
85,774
13
171,549
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,830
13
171,660
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` def oracle(n, start, end): nod = 0 t = n - 1 ii = 0 while start - ii > t*2: if t == 0: nod += 1 break nod += 1 ii += t*2 t -= 1 if t < -10: impo...
output
1
85,830
13
171,661
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,831
13
171,662
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` t = int(input()) def query(i, n, x): if (x % 2 == 1): return i else: return (i + x // 2) for _ in range(t): n, l, r = map(int, input().split()) i = 1 s = 0 includeOne = False if r == n ...
output
1
85,831
13
171,663
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,832
13
171,664
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` import sys input = sys.stdin.buffer.readline for t in range(int(input())): n,l,r = map(int,input().split()) for i in range(l,min(2*(n-2)+1,r) + 1): print('1' if i & 1 else i//2 + 1 , end = ' ') n_set = n set_idx...
output
1
85,832
13
171,665
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,833
13
171,666
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` for _ in range(int(input())): numbers, LEFTs, RIGHTs = map(int, input().split()) KEYSs = 0 GREATS = 0 for i in range(1, numbers+1): if KEYSs + 2 * (numbers-i) >= LEFTs: GREATS = LEFTs-KEYSs-1 break KEYSs += 2 * (numbers-i...
output
1
85,833
13
171,667
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly...
instruction
0
85,834
13
171,668
Tags: constructive algorithms, graphs, greedy, implementation Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def solve(n,l,r): fir,st = 0,1 while st < n: x = 2*(n-st) if fir+x >= l: break fir +...
output
1
85,834
13
171,669