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 a correct Python 3 solution for this coding contest problem.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following information for each node u of T:
* node ID of u
* parent of u... | instruction | 0 | 51,282 | 13 | 102,564 |
"Correct Solution:
```
class Node:
def __init__(self, parent, left, right):
self.parent, self.left, self.right = parent, left, right
N = int(input())
T = [Node(None, None, None) for _ in range(N)]
for t in T:
i, left, right = map(int, input().split())
if left != -1:
T[i].left = left
... | output | 1 | 51,282 | 13 | 102,565 |
Provide a correct Python 3 solution for this coding contest problem.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following information for each node u of T:
* node ID of u
* parent of u... | instruction | 0 | 51,283 | 13 | 102,566 |
"Correct Solution:
```
N = int(input())
class Node():
def __init__(self, parent = -1, left = -1, right = -1):
self.parent = parent
self.left = left
self.right = right
binary_tree = [Node() for _ in range(N)]
for _ in range(N):
node_input = input()
id, left, right = map(int, node_in... | output | 1 | 51,283 | 13 | 102,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,284 | 13 | 102,568 |
Yes | output | 1 | 51,284 | 13 | 102,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,285 | 13 | 102,570 |
Yes | output | 1 | 51,285 | 13 | 102,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,286 | 13 | 102,572 |
Yes | output | 1 | 51,286 | 13 | 102,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,287 | 13 | 102,574 |
Yes | output | 1 | 51,287 | 13 | 102,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,288 | 13 | 102,576 |
No | output | 1 | 51,288 | 13 | 102,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,289 | 13 | 102,578 |
No | output | 1 | 51,289 | 13 | 102,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,290 | 13 | 102,580 |
No | output | 1 | 51,290 | 13 | 102,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A rooted binary tree is a tree with a root node in which every node has at most two children.
Your task is to write a program which reads a rooted binary tree T and prints the following informa... | instruction | 0 | 51,291 | 13 | 102,582 |
No | output | 1 | 51,291 | 13 | 102,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,336 | 13 | 102,672 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
import sys
n,s=map(int,input().split())
if 2*s>n*(n+1) or s<2*n-1:
print('NO')
sys.exit()
for i in range(n,-1,-1):
if i==0:
branch=1
break
tmp=0
tmpn=n
j=1
while tmpn-i**(j-1)>=0:
tmp+=j*... | output | 1 | 51,336 | 13 | 102,673 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,337 | 13 | 102,674 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
import math
def f(n,k):
if k==1:
return (n*(n+1))//2
a=math.floor(math.log(n,k))
b=sum(k**i for i in range(a+1))
c=sum((i+1)*k**i for i in range(a+1))
if n<b:
return c-(b-n)*(a+... | output | 1 | 51,337 | 13 | 102,675 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,338 | 13 | 102,676 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
import math
EPS = 1e-6
hhh = None
def solve():
n, M = [int(x) for x in input().split()]
if out_of_solution_bounds(n, M):
print('No')
return
b = find_optimal_b(n, M)
heights = f... | output | 1 | 51,338 | 13 | 102,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,339 | 13 | 102,678 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
def clc(mid):
sm , i , cp = 0 , 1 , n
cur = 1
while(cp + 1 > cur):
sm = sm + i * cur
i+= 1
cp -= cur
cur = cur * mid
return sm + i * cp
n , s = map(int,input().spli... | output | 1 | 51,339 | 13 | 102,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,340 | 13 | 102,680 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
def good(max_branch, s, n):
nodes = 0
can = 1
lowest_s = 0
depth = 1
while(nodes < n):
added = min(n - nodes, can)
lowest_s += added * depth
nodes += added
can *... | output | 1 | 51,340 | 13 | 102,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, where the root has index 1. Every other vertex has... | instruction | 0 | 51,341 | 13 | 102,682 |
Tags: binary search, constructive algorithms, dfs and similar, graphs, greedy, trees
Correct Solution:
```
n, s = map(int, input().split())
if not 2*n - 1 <= s <= n * (n+1) // 2:
print('No')
exit()
print('Yes')
def ok(d):
dep, cur, sum, m = 2, 1, 1, 0
while cur + m < n:
m += cur
cur = m... | output | 1 | 51,341 | 13 | 102,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, whe... | instruction | 0 | 51,342 | 13 | 102,684 |
No | output | 1 | 51,342 | 13 | 102,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, whe... | instruction | 0 | 51,343 | 13 | 102,686 |
No | output | 1 | 51,343 | 13 | 102,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, whe... | instruction | 0 | 51,344 | 13 | 102,688 |
No | output | 1 | 51,344 | 13 | 102,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Misha walked through the snowy forest and he was so fascinated by the trees to decide to draw his own tree!
Misha would like to construct a rooted tree with n vertices, indexed from 1 to n, whe... | instruction | 0 | 51,345 | 13 | 102,690 |
No | output | 1 | 51,345 | 13 | 102,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interac... | instruction | 0 | 51,514 | 13 | 103,028 |
No | output | 1 | 51,514 | 13 | 103,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interac... | instruction | 0 | 51,515 | 13 | 103,030 |
No | output | 1 | 51,515 | 13 | 103,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interac... | instruction | 0 | 51,516 | 13 | 103,032 |
No | output | 1 | 51,516 | 13 | 103,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interac... | instruction | 0 | 51,517 | 13 | 103,034 |
No | output | 1 | 51,517 | 13 | 103,035 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note that the only difference between the easy and hard version is the constraint on the number of queries. You can make hacks only if all versions of the problem are solved.
This is an interac... | instruction | 0 | 51,518 | 13 | 103,036 |
No | output | 1 | 51,518 | 13 | 103,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,557 | 13 | 103,114 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from collections import deque
T = int(input())
def solve(E, W):
nodes = {idx: (w, []) for idx, w in weights.items()}
for u, v in E:
nodes[u][1].append(v)
nodes[v][1].append(u)
layers = []
visited = set([1])
parents = {... | output | 1 | 51,557 | 13 | 103,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,558 | 13 | 103,116 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
#import sys
#input = lambda: sys.stdin.readline().rstrip()
from collections import deque
T = int(input())
for _ in range(T):
N = int(input())
X = [[] for i in range(N)]
pp = [int(a)-1 for a in input().split()]
for i, p in enumerate(pp, 1):
... | output | 1 | 51,558 | 13 | 103,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,559 | 13 | 103,118 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
import sys
import collections
def read_ints():
return [int(i) for i in sys.stdin.readline().strip().split()]
def read_int():
return int(sys.stdin.readline().strip())
class Node:
def __init__(self, id, number, parent):
self.id = id
... | output | 1 | 51,559 | 13 | 103,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,560 | 13 | 103,120 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from sys import stdin
import sys
from collections import deque
def NC_Dij(lis,start):
ret = [float("inf")] * len(lis)
ret[start] = 0
q = deque([start])
plis = [i for i in range(len(lis))]
while len(q) > 0:
now = q.popleft()
... | output | 1 | 51,560 | 13 | 103,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,561 | 13 | 103,122 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from collections import defaultdict
def main():
cases = int(input())
ans_list = []
for _ in range(cases):
n = int(input())
dp = [0 for i in range(n+1)]
graph = defaultdict(set)
edges = list(map(int, input().split... | output | 1 | 51,561 | 13 | 103,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,562 | 13 | 103,124 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from collections import deque
for _ in range(int(input())):
N = int(input());X = [[] for i in range(N)];pp = [int(a)-1 for a in input().split()]
for i, p in enumerate(pp, 1):X[i].append(p);X[p].append(i)
P = [-1] * N;Q = deque([0]);R = [];Y = [[... | output | 1 | 51,562 | 13 | 103,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,563 | 13 | 103,126 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
from collections import deque
for _ in range(int(input())):
N = int(input())
X = [[] for i in range(N)]
pp = [int(a)-1 for a in input().split()]
for i, p in enumerate(pp, 1):
X[i].append(p)
X[p].append(i)
P = [-1] * N
... | output | 1 | 51,563 | 13 | 103,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected graph without cycles. The distance between two ... | instruction | 0 | 51,564 | 13 | 103,128 |
Tags: dfs and similar, dp, greedy, trees
Correct Solution:
```
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque
T = int(input())
for _ in range(T):
N = int(input())
X = [[] for i in range(N)]
pp = [int(a)-1 for a in input().split()]
for i, p in enumerate(pp, 1):
... | output | 1 | 51,564 | 13 | 103,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected ... | instruction | 0 | 51,565 | 13 | 103,130 |
Yes | output | 1 | 51,565 | 13 | 103,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected ... | instruction | 0 | 51,566 | 13 | 103,132 |
Yes | output | 1 | 51,566 | 13 | 103,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected ... | instruction | 0 | 51,567 | 13 | 103,134 |
No | output | 1 | 51,567 | 13 | 103,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n - 1 integers a_2, ..., a_n and a tree with n vertices rooted at vertex 1. The leaves are all at the same distance d from the root.
Recall that a tree is a connected undirected ... | instruction | 0 | 51,568 | 13 | 103,136 |
No | output | 1 | 51,568 | 13 | 103,137 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,757 | 13 | 103,514 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
from collections import deque
n = int(input())
val = [0] + [int(i) for i in input().split(' ')]
highest_dist = [0]*(n+1)
g = [[]for i in range(n+1)]
for i in range(2,n+1):
a,b = map(int, input().split(' '))
g[a].append((i,b))
pilha = deque([1])
wh... | output | 1 | 51,757 | 13 | 103,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,758 | 13 | 103,516 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
read = lambda: map(int, input().split())
n = int(input())
a = [0] + list(read())
g = [list() for i in range(n + 1)]
for i in range(2, n + 1):
p, c = read()
g[i].append((p, c))
g[p].append((i, c))
was = [0] * (n + 1)
st = [(1, 0, 0)]
while st:
... | output | 1 | 51,758 | 13 | 103,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,759 | 13 | 103,518 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
from sys import *
setrecursionlimit(1000001)
n=int(input())
a=[0]+list(map(int,input().split()))
E=[[] for _ in range(n+1)]
k=[1]*(n+1)
for i in range(n-1):
p,c=map(int,input().split())
E[i+2]+=[(p,c)]
E[p]+=[(i+2,c)]
def bfs(nom,pre=0):
ch,... | output | 1 | 51,759 | 13 | 103,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,760 | 13 | 103,520 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import deque
class Graph(object):
"""docstring for Graph"""
def __init__(self,n,d): # Number of nodes and d is True if directed
self.n = n
self.graph = [[] for i in range(n)]
self.parent = [-1 ... | output | 1 | 51,760 | 13 | 103,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,761 | 13 | 103,522 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for u in range(1, n):
p, c = (int(x) for x in input().split())
g[p-1].append((u, c))
stack = [(0, 0, False)]
r = 0
while stack:
u, d, f = stack.pop()
f = f or... | output | 1 | 51,761 | 13 | 103,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,762 | 13 | 103,524 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
n = int(input())
a = [0] + list(map(int, input().split()))
g = [list() for i in range(n+1)]
for i in range(2, n+1):
u, v = map(int, input().split())
g[i].append((u, v))
g[u].append((i, v))
vis = [0] * (n+1)
stk = [(1, 0, 0)]
while stk:
v, mi... | output | 1 | 51,762 | 13 | 103,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,763 | 13 | 103,526 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
nn=int(input())
a=[0]+list(map(int,input().split()))
E=[[] for _ in range(nn+1)]
for i in range(nn-1):
p,c=map(int,input().split())
E[i+2]+=[(p,c)]
E[p]+=[(i+2,c)]
ans=0
ch=[(1,0,0)]
while ch:
nom,pre,l=ch.pop()
if l>a[nom]:... | output | 1 | 51,763 | 13 | 103,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.
The girl noticed that some o... | instruction | 0 | 51,764 | 13 | 103,528 |
Tags: dfs and similar, dp, graphs, trees
Correct Solution:
```
n=int(input())
a=[0]+list(map(int,input().split()))
E=[[] for _ in range(n+1)]
for i in range(n-1):
p,c=map(int,input().split())
E[i+2]+=[(p,c)]
E[p]+=[(i+2,c)]
ans=0
ch=[(1,0,0)]
while ch:
nom,pre,l=ch.pop()
if l>a[nom]: continue
a... | output | 1 | 51,764 | 13 | 103,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a n... | instruction | 0 | 51,765 | 13 | 103,530 |
Yes | output | 1 | 51,765 | 13 | 103,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a n... | instruction | 0 | 51,766 | 13 | 103,532 |
Yes | output | 1 | 51,766 | 13 | 103,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a n... | instruction | 0 | 51,767 | 13 | 103,534 |
Yes | output | 1 | 51,767 | 13 | 103,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a n... | instruction | 0 | 51,768 | 13 | 103,536 |
Yes | output | 1 | 51,768 | 13 | 103,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a n... | instruction | 0 | 51,769 | 13 | 103,538 |
No | output | 1 | 51,769 | 13 | 103,539 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.