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.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance between s and t in the spanning tree.
Given a gra... | instruction | 0 | 94,617 | 13 | 189,234 |
Tags: combinatorics, dfs and similar, graphs, math, shortest paths, trees
Correct Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
n,m = map(int,input().split())
MOD = 998244353
adjList = []
dist = []
ans = []
for _ in range(n):
adjLis... | output | 1 | 94,617 | 13 | 189,235 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance between s and t in the spanning tree.
Given a gra... | instruction | 0 | 94,618 | 13 | 189,236 |
Tags: combinatorics, dfs and similar, graphs, math, shortest paths, trees
Correct Solution:
```
import io
import os
from collections import deque
def solve(N, M, edges):
graph = [[] for i in range(N)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def bfs(source):
q = de... | output | 1 | 94,618 | 13 | 189,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance betw... | instruction | 0 | 94,619 | 13 | 189,238 |
No | output | 1 | 94,619 | 13 | 189,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance betw... | instruction | 0 | 94,620 | 13 | 189,240 |
No | output | 1 | 94,620 | 13 | 189,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance betw... | instruction | 0 | 94,621 | 13 | 189,242 |
No | output | 1 | 94,621 | 13 | 189,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We define a spanning tree of a graph to be a BFS tree rooted at vertex s if and only if for every node t the shortest distance between s and t in the graph is equal to the shortest distance betw... | instruction | 0 | 94,622 | 13 | 189,244 |
No | output | 1 | 94,622 | 13 | 189,245 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The root of the tree is node 1.
This tree has a speci... | instruction | 0 | 94,729 | 13 | 189,458 |
Tags: data structures, dfs and similar, trees
Correct Solution:
```
class BIT():
"""区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する
add: 区間[begin, end)にvalを加える
get_val: i番目(0-indexed)の値を求める
"""
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def get_val(self, i):
i = i... | output | 1 | 94,729 | 13 | 189,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The roo... | instruction | 0 | 94,730 | 13 | 189,460 |
No | output | 1 | 94,730 | 13 | 189,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The roo... | instruction | 0 | 94,731 | 13 | 189,462 |
No | output | 1 | 94,731 | 13 | 189,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The roo... | instruction | 0 | 94,732 | 13 | 189,464 |
No | output | 1 | 94,732 | 13 | 189,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value ai. The roo... | instruction | 0 | 94,733 | 13 | 189,466 |
No | output | 1 | 94,733 | 13 | 189,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,750 | 13 | 189,500 |
Tags: dp, implementation, trees
Correct Solution:
```
n,v,d=list(map(int,input().split()))
dp=[[0]*2 for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
for k in range(1,min(i,v)+1):
dp[i][0]+=dp[i-k][0]
if k>=d:
dp[i][1]+=dp[i-k][0]
else:
dp[i][1]+=dp[i-k][1]
prin... | output | 1 | 94,750 | 13 | 189,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,751 | 13 | 189,502 |
Tags: dp, implementation, trees
Correct Solution:
```
mod = 10**9+7
def countWays(arr, m, N,d):
count = [0 for i in range(N + 1)]
count[0] = 1
for i in range(1, N + 1):
for j in range(m):
if (i >= arr[j]) and arr[j]<d:
count[i] += count[i - arr[j]]
cou... | output | 1 | 94,751 | 13 | 189,503 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,752 | 13 | 189,504 |
Tags: dp, implementation, trees
Correct Solution:
```
def dp(curr, least, k, total, loc=0):
global d
if curr == total: return int(least == 0)
if d[curr][int(least==0)] != -1: return d[curr][int(least==0)]
for i in range(1, k+1):
if curr+i > total: break
loc+= dp(curr+i, 0 if least <= i else least, k, total)
d[... | output | 1 | 94,752 | 13 | 189,505 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,753 | 13 | 189,506 |
Tags: dp, implementation, trees
Correct Solution:
```
mod=int(1e9+7)
n,k,d=map(int,input().split())
dp=[0 for i in range(n+k+1)]
dp[0]=1
for i in range(n+1):
for j in range(1,k+1):
dp[i+j]+=dp[i]
dp[i+j]%=mod
dp2=[0 for i in range(n+k+1)]
dp2[0]=1
for i in range(n+1):
for j in range(1,d)... | output | 1 | 94,753 | 13 | 189,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,754 | 13 | 189,508 |
Tags: dp, implementation, trees
Correct Solution:
```
n, k, d = [int(x) for x in input().split()]
z = [[1], [1]]
for i in range(1, n + 1):
z[0].append(sum(z[0][max(i-d+1, 0):]))
z[1].append(sum(z[1][max(i-k, 0):]))
print((z[1][-1] - z[0][-1]) % (10**9+7))
``` | output | 1 | 94,754 | 13 | 189,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,755 | 13 | 189,510 |
Tags: dp, implementation, trees
Correct Solution:
```
N,K,D=map(int,input().split())
mod=10**9+7
dpK=[0 for i in range(N+1)]
dpK[0]=1
for i in range(1,N+1):
for j in range(1,K+1):
if i>=j:
dpK[i]+=dpK[i-j]
dpK[i]%=mod
dp=[0 for i in range(N+1)]
dp[0]=1
for i in range(1,N+1):
for j in ... | output | 1 | 94,755 | 13 | 189,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,756 | 13 | 189,512 |
Tags: dp, implementation, trees
Correct Solution:
```
n, k, d = map(int, input().split())
dp = [[0 for i in range(2)] for j in range(n + 10)]
dp[0][0] = 1
MOD = int(1e9) + 7
for i in range(1, n + 1):
for j in range(1, min(d - 1, n) + 1):
dp[i][0] += dp[i - j][0] % MOD
for j in range(1, min(d - 1, n) ... | output | 1 | 94,756 | 13 | 189,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
* each vertex has exactly k ch... | instruction | 0 | 94,757 | 13 | 189,514 |
Tags: dp, implementation, trees
Correct Solution:
```
import sys
from math import log2,floor,ceil,sqrt,gcd
# import bisect
# from collections import deque
# sys.setrecursionlimit(7*10**4)
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.s... | output | 1 | 94,757 | 13 | 189,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,758 | 13 | 189,516 |
Yes | output | 1 | 94,758 | 13 | 189,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,759 | 13 | 189,518 |
Yes | output | 1 | 94,759 | 13 | 189,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,760 | 13 | 189,520 |
Yes | output | 1 | 94,760 | 13 | 189,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,761 | 13 | 189,522 |
Yes | output | 1 | 94,761 | 13 | 189,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,762 | 13 | 189,524 |
No | output | 1 | 94,762 | 13 | 189,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,763 | 13 | 189,526 |
No | output | 1 | 94,763 | 13 | 189,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,764 | 13 | 189,528 |
No | output | 1 | 94,764 | 13 | 189,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite roote... | instruction | 0 | 94,765 | 13 | 189,530 |
No | output | 1 | 94,765 | 13 | 189,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,942 | 13 | 189,884 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
n,k=list(map(int,input().strip().split(' ')))
import math
L=math.ceil((n-(k+1))/(k))
remain=(n-(k+1))%(k)
if (n-(k+1))%(k)==0:
remain+=k
#print(L,remain,'L,remain')
if remain%(k)==1:
print(2*(L)+1)
else:
print(2*(L+1))
... | output | 1 | 94,942 | 13 | 189,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,943 | 13 | 189,886 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
inp = [ int(x) for x in input().split() ]
n = inp[0]
k = inp[1]
mainLen = (n-1) // k
nodeLeft = (n-1) % k
if nodeLeft == 0:
print(mainLen*2)
elif nodeLeft == 1:
print(mainLen*2 + 1)
else:
print(mainLen*2 + 2)
for i in rang... | output | 1 | 94,943 | 13 | 189,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,944 | 13 | 189,888 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
import sys
def main():
n,k = map(int,sys.stdin.readline().split())
a = n-k
if a ==1:
print(2)
for i in range(k):
print(1,i+2)
elif a > k+1 :
l = ((a-1)//k +1)*2
if (a-1)%k>1:... | output | 1 | 94,944 | 13 | 189,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,945 | 13 | 189,890 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
n, k = map(int, input().split())
div = (n - 1) // k
rem = (n - 1) % k
if rem == 0:
print(div * 2)
elif rem == 1:
print(2 * div + 1)
else:
print(2 * (div + 1))
j = 2
rest = k - rem
while rem > 0:
print(1, j)
for i in r... | output | 1 | 94,945 | 13 | 189,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,946 | 13 | 189,892 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
from sys import stdin, stdout
from collections import deque
def bfs(v):
ans = 0
visit[v] = 1
queue = deque()
queue.append((v, 0))
while (queue):
v, dist = queue.popleft()
ans = max(... | output | 1 | 94,946 | 13 | 189,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,947 | 13 | 189,894 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
n, k = map(int, input().split())
reb = n - 1
our = reb // k
if reb % k == 0:
eps = 0
elif reb % k == 1:
eps = 1
else:
eps = 2
print(our * 2 + eps)
next = 2
big = reb % k
for i in range(big):
prev = 1
for j in range(ou... | output | 1 | 94,947 | 13 | 189,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,948 | 13 | 189,896 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
n,k = map(int,input().split())
n -= 1
val = n//k
div = n%k
i = 2
if div==0:
print(val*2)
elif div==1:
print(val*2+1)
else:
print((val+1)*2)
for a in range(k):
print(1,i)
for j in range(val-1):
print(i,i+1)
... | output | 1 | 94,948 | 13 | 189,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exact... | instruction | 0 | 94,949 | 13 | 189,898 |
Tags: constructive algorithms, greedy, implementation, trees
Correct Solution:
```
nodes, exits = [int(x) for x in input().split()]
nonExits = nodes - exits
nonE = list(range(exits + 1, nodes + 1))
#1 -> exits + 1 :: lopud
#exits + 1 -> nodes + 1 :: mitte lopud
nonStart = exits + 1
an = []
exitList = []
for i in... | output | 1 | 94,949 | 13 | 189,899 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,147 | 13 | 190,294 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
graph = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
def check():
stack = [0]
checked = [False]*N
ne... | output | 1 | 95,147 | 13 | 190,295 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,148 | 13 | 190,296 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10 ** 6)
def dfs(v, p, aaa):
if len(links[v]) == 1:
return aaa[v]
children = []
for u in links[v]:
if u == p:
continue
result = dfs(u, v, aaa)
if result == -1:
return -1
children.appen... | output | 1 | 95,148 | 13 | 190,297 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,149 | 13 | 190,298 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(input())
A = list(map(int,input().split()))
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for a,b in AB:
a,b = a-1,b-1
es[a].append(b)
es[b].append(a)
r = -1
for i in r... | output | 1 | 95,149 | 13 | 190,299 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,150 | 13 | 190,300 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
A = [int(x) for x in input().split()]
UV = [[int(x)-1 for x in row.split()] for row in sys.stdin.readlines()]
if N == 2:
x,y = A
answer = 'YES' if x == y else 'NO'
print(answer)
exit()
graph = [... | output | 1 | 95,150 | 13 | 190,301 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,151 | 13 | 190,302 |
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def readln(ch):
_res = list(map(int,str(input()).split(ch)))
return _res
n = int(input())
a = readln(' ')
e = [set([]) for i in range(0,n+1)]
for i in range(1,n):
s = readln(' ')
e[s[0]].add(s[1])
e[s[1]].add(s[0])
rt = 1
now = ... | output | 1 | 95,151 | 13 | 190,303 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,152 | 13 | 190,304 |
"Correct Solution:
```
def get_par(tree: list, root: int) -> list:
"""根付き木の頂点それぞれの親を求める"""
n = len(tree)
visited = [False] * n
visited[root] = True
par = [-1] * n
stack = [root]
while stack:
v = stack.pop()
for nxt_v in tree[v]:
if visited[nxt_v]:
... | output | 1 | 95,152 | 13 | 190,305 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,153 | 13 | 190,306 |
"Correct Solution:
```
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
ns = defaultdict(set)
for i in range(n-1):
u,v = map(int, inp... | output | 1 | 95,153 | 13 | 190,307 |
Provide a correct Python 3 solution for this coding contest problem.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possible to remove all the stones from the vertices by repeat... | instruction | 0 | 95,154 | 13 | 190,308 |
"Correct Solution:
```
def examA():
N = I()
A = LI()
ans = "YES"
cur = 0
for a in A:
if a%2==1:
cur +=1
if cur%2==1:
ans = "NO"
print(ans)
return
def examB():
N = I()
A = LI()
ans = "YES"
sumA = sum(A)
oneA = (1+N)*N//2
if sumA%oneA!=0... | output | 1 | 95,154 | 13 | 190,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,155 | 13 | 190,310 |
Yes | output | 1 | 95,155 | 13 | 190,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,156 | 13 | 190,312 |
Yes | output | 1 | 95,156 | 13 | 190,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,157 | 13 | 190,314 |
Yes | output | 1 | 95,157 | 13 | 190,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,158 | 13 | 190,316 |
Yes | output | 1 | 95,158 | 13 | 190,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,159 | 13 | 190,318 |
No | output | 1 | 95,159 | 13 | 190,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,160 | 13 | 190,320 |
No | output | 1 | 95,160 | 13 | 190,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.
Currently, there are A_i stones placed on vertex i. Determine whether it is possi... | instruction | 0 | 95,161 | 13 | 190,322 |
No | output | 1 | 95,161 | 13 | 190,323 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.