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
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b do...
instruction
0
50,597
13
101,194
Yes
output
1
50,597
13
101,195
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b do...
instruction
0
50,598
13
101,196
No
output
1
50,598
13
101,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b do...
instruction
0
50,599
13
101,198
No
output
1
50,599
13
101,199
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b do...
instruction
0
50,600
13
101,200
No
output
1
50,600
13
101,201
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b do...
instruction
0
50,601
13
101,202
No
output
1
50,601
13
101,203
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,619
13
101,238
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` #!/usr/bin/env python3 import queue R = lambda: list(map(int, input().split())) n = R()[0] g, d, frm = [[] for _ in range(n)], [0] * n, [0] * n for _ in range(n - 1): u, v = R() g[u - 1].append(v - 1) g[v - 1].append(u - 1) def bfs(s): ...
output
1
50,619
13
101,239
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,620
13
101,240
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` import sys input = sys.stdin.readline NEGINF = -1000000 n = int(input()) adj = [[] for i in range(n)] parent = [-1] * n visited = [False] * n for _ in range(n - 1): a, b = map(int, input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a...
output
1
50,620
13
101,241
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,621
13
101,242
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` from collections import namedtuple, deque from sys import stdin def load_graph(): n = int(stdin.readline()) G = [set() for i in range(n)] for line in stdin.readlines(): a, b = line.split() a, b = int(a) - 1, int(b) - 1 #...
output
1
50,621
13
101,243
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,622
13
101,244
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` from collections import deque import sys input = sys.stdin.readline def bfs(s): q = deque() q.append(s) dist1 = [-1] * (n + 1) dist1[s] = 0 while q: i = q.popleft() di = dist1[i] for j in G[i]: if dis...
output
1
50,622
13
101,245
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,623
13
101,246
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` def dfs(n, source, neighbors): # Distances à la racine dist = [-1] * n # Pointeur sur parent parent = [-1] * n # Hauteur du sous-arbre height = [-1] * n # Pointeur sur sous-arbre le plus haut height_ptr = [-1] * n # S...
output
1
50,623
13
101,247
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,624
13
101,248
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` import sys from collections import defaultdict def diam(graph): n=len(graph) st,m=0,-1 mark=[0]*n dist=[0]*n dist2=[0]*n ret=[0]*4 q=[] for i in range(1,4): q.append(st) mark=[0]*n mark[st]=1 d...
output
1
50,624
13
101,249
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,625
13
101,250
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` import io import os from collections import Counter, defaultdict, deque def longestPathFrom(root, getNbr): # BFS queue = deque() queue.append(root) parent = {} parent[root] = None while queue: curr = queue.popleft() ...
output
1
50,625
13
101,251
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such that the number of edges which belong to at least ...
instruction
0
50,626
13
101,252
Tags: dfs and similar, dp, greedy, trees Correct Solution: ``` class HLD: def __init__(self, g): self.g = g self.n = len(g) self.parent = [-1]*self.n self.size = [1]*self.n self.head = [0]*self.n self.preorder = [0]*self.n self.k = 0 self.depth = [0]*s...
output
1
50,626
13
101,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,627
13
101,254
Yes
output
1
50,627
13
101,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,628
13
101,256
Yes
output
1
50,628
13
101,257
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,629
13
101,258
Yes
output
1
50,629
13
101,259
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,630
13
101,260
Yes
output
1
50,630
13
101,261
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,631
13
101,262
No
output
1
50,631
13
101,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,632
13
101,264
No
output
1
50,632
13
101,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,633
13
101,266
No
output
1
50,633
13
101,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an unweighted tree with n vertices. Recall that a tree is a connected undirected graph without cycles. Your task is to choose three distinct vertices a, b, c on this tree such tha...
instruction
0
50,634
13
101,268
No
output
1
50,634
13
101,269
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,936
13
101,872
Tags: constructive algorithms, graphs, trees Correct Solution: ``` # Problem: B. Bear and Forgotten Tree 3 # Contest: Codeforces - VK Cup 2016 - Round 1 # URL: https://codeforces.com/contest/639/problem/B # Memory Limit: 256 MB # Time Limit: 2000 ms # # KAPOOR'S from sys import stdin, stdout def INI(): return int(...
output
1
50,936
13
101,873
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,937
13
101,874
Tags: constructive algorithms, graphs, trees Correct Solution: ``` from __future__ import print_function import sys from collections import * from heapq import * from functools import * import re from itertools import * INF=float("inf") NINF=float("-inf") try: input=raw_input except: pass def read_string(): ...
output
1
50,937
13
101,875
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,938
13
101,876
Tags: constructive algorithms, graphs, trees Correct Solution: ``` n,d,h = (int(i) for i in input().split()) if h*2 < d or n < d+1 or d == 1 and n > 2 : print(-1) else: for i in range(h): print(i+1,i+2) ost = h+1 if d > h: print(1,ost+1) for i in range(d-h-1): print(ost+i+1,o...
output
1
50,938
13
101,877
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,939
13
101,878
Tags: constructive algorithms, graphs, trees Correct Solution: ``` import sys [n,d,h]=[int(i) for i in input().split()]; if n==2: print(1,2); sys.exit(0); if (d==1) or (d>2*h): print(-1); sys.exit(0); for i in range(1,h+1): print(i,i+1); if(d+1>h+1): print(1,h+2); for i in range(h+3,d+2): pr...
output
1
50,939
13
101,879
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,940
13
101,880
Tags: constructive algorithms, graphs, trees Correct Solution: ``` n,d,h=map(int,input().split()) if n ==2: if d == h and d == 1: print('1 2') else: print(-1) elif d== 1 or d>2*h: print(-1) else: for i in range(h): print(i+1,i+2) for i in range(d-h): print(1 if i==0 ...
output
1
50,940
13
101,881
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,941
13
101,882
Tags: constructive algorithms, graphs, trees Correct Solution: ``` n,d,h = map(int, input().split()) if n<(h+1): print(-1) elif ((d<h) or (d>2*h)): print(-1) elif h==1 and d==1 and n>=3: print(-1) else: count = 2 stmt=h for i in range(h): print(i+1, i+2) for i in range(h, n-(d-h+1)):...
output
1
50,941
13
101,883
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,942
13
101,884
Tags: constructive algorithms, graphs, trees Correct Solution: ``` n, d, h = map(int, input().split()) if d > h * 2 or (n > 2 and h == 1 and d == 1): print(-1) else: for i in range(2, h + 2): print(i-1, i) c = h+2 for i in range(d - h): if i == 0: print(1, c) else: ...
output
1
50,942
13
101,885
Provide tags and a correct Python 3 solution for this coding contest problem. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sa...
instruction
0
50,943
13
101,886
Tags: constructive algorithms, graphs, trees Correct Solution: ``` # Codeforces 639B # n, d, h = map(int, input().split()) if h < ((d + 1) >> 1) or (n > 2 and d == 1): print(-1) else: km = 2 if h != 1 else 1 print(h + 1, km) for i in range(2, h): print(i, i + 1) if h != 1: print(...
output
1
50,943
13
101,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,944
13
101,888
Yes
output
1
50,944
13
101,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,945
13
101,890
Yes
output
1
50,945
13
101,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,946
13
101,892
Yes
output
1
50,946
13
101,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,947
13
101,894
Yes
output
1
50,947
13
101,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,948
13
101,896
No
output
1
50,948
13
101,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,949
13
101,898
No
output
1
50,949
13
101,899
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,950
13
101,900
No
output
1
50,950
13
101,901
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had ...
instruction
0
50,951
13
101,902
No
output
1
50,951
13
101,903
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,265
13
102,530
"Correct Solution: ``` import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int...
output
1
51,265
13
102,531
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,266
13
102,532
"Correct Solution: ``` N, M, s, t = map(int, input().split()) E = [[] for _ in range(N+1)] for _ in range(M): x, y = map(int, input().split()) E[x].append(y) E[y].append(x) closed = [False] * (N+1) closed[s] = True dist = [float("inf")] * (N+1) q = [s] for dist_ in range(N): q_new = [] for v in q: ...
output
1
51,266
13
102,533
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,267
13
102,534
"Correct Solution: ``` # AOJ 2608: Minus One # Python3 2018.6.30 bal4u import heapq MAX = 0x7fffffff def dijkstra(dist, start): Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if dist[s] < t: continue for e in to[s]: nt = t + 1 if dist[e] > nt: dist[e] = nt ...
output
1
51,267
13
102,535
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,268
13
102,536
"Correct Solution: ``` import heapq def dijkstra_heap(s): d = [float("inf")] * n used = [True] * n d[s] = 0 used[s] = False edgelist = [] for e in edge[s]: heapq.heappush(edgelist,e) while len(edgelist): minedge = heapq.heappop(edgelist) if not used[minedge[1]]: ...
output
1
51,268
13
102,537
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,269
13
102,538
"Correct Solution: ``` #!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return li...
output
1
51,269
13
102,539
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,270
13
102,540
"Correct Solution: ``` # coding: utf-8 import queue n,m,s,t=map(int,input().split()) table=[[] for i in range(n)] inf=300001 dist_s=[inf for i in range(n)] dist_t=[inf for i in range(n)] s_list=[0 for i in range(inf+1)] t_list=[0 for i in range(inf+1)] s-=1;t-=1 for i in range(m): a,b=map(int,input().split()) a...
output
1
51,270
13
102,541
Provide a correct Python 3 solution for this coding contest problem. Ikta has an extraordinary feeling for undirected graphs. Ikta likes the undirected graph G and its two-point s, t pair (G, s, t) that has the greatest "beauty". The "beauty" of a pair (G, s, t) is the edge e = \\ {u, v \\} (u and v are two different ...
instruction
0
51,271
13
102,542
"Correct Solution: ``` from collections import deque, defaultdict n, m, s, t = map(int, input().split()) s -= 1 t -= 1 edges = [[] for _ in range(n)] for _ in range(m): x, y = map(int, input().split()) x -= 1 y -= 1 edges[x].append(y) edges[y].append(x) def dist_from(s): INF = 10 ** 20 dist = [INF] * n ...
output
1
51,271
13
102,543
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,276
13
102,552
"Correct Solution: ``` class Node(): def __init__(self): self.parent = -1 self.left = -1 self.right = -1 def get_depth(u, p): D[u] = p if result[u].right is not None: get_depth(result[u].right, p) if result[u].left is not None: get_depth(result[u].left, p+1) def get_depth_1(u, p): i = u ...
output
1
51,276
13
102,553
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,277
13
102,554
"Correct Solution: ``` class node: def __init__(self, parent, left, right, depth, height): self.p = parent self.l = left self.r = right self.d = depth self.h = height def setDepth(u, depthPosition): if u == -1: return T[u].d = depthPosition setDepth(T[u]....
output
1
51,277
13
102,555
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,278
13
102,556
"Correct Solution: ``` N = int(input()) binary_tree = [{"parent": -1, "sibling": -1} for _ in range(N)] for _ in range(N): node_input = input() id, left, right = map(int, node_input.split()) binary_tree[id]["left"] = left binary_tree[id]["right"] = right degree = 0 if left != -1: degr...
output
1
51,278
13
102,557
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,279
13
102,558
"Correct Solution: ``` def binary(node,parent,sibling,depth,root): if node!=-1: id,left,right=A[node] degree = len([i for i in (right, left) if i != -1]) if parent==-1:root="root" elif degree!=0:root="internal node" else:root="leaf" B.append([node,parent,sibling,degre...
output
1
51,279
13
102,559
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,280
13
102,560
"Correct Solution: ``` #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_B&lang=jp def cal_depth(binary_tree, target_index, depth, parent, sibling): if target_index == -1: return 0 binary_tree[target_index]["depth"] = depth binary_tree[target_index]["parent"] = parent binary_tree...
output
1
51,280
13
102,561
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,281
13
102,562
"Correct Solution: ``` N=int(input()) t=[0]*N r=set(range(N)) for _ in[0]*N: x,y,z=list(map(int,input().split())) t[x]=[y,z]+[0]*2+[(y!=-1)+(z!=-1)]+[0]*2 r-={y,z} def f(i,p,s,d): if i<0:return-1 l,r=t[i][:2] t[i][2:]=[p,s,t[i][4],d,max(f(l,i,r,d+1),f(r,i,l,d+1))+1] return t[i][-1] f(r.pop(),-1,-1,0) for i in ra...
output
1
51,281
13
102,563