s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s347631973
p02279
u851695354
1489593783
Python
Python3
py
Runtime Error
20
7772
1416
class Tree: def __init__(self,parent,left,right): self.parent = parent self.left = left self.right = right def setdepth(u, p): depths[u] = p if trees[u].right != -1: # ???????????????????????±???????¨???? setdepth(trees[u].right, p) if trees[u].left != -1: ...
s810513317
p02279
u851695354
1489594520
Python
Python3
py
Runtime Error
710
72020
1457
import sys class Tree: def __init__(self,parent,left,right): self.parent = parent self.left = left self.right = right def setdepth(u, p): depths[u] = p if trees[u].right != -1: # ???????????????????????±???????¨???? setdepth(trees[u].right, p) if trees[u].left ...
s504449296
p02279
u370086573
1493981083
Python
Python3
py
Runtime Error
0
0
1241
class Node: parent = NIL left = NIL right = NIL label = "" def show_info(u): global T, D if T[i].parent == NIL: T[u].label = "root" elif T[i].left == NIL: T[u].label = "leaf" else: T[u].label = "internal node" print('node {0}: parent = {1}, depth = {2}, {3},...
s246975764
p02279
u370086573
1493981121
Python
Python3
py
Runtime Error
0
0
1241
class Node: parent = NIL left = NIL right = NIL label = "" def show_info(u): global T, D if T[i].parent == NIL: T[u].label = "root" elif T[i].left == NIL: T[u].label = "leaf" else: T[u].label = "internal node" print('node {0}: parent = {1}, depth = {2}, {3},...
s863472533
p02279
u370086573
1493982005
Python
Python3
py
Runtime Error
20
7824
1411
NIL = -1 class Node: parent = NIL left = NIL right = NIL label = "" def show_info(u): global T, D print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(u, T[u].parent, D[u], T[u].label, getChildren(u))) def setLabel(n): for i in range(n): if T[i].parent == NIL: ...
s231836538
p02279
u370086573
1493983619
Python
Python3
py
Runtime Error
20
7716
1168
NIL = -1 class Node: parent = NIL left = NIL right = NIL label = "" def setDepth(u,d): D[u] = d if T[u].left != NIL: setDepth(T[u].left,d + 1) if T[u].right != NIL: setDepth(T[u].right, d) def getChildren(u): c = T[u].left result = [] while c != NIL: ...
s315737401
p02279
u603049633
1496297030
Python
Python3
py
Runtime Error
0
0
1017
class Node: def __init__(self, num, parent, children): self.id = num self.parent = -1 self.depth = 0 self.type = None self.children = children def show(self): print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.id,self.parent,self.depth,sel...
s805276496
p02279
u091533407
1499484337
Python
Python3
py
Runtime Error
30
7836
1298
import sys def dep(u, p): D[u] = p if tree[u][2] != NIL: dep(tree[u][2], p) if tree[u][1] != NIL: dep(tree[u][1], p+1) def print_ans(): for i in range(n): if tree[i][0] == NIL: typea = "root" elif tree[i][1] == NIL: typea = "leaf" else:...
s894313617
p02279
u091533407
1499484917
Python
Python3
py
Runtime Error
30
7792
1118
import sys def dep(u, p): D[u] = p if tree[u][2] != NIL: dep(tree[u][2], p) if tree[u][1] != NIL: dep(tree[u][1], p+1) def print_ans(): for i in range(n): if tree[i][0] == NIL: typea = "root" elif tree[i][1] == NIL: typea = "leaf" else:...
s909488974
p02279
u091533407
1499485434
Python
Python3
py
Runtime Error
20
7828
1099
import sys def dep(u, p): D[u] = p if tree[u][2] != NIL: dep(tree[u][2], p) if tree[u][1] != NIL: dep(tree[u][1], p+1) def print_ans(): for i in range(n): print("node {}: parent = {}, depth = {}, {}, {}" .format(i, tree[i][0], D[i], tree[i][4], tree[i][3])) if...
s354701814
p02279
u091533407
1499486147
Python
Python3
py
Runtime Error
30
7812
1044
import sys def dep(u, p): D[u] = p if tree[u][2] != NIL: dep(tree[u][2], p) if tree[u][1] != NIL: dep(tree[u][1], p+1) def print_ans(): for i in range(n): print("node {}: parent = {}, depth = {}, {}, {}" .format(i, tree[i][0], D[i], "root" ...
s298757286
p02279
u510829608
1502427720
Python
Python3
py
Runtime Error
0
0
854
import sys NIL = -1 def set_depth(v, depth): tree[v][2] = depth if child in tree[v][1]: set_depth(child, depth + 1) N = int(input()) tree = [[NIL, [], 0, 'leaf'] for _ in range(N)] for _ in range(N): line = [int(i) for i in sys.stdin.readline().split()] t_id = line[0] children = lin...
s594490118
p02279
u519227872
1502546830
Python
Python3
py
Runtime Error
0
0
877
n = int(input()) tree = {} for i in range(n): row = [int(k) for k in input().split()] id = row[0] ch = row[2:] val = tree.get(id, []) val += ch tree[id] = val def printInfo(id): parent = -1 depth = 0 for p in tree.keys(): if id in tree[p]: parent = p ...
s076579817
p02279
u519227872
1502548428
Python
Python3
py
Runtime Error
0
0
866
n = int(input()) tree = {} for i in range(n): row = [int(k) for k in input().split()] id = row[0] ch = row[2:] val = tree.get(id, []) val += ch tree[id] = val def printInfo(id): parent = -1 depth = 0 for p in tree.keys(): if id in tree[p]: parent = p ...
s705696186
p02279
u519227872
1502566042
Python
Python3
py
Runtime Error
0
0
1036
n = int(input()) class Node(object): def __init__(self, p, l, r): self.p = p self.l = l self.r = r nodes = [Node(None, None, None) for i in range(n)] for i in range(n): id, left, right = map(int, input().split()) nodes[id].l = left nodes[id].r = right if left != -1: ...
s855761963
p02279
u855199458
1502682358
Python
Python3
py
Runtime Error
20
7764
1131
# -*- coding: utf-8 -*- N = int(input()) tree = {n:{"parent":-1, "left": -1, "right": -1} for n in range(N)} # left-child right-sibing parent = set([n for n in range(N)]) for n in range(N): inp = [int(n) for n in input().split()] tree[inp[0]]["children"] = inp[2:] tree[inp[0]]["left"] = inp[2] if len(inp) ...
s487278562
p02279
u855199458
1502682541
Python
Python3
py
Runtime Error
820
102288
1174
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(114514) N = int(input()) tree = {n:{"parent":-1, "left": -1, "right": -1} for n in range(N)} # left-child right-sibing parent = set([n for n in range(N)]) for n in range(N): inp = [int(n) for n in input().split()] tree[inp[0]]["children"] = inp[2:] ...
s916523003
p02279
u918276501
1508083526
Python
Python3
py
Runtime Error
0
0
584
def set_pdt(i, p, d): u = tree[i] u[0], u[1] = p, d for c in u[3]: set_pdt(c, i, d+1) else: if u[0] == -1: u[2] = "root" elif u[3]: u[2] = "internal node" else: u[2] = "leaf" n = int(input()) # p d t ch tree = [[-1,0,0,0] for _...
s763350241
p02279
u918276501
1508083659
Python
Python3
py
Runtime Error
0
0
586
def set_pdt(i, p, d): u = tree[i] u[0], u[1] = p, d for c in u[3]: set_pdt(c, i, d+1) else: if u[0] == -1: u[2] = "root" elif u[3]: u[2] = "internal node" else: u[2] = "leaf" n = int(input()) # p d t ch tree = [[-1,0,0,0] for _...
s802325114
p02279
u662418022
1517121524
Python
Python3
py
Runtime Error
30
5620
1461
# -*- coding: utf-8 -*- class Node(): def __init__(self, ID, parent=-1, left=-1, right=-1, depth=0, children=[]): self.id = ID self.parent = parent self.left = left self.right = right self.depth = depth self.children = children if __name__ == '__main__': n = ...
s386181066
p02279
u662418022
1517121615
Python
Python3
py
Runtime Error
20
5620
1461
# -*- coding: utf-8 -*- class Node(): def __init__(self, ID, parent=-1, left=-1, right=-1, depth=0, children=[]): self.id = ID self.parent = parent self.left = left self.right = right self.depth = depth self.children = children if __name__ == '__main__': n = ...
s981545829
p02279
u662418022
1517121928
Python
Python3
py
Runtime Error
20
5620
1461
# -*- coding: utf-8 -*- class Node(): def __init__(self, ID, parent=-1, left=-1, right=-1, depth=0, children=[]): self.id = ID self.parent = parent self.left = left self.right = right self.depth = depth self.children = children if __name__ == '__main__': n = ...
s912170547
p02279
u996463517
1518360735
Python
Python3
py
Runtime Error
20
5616
1059
class tree: def __init__(self,name,parent,left,right): self.name = name self.parent = parent self.left = left self.right = right trees = {} trees['0'] = tree('0','-1','-1','-1') n = int(input()) for i in range(n): s = [i for i in input().split()] p = s[0] k = s[1] s...
s166192334
p02279
u996463517
1518361118
Python
Python3
py
Runtime Error
20
5612
889
class tree: def __init__(self,name,parent): self.name = name self.parent = parent trees = {} trees['0'] = tree('0','-1') n = int(input()) for i in range(n): s = [i for i in input().split()] p = s[0] s_t = s[2:] for j in range(len(s_t)): trees[s_t[j]] = tree(s_t[j],p) def ...
s351286234
p02279
u150984829
1519044624
Python
Python3
py
Runtime Error
0
0
321
t={} p={} for _ in[0]*int(input()): e=input().split() t[e[0]]=e[2:] for i in e[2:]:p[i]=e[0] r=(set(t)-set(p)).pop() p[r]='-1' d={r:0} for for i in t: f='root,'if'-1'==p[i]else'internal node,'if t[i]else'leaf,' d='0' print('node',i+':','parent =',p[i]+',','depth =',d+',',f,list(map(int,t[i]))) ...
s226845553
p02279
u150984829
1519046580
Python
Python3
py
Runtime Error
0
0
363
def q(a,h): d[a]=str(h) for b in t[a]:q(b,h+1) t,p,d={},{},{} for _ in[0]*int(input()): e=input().split() t[e[0]]=e[2:] for i in e[2:]:p[i]=e[0] r=(set(t)-set(p)).pop() p[r]='-1' q(r,0) for i in sorted(map(int,t)): i=str(i);print(f'node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'i...
s603846184
p02279
u843404779
1525272917
Python
Python3
py
Runtime Error
20
5612
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s277061852
p02279
u843404779
1525272944
Python
Python3
py
Runtime Error
20
5612
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s926495814
p02279
u843404779
1525273034
Python
Python3
py
Runtime Error
20
5616
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s414402941
p02279
u843404779
1525273054
Python
Python3
py
Runtime Error
30
5616
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s076171997
p02279
u843404779
1525273084
Python
Python3
py
Runtime Error
20
5616
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s890669953
p02279
u724548524
1525337148
Python
Python3
py
Runtime Error
20
5628
1415
class Node: def __init__(self, parent = -1, left = -1, right = -1, depth = 0): self.parent = parent self.left = left self.right = right self.depth = depth def print_node(i): global node print("node " + str(i) + ": ", end = "") print("parent = " + str(node[i].parent) ...
s404197502
p02279
u126478680
1525580764
Python
Python3
py
Runtime Error
30
6348
1687
from enum import Enum, auto class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self.depth = de...
s547746570
p02279
u126478680
1525581219
Python
Python3
py
Runtime Error
40
6352
1711
from enum import Enum, auto class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self.depth = de...
s432968966
p02279
u126478680
1525581291
Python
Python3
py
Runtime Error
30
6352
1711
from enum import Enum, auto class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self.depth = de...
s748575478
p02279
u126478680
1525584922
Python
Python3
py
Runtime Error
0
0
1772
from enum import Enum, auto import sys class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self...
s141030735
p02279
u126478680
1525584987
Python
Python3
py
Runtime Error
30
6352
1777
from enum import Enum, auto import sys class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self...
s159046336
p02279
u126478680
1526297528
Python
Python3
py
Runtime Error
30
6352
1683
from enum import Enum, auto import sys class NodeType(Enum): LEAF = auto() INTERNAL_NODE = auto() ROOT = auto() class Node(): def __init__(self, parent=None, left=None, right=None, depth=None, nodetype=None): self.parent = parent self.left = left self.right = right self...
s147821497
p02279
u126478680
1526299886
Python
Python3
py
Runtime Error
20
5620
1353
import sys sys.setrecursionlimit(100000) class Node(): def __init__(self, p=None, l=None, r=None): self.parent = p self.left = l self.right = r self.depth = None n = int(input()) nodes = [Node() for i in range(n)] for i in range(n): id, k, *c = list(map(int, input().split(' '))...
s895233144
p02279
u255317651
1526775750
Python
Python3
py
Runtime Error
20
5632
1856
# -*- coding: utf-8 -*- """ Created on Sat May 19 19:34:44 2018 ALDS1_7_A @author: maezawa """ n = int(input()) parent =[] left = [] right = [None for _ in range(n)] child = [[] for _ in range(n)] depth = [None for _ in range(n)] def get_parent(i): for j in range(n): if i in child[j]: return ...
s025479206
p02279
u255317651
1526776193
Python
Python3
py
Runtime Error
20
5628
1860
# -*- coding: utf-8 -*- """ Created on Sat May 19 19:34:44 2018 ALDS1_7_A @author: maezawa """ n = int(input()) parent =[] left = [] right = [None for _ in range(n)] child = [[] for _ in range(n)] depth = [None for _ in range(n)] def get_parent(i): for j in range(n): if i in child[j]: return ...
s441715577
p02279
u088372268
1526803808
Python
Python3
py
Runtime Error
30
5616
1568
class Node: def __init__(self, parent=-1,left=-1, right=-1): self.parent = parent self.left = left self.right = right n = int(input()) rooted_tree = [Node() for i in range(n)] d = [0 for k in range(n)] def set_depth(u, p): d[u] = p if rooted_tree[u].right != -1: set_depth...
s294930554
p02279
u088372268
1526804484
Python
Python3
py
Runtime Error
20
5620
1596
import sys class Node: def __init__(self, parent=-1,left=-1, right=-1): self.parent = parent self.left = left self.right = right n = int(input()) rooted_tree = [Node() for i in range(n)] d = [0 for k in range(n)] def set_depth(u, p): d[u] = p if rooted_tree[u].right != -1: ...
s857527386
p02279
u843404779
1526910927
Python
Python3
py
Runtime Error
20
5612
1466
def rec_function(i, p): node_info[i]['depth'] = p if node_info[i]['parent'] == -1: node_info[i]['type'] = 'root' elif node_info[i]['left'] == None: node_info[i]['type'] = 'leaf' else: node_info[i]['type'] = 'internal node' if node_info[i]['right'] != None: rec_funct...
s738425317
p02279
u684241248
1527832719
Python
Python3
py
Runtime Error
30
5612
2830
class Tree: def __init__(self, ary): self.nodes = [Node(node, self) for node in ary] [node.set() for node in self.nodes] for node in self.nodes: if node.parent == -1: node.set_depth(0) break def output(self): [node.output() for node in...
s942671362
p02279
u684241248
1527833038
Python
Python3
py
Runtime Error
30
5612
2858
class Tree: def __init__(self, ary): self.nodes = [Node(node, self) for node in ary] [node.set() for node in self.nodes] for node in self.nodes: if node.parent == -1: node.set_depth(0) break def output(self): [node.output() for node in...
s858134064
p02279
u684241248
1527834627
Python
Python3
py
Runtime Error
20
5620
1714
class Tree: def __init__(self, ary): self.nodes = [ Node(node, self) for node in sorted(ary, key=lambda x: x[0]) ] [node.set() for node in self.nodes] for node in self.nodes: if node.parent == -1: node.set_depth(0) break de...
s431174756
p02279
u007270338
1528359251
Python
Python3
py
Runtime Error
0
0
1409
#coding:utf-8 n = int(input()) T = [list(map(int, input().split())) for i in range(n)] A = [] def parentSearch(): numList = [] for t in T: if t[1] != 0: for num in t[2:]: numList.append(num) numList.sort() for i in range(n-1): if numList[i] != i: ...
s006713076
p02279
u007270338
1528359865
Python
Python3
py
Runtime Error
20
5624
1529
#coding:utf-8 n = int(input()) T = [list(map(int, input().split())) for i in range(n)] A = [] def parentSearch(): numList = [] for t in T: if t[1] != 0: for num in t[2:]: numList.append(num) numList.sort() for i in range(n-1): if numList[i] != i: ...
s942814181
p02279
u766183517
1529829373
Python
Python3
py
Runtime Error
60
7164
3018
from typing import List class Node: def __init__(self, node_id, parent_id): self.node_id = node_id self.parent_id = parent_id self.children = [] self.depth = None self.node_type =None def __str__(self): return str(self.node_id) def __repr__(self): ...
s726852183
p02280
u760378812
1541046252
Python
Python3
py
Runtime Error
0
0
2264
#include <iostream> #include <string> #include <cstring> #include <fstream> #include <cmath> #include <iomanip> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <deque> #include <map> #include <set> #include <queue> #include <stack> #include <list> #include <unordered_map> using namesp...
s051944439
p02280
u096660561
1556099151
Python
Python3
py
Runtime Error
0
0
2134
n = int(input()) class BiTree(): def __init__(self, node, left, right): self.node = node self.left = left self.right = right dali = [0] * n def inputdata(i): node, left, right = list(map(int, input().split())) dali[i] = BiTree(node, left, right) def getParent(i): for k in...
s729774311
p02280
u096660561
1556099228
Python
Python3
py
Runtime Error
0
0
2134
n = int(input()) class BiTree(): def __init__(self, node, left, right): self.node = node self.left = left self.right = right dali = [0] * n def inputdata(i): node, left, right = list(map(int, input().split())) dali[i] = BiTree(node, left, right) def getParent(i): for k in...
s912016184
p02280
u096660561
1556100905
Python
Python3
py
Runtime Error
0
0
2253
n = int(input()) class BiTree(): def __init__(self, node, left, right): self.node = node self.left = left self.right = right dali = [0] * n def inputdata(i): node, left, right = list(map(int, input().split())) dali[node] = BiTree(node, left, right) def getParent(i): for k in rang...
s062785662
p02280
u805716376
1556793552
Python
Python3
py
Runtime Error
20
5628
930
n = int(input()) deg = [0]*n child, parent = {}, {} sib = [None]*n for i in range(n): a = list(map(int, input().split())) if a[1] != -1: child[a[0]] = a[1:] sib[a[1]] = a[2] sib[a[2]] = a[1] deg[a[0]] = 2 for j in child[a[0]]: parent[j] = a[0] else: ...
s333370671
p02280
u805716376
1556794192
Python
Python3
py
Runtime Error
20
5632
1072
n = int(input()) deg = [0]*n child, parent = {}, {} sib = [None]*n for i in range(n): a = list(map(int, input().split())) if a[1] != -1: if a[2] == -1: child[a[0]] = [a[1]] sib[a[1]] = a[2] deg[a[0]] = 1 else: child[a[0]] = a[1:] sib[a[...
s327342142
p02280
u888548672
1556871625
Python
Python3
py
Runtime Error
0
0
2951
#include <iostream> #define TREE_SIZE 30 #define NIL -1 using namespace std; struct Node { int parent_node = NIL; int left_child = NIL; int right_child = NIL; }; Node Tree[TREE_SIZE]; int Depth[TREE_SIZE]; int Height[TREE_SIZE]; // set depth of all nodes by recursion void Set_depth_of_node(int node_id, ...
s070505849
p02280
u888548672
1556871686
Python
Python3
py
Runtime Error
0
0
2930
#include <iostream> #define TREE_SIZE 30 #define NIL -1 struct Node { int parent_node = NIL; int left_child = NIL; int right_child = NIL; }; Node Tree[TREE_SIZE]; int Depth[TREE_SIZE]; int Height[TREE_SIZE]; // set depth of all nodes by recursion void Set_depth_of_node(int node_id, int depth) { Dept...
s819383985
p02280
u198069342
1416408213
Python
Python
py
Runtime Error
0
0
513
def f(n,d): t=[f(i,d+1)+1 for i in l[n][1]] h=0 if t==[] else max(t) c[n][3:3]=[len(l[n][1]),d,h,"root" if d<1 else "leaf" if h<1 else "internal node"] return h m=input() c=[0]*m l=sorted([map(int,raw_input().split()) for _ in range(m)]) for i in l: n,a,b=i if a>0:c[a]=[a,n,b] if b>0:c[b]=[b...
s171568375
p02280
u567281053
1460132212
Python
Python
py
Runtime Error
0
0
807
import sys class Node: def __init__(self, id, children): self.id = id self.parent = -1 self.depth = 0 self.type = "root" self.children = children if __name__ == "__main__": lines = sys.stdin.readlines() N = lines[0] tree = [] for i in range(int(N)): ...
s340419842
p02280
u567281053
1460221194
Python
Python
py
Runtime Error
10
6420
2130
import sys class Node: def __init__(self, id, left, right, degree, depth, type): self.id = id self.parent = None self.sibling = -1 self.degree = degree self.depth = depth self.height = 0 self.type = type self.left = left self.right = right ...
s380453206
p02280
u890722286
1474811819
Python
Python3
py
Runtime Error
30
7828
1510
def print_node(i, node): parent = -1 if node[1] == None else node[1] degree = len([x for x in node[0] if x != -1]) sibling = -1 if parent == -1 else node[2] depth = node[3] height = node[4] t = 'root' if parent == -1 else 'leaf' if height == 0 else 'internal node' ans = "node {}: parent = {}...
s383395691
p02280
u711765449
1486880084
Python
Python3
py
Runtime Error
0
0
1636
NIL = -1 class Node: parent,left,right = NIL,NIL,NIL type = NIL depth = NIL sibling = NIL degree = NIL def setHeight(H,u): h1 = h2 = 0 if T[u].right != NIL: h1 = setHeight(H,T[u].right) + 1 if T[u].left != NIL: h2 = setHeight(H,T[u].left) + 1 return max(h1,h2) def g...
s916917488
p02280
u370086573
1493717312
Python
Python3
py
Runtime Error
0
0
1742
class Node: def __init__(self, id, left, right): self.id = id self.right = right self.left = left self.parent = -1 def setHeight(u): global T, H hr = hl = 0 if T[u].right != -1: hr = setHeight(T[u].right) + 1 if T[u].left != -1: hl = setHeight(T[u].l...
s534724905
p02280
u370086573
1493717345
Python
Python3
py
Runtime Error
0
0
1742
class Node: def __init__(self, id, left, right): self.id = id self.right = right self.left = left self.parent = -1 def setHeight(u): global T, H hr = hl = 0 if T[u].right != -1: hr = setHeight(T[u].right) + 1 if T[u].left != -1: hl = setHeight(T[u].l...
s996209854
p02280
u370086573
1493717673
Python
Python3
py
Runtime Error
0
0
1739
class Node: def __init__(self, id, left, right): self.id = id self.right = right self.left = left self.parent = -1 def setHeight(u): global T, H hr = hl = 0 if T[u].right != -1: hr = setHeight(T[u].right) + 1 if T[u].left != -1: hl = setHeight(T[u].l...
s437840033
p02280
u990398499
1497590127
Python
Python3
py
Runtime Error
0
0
1781
N = int(input()) M = [] type = ['root','internal node','leaf'] class node: def __init__(self,idx,parent,left,right): self.idx = idx self.parent = parent self.left = left self.right= right self.sibling = -1 self.degree= -1 self.depth = -1 sel...
s695674752
p02280
u990398499
1497590392
Python
Python3
py
Runtime Error
0
0
1945
N = int(input()) M = [] type = ['root','internal node','leaf'] class node: def __init__(self,idx,parent,left,right): self.idx = idx self.parent = parent self.left = left self.right= right self.sibling = -1 self.degree= -1 self.depth = -1 sel...
s793673401
p02280
u990398499
1497591417
Python
Python3
py
Runtime Error
30
7828
2003
N = int(input()) M = [] type = ['root','internal node','leaf'] class node: def __init__(self,idx,parent,left,right): self.idx = idx self.parent = parent self.left = left self.right= right self.sibling = -1 self.degree= -1 self.depth = -1 sel...
s021848038
p02280
u533883485
1499147510
Python
Python3
py
Runtime Error
0
0
2109
# coding=utf-8 class Node: def __init__(self, ID, left, right): ### ?????¬?????± ### self.id = ID self.parent = -1 #?????? self.sibling = -1 #?????? self.degree = -1 #?????? self.depth = 0 #?????? self.height = 0 #?????? self.type = None #?????? ...
s714427497
p02280
u491916705
1502419296
Python
Python
py
Runtime Error
0
0
1796
class Node(): def __init__(self, id, left, right, parent=-1, sibling=-1, degree=-1, depth=-1, height=-1, type=None): self.id = id self.left = left self.right = right self.parent = parent self.sibling = sibling self.degree = degree self.depth = depth se...
s258477386
p02280
u798803522
1509864011
Python
Python3
py
Runtime Error
0
0
1616
from collections import defaultdict def dfs(here, p, d, conn, parent, depth, height): parent[here] = p depth[here] = d l_d, r_d = 0, 0 for c in conn[here]: if c[0] >= 0: l_d = dfs(c[0], here, d + 1, conn, parent, depth, height) if c[1] >= 0 r_d = dfs(c[1], here, ...
s212561522
p02280
u798803522
1509864026
Python
Python3
py
Runtime Error
0
0
1617
from collections import defaultdict def dfs(here, p, d, conn, parent, depth, height): parent[here] = p depth[here] = d l_d, r_d = 0, 0 for c in conn[here]: if c[0] >= 0: l_d = dfs(c[0], here, d + 1, conn, parent, depth, height) if c[1] >= 0: r_d = dfs(c[1], here,...
s867666026
p02280
u949517845
1512299483
Python
Python3
py
Runtime Error
0
0
2056
# -*- coding:utf-8 -*- import sys def bin_tree(lst, n): """ tree[0]: node tree[1]: parent tree[2]: sibling tree[3]: degree tree[4]: depth tree[5]: height """ info = [[-1, -1, -1, -1, -1, -1] for n in range(0, n)] degree = 0 for node, left, right in l...
s426465825
p02280
u426534722
1517581981
Python
Python3
py
Runtime Error
0
0
1550
import sys readline = sys.stdin.readline class Tree: __slots__ = ['id', 'p', 'sibling', 'degree', 'depth', 'height', 'type', 'c'] def __init__(self, id): self.id = id self.p = -1 self.sibling = -1 self.degree = 0 self.depth = 0 self.height = 0 self.type = ...
s058011997
p02280
u150984829
1519061517
Python
Python3
py
Runtime Error
0
0
535
def q(a,k): d[a]=k for b in t[a]: if'-1'!=b:q(b,k+1) def n(a,k): h[a]=max(h[a],k)if a in h else k if'-1'!=p[a]:n(p[a],k+1) t,p,s,d,h={},{},{},{},{} for _ in[0]*int(input()): x,y,z=input().split() t[x]=set([y,z])-{-1} p[y]=p[z]=x s[y],s[z]=z,y r=(set(t)-set(p)).pop() p[r]=s[r]='-1' q(r,0) for i in t: if not t...
s647724659
p02280
u150984829
1519062269
Python
Python3
py
Runtime Error
0
0
531
def q(a,k): d[a]=k for b in t[a]: if'-1'!=b:q(b,k+1) def n(a,k): h[a]=max(h[a],k)if a in h else k if'-1'!=p[a]:n(p[a],k+1) t,p,s,d,h={},{},{},{},{} n=int(input()) for _ in[0]*n: x,y,z=input().split() t[x]=set([y,z])-{'-1'} p[y]=p[z]=x s[y],s[z]=z,y r=(set(t)-set(p)).pop() p[r]=s[r]='-1' q(r,0) for i in t: if...
s995418475
p02280
u150984829
1519062319
Python
Python3
py
Runtime Error
0
0
531
def q(a,k): d[a]=k for b in t[a]: if'-1'!=b:q(b,k+1) def n(a,k): h[a]=max(h[a],k)if a in h else k if'-1'!=p[a]:n(p[a],k+1) t,p,s,d,h={},{},{},{},{} N=int(input()) for _ in[0]*n: x,y,z=input().split() t[x]=set([y,z])-{'-1'} p[y]=p[z]=x s[y],s[z]=z,y r=(set(t)-set(p)).pop() p[r]=s[r]='-1' q(r,0) for i in t: if...
s705409489
p02280
u150984829
1519064027
Python
Python3
py
Runtime Error
0
0
472
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+[(l!=-1)+(r!=-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 range(N): print('node {}...
s682394814
p02280
u150984829
1519064257
Python
Python3
py
Runtime Error
0
0
452
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,0,(y!=-1)+(z!=-1),0,0] r-={y,z} def f(i,p,s,d): if i<0:return-1 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 range(N): print('node {}: parent = {}, sibli...
s059142648
p02280
u150984829
1519064414
Python
Python3
py
Runtime Error
0
0
457
N=int(input()) t=[0]*N r=set(range(N)) for _ in[0]*N: e=list(map(int,input().split())) t[e[0]]=e[1:]+[0]*5 r-={e[1:]} def f(i,p,s,d): if i<0:return-1 l,r=t[i][:2] t[i][2:]=[p,s,(l!=-1)+(r!=-1),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 range(N): print('node {}: parent = {}, ...
s562251809
p02280
u150984829
1519067019
Python
Python3
py
Runtime Error
0
0
450
N=int(input()) t=[0]*N r=set(range(N)) for _ in[0]*N: x,y,z=map(int,input().split()) t[x]=[y,z]+[0]*5 r-={y,z} def f(i,p,s,d): if i<0:return-1 l,r=t[i][:2] t[i][2:5]=[p,s,(l!=-1)+(r!=-1),d] return t[i][6]=max(f(l,i,r,d+1),f(r,i,l,d+1))+1 f(r.pop(),-1,-1,0) for i in range(N): print('node {}: parent = {}, sibling...
s585807404
p02280
u912143677
1521809280
Python
Python3
py
Runtime Error
0
0
957
NIL = -1 class Node: parent = NIL left = NIL right = NIL n = int(input()) t = [Node() for i in range(n)] for i in range(n): a = list(map(int, input().split())) if a[1] != -1: t[i].left = a[1] t[a[1]].parent = a[i] if a[2] != -1: t[i].right = a[2] t[a[2]].parent...
s783534430
p02280
u938045879
1527781479
Python
Python3
py
Runtime Error
0
0
1290
n = int(input()) root = set(range(n)) binary_tree = [] out = [0 for i in range(n)] for i in range(n): l = list(map(int, input().split())) binary_tree.append(l) s = set(l[1:3]) root -= s def binary(id, parent, depth, sibling, height): output = {} hline = [] hline.append(height) output['n...
s636709470
p02280
u464859367
1528538118
Python
Python3
py
Runtime Error
0
0
3949
using System; using System.Collections.Generic; using System.Text; namespace ALDS1_7_B { class Node { public int Parent { get; set; } public int Sibling { get; set; } public int Degree { get; set; } public int Depth { get; set; } public int Hight { get; set; } pu...
s492157254
p02280
u464859367
1528590849
Python
Python3
py
Runtime Error
0
0
4352
using System; using System.Collections.Generic; using System.Text; namespace ALDS1_7_B { class Node { public int Parent { get; set; } public int Sibling { get; set; } public int Degree { get; set; } public int Depth { get; set; } public int Hight { get; set; } pu...
s366517107
p02280
u782850731
1380149075
Python
Python
py
Runtime Error
0
0
1559
#!/usr/bin/env python from __future__ import division, print_function from sys import stdin FORMAT = ('node {0.id}: parent = {0.parent}, sibling = {0.sibling}, ' 'degree = {0.degree}, depth = {0.depth}, height = {0.height}, ' '{0.type}').format class Node(object): def __init__(self, data): ...
s816485146
p02281
u805716376
1556796546
Python
Python3
py
Runtime Error
0
0
409
def s(x): print('',x,end='') def p(u): if u+1:s(u);p(R[u]);p(L(u)) def i(u): if u+1:i(R(u));s(u);p(L(u)) def o(u): if u+1:o(R(u));o(L(u));s(u) n = int(inpout()) R, L = [0]*n, [0]*n for _ in range(n): a, b, c = map(int, input().split()) R[a] = b L[a] = c root = (set(range(n))-set(R)-...
s411609854
p02281
u805716376
1556796577
Python
Python3
py
Runtime Error
0
0
408
def s(x): print('',x,end='') def p(u): if u+1:s(u);p(R[u]);p(L(u)) def i(u): if u+1:i(R(u));s(u);p(L(u)) def o(u): if u+1:o(R(u));o(L(u));s(u) n = int(input()) R, L = [0]*n, [0]*n for _ in range(n): a, b, c = map(int, input().split()) R[a] = b L[a] = c root = (set(range(n))-set(R)-s...
s751876698
p02281
u805716376
1556796659
Python
Python3
py
Runtime Error
0
0
417
def s(x): print('',x,end='') def p(u): if u+1:s(u);p(R[u]);p(L(u)) def i(u): if u+1:i(R(u));s(u);p(L(u)) def o(u): if u+1:o(R(u));o(L(u));s(u) n = int(input()) R, L = [0]*n, [0]*n for _ in range(n): a, b, c = map(int, input().split()) R[a] = b L[a] = c root = (set(range(n))-set(R)-s...
s418716751
p02281
u805716376
1556797454
Python
Python3
py
Runtime Error
0
0
462
def s(x): print('',x,end='') def p(u): if u+1:s(u);p(R[u]);p(R(u+n)) def i(u): if u+1:i(R(u));s(u);p(L(u)) def o(u): if u+1:o(R(u));o(L(u));s(u) n = int(input()) R, L = [0]*2*n, [0]*n for _ in range(n): a, b, c = map(int, input().split()) R[a], R[a+n] = b,c L[a] = c root = (set(rang...
s435365940
p02281
u805716376
1556797797
Python
Python3
py
Runtime Error
0
0
417
def s(x): print('',x,end='') def p(u): if u+1:s(u);p(R[u]);p(L(u)) def i(u): if u+1:i(R(u));s(u);p(L(u)) def o(u): if u+1:o(R(u));o(L(u));s(u) n = int(input()) R, L = [0]*n, [0]*n for _ in range(n): a, b, c = map(int, input().split()) R[a] = b L[a] = c root = (set(range(n))-set(R)-s...
s962112263
p02281
u882992966
1442182266
Python
Python3
py
Runtime Error
30
7788
1913
import sys class Node(object): def __init__(self, parent=-1, left=-1, right=-1): self.parent = parent self.left = left self.right = right def __str__(self): return "parent = %s, left = %s, right = %s" % (self.parent, self.left, self.right) def __repr__(self): retu...
s747129873
p02281
u519227872
1502565327
Python
Python3
py
Runtime Error
0
0
1033
n = int(input()) class Node(object): def __init__(self, p, l, r): self.p = p self.l = l self.r = r nodes = [Node(None, None, None) for i in range(n)] for i in range(n): id, left, right = map(int, input().split()) nodes[i].l = left nodes[i].r = right if left != -1: n...
s204182064
p02281
u798803522
1509811714
Python
Python3
py
Runtime Error
0
0
1190
from collections import defaultdict def preorder(here, conn, chain): if here == -1: return chain.append(here) if conn[here]: preorder(conn[here][0], conn, chain) preorder(conn[here][1], conn, chain) def inorder(here, conn, chain): if here == -1: return if conn[here]:...
s763315419
p02281
u845643816
1511260330
Python
Python3
py
Runtime Error
0
0
746
N = int(input()) left = [-1 for i in range(N)] right = [-1 for i in range(N)] root = sum(range(N)) for i in range(N): i, l, r = map(int, input().split()) left[i] = l right[i] = r root -= (l + r) def preorder(i): if i == -1: return print(' ', i, sep = '') preorder(left[i]) ...
s557881967
p02281
u845643816
1511260741
Python
Python3
py
Runtime Error
0
0
754
N = int(input()) left = [-1 for i in range(N)] right = [-1 for i in range(N)] root = sum(range(N)) - N - 1 for i in range(N): i, l, r = map(int, input().split()) left[i] = l right[i] = r root -= (l + r) def preorder(i): if i == -1: return print(' ', i, sep = '') preorder(left[...
s303939197
p02281
u845643816
1511260854
Python
Python3
py
Runtime Error
0
0
784
N = int(input()) left = [-1 for i in range(N)] right = [-1 for i in range(N)] root = sum(range(N)) - N - 1 for i in range(N): i, l, r = map(int, input().split()) left[i] = l right[i] = r root -= (l + r) def preorder(i): if i == -1: return print(' ', i, sep = '', end = '') preo...
s671952712
p02281
u626266743
1511267747
Python
Python3
py
Runtime Error
0
0
689
n = int(input()) tree = [None for i in range(n)] root = set(range(n)) for i in range(n): i, l, r = map(int, input().split()) left[i] = l right[i] = r root -= {1, r} def preorder(i): if i == -1: return print(' ', i, sep = '') preorder(left[i]) preorder(right[i]) def inord...
s632311170
p02281
u626266743
1511267779
Python
Python3
py
Runtime Error
0
0
719
n = int(input()) tree = [None for i in range(n)] root = set(range(n)) for i in range(n): i, l, r = map(int, input().split()) left[i] = l right[i] = r root -= {1, r} def preorder(i): if i == -1: return print(' ', i, sep = '', end = '') preorder(left[i]) preorder(right[i]) ...