buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
class Node: def __init__(self): self.parent = -1 def dfs(v, d=0): G[v].depth = d for child in G[v].children: dfs(child, d+1) N = int(input()) G = [Node() for _ in range(N)] for _ in range(N): idx, k, *children = [int(x) for x in input().split()] G[idx].children = children if ...
class Node: def __init__(self): self.parent = -1 def dfs(v, d=0): G[v].depth = d for child in G[v].children: dfs(child, d+1) N = int(input()) G = [Node() for _ in range(N)] for _ in range(N): idx, k, *children = [int(x) for x in input().split()] G[idx].children = children if ...
[["-", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6], ["+", 3, 4, 0, 652, 63, 319, 500, 557, 0, 6]]
5
237
2
n = int(input()) tree = [None] * n root = set(range(n)) def set_pd(i, parent, depth): node = tree[i] node[1], node[2] = parent, depth for child in node[0]: set_pd(child, i, depth + 1) while n: l = list(map(int, input().split())) c = set(l[2:]) tree[l[0]] = [c, None, None] root -=...
n = int(input()) tree = [None] * n root = set(range(n)) def set_pd(i, parent, depth): node = tree[i] node[1], node[2] = parent, depth for child in node[0]: set_pd(child, i, depth + 1) while n: l = list(map(int, input().split())) c = l[2:] tree[l[0]] = [c, None, None] root -= set(...
[["-", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 677, 12, 652, 63, 22], ["+", 0, 1, 0, 677, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 677, 12, 652, 3, 4, 0, 25]]
5
198
6
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...
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,se...
[["-", 8, 196, 0, 1, 0, 662, 12, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 206, 51, 22]]
5
294
4
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 _...
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()) tree = [[-1,0,0,0] for _ in range(n)] root ...
[["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 70], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 206, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 0, 73], ["+", 0, 652, 3, 4, 0, 652, 63, 319, 0, 131], ["+", 0, 652, 3, 4, 0, 652, 63, 319, 319, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
211
7
def set_info(a, i, p, d): a[i][1], a[i][2] = p, d for b in a[i][0]: set_info(a, b, i, d + 1) n = int(input()) tree = [[None] for i in range(n)] root = set(range(n)) for i in range(n): l = list(map(int, input().split())) tree[l[0]] = [l[2:], None, None] root -= set(l[2:]) set_info(tree, ro...
def set_info(a, i, p, d): a[i][1], a[i][2] = p, d for b in a[i][0]: set_info(a, b, i, d + 1) n = int(input()) tree = [[None] for i in range(n)] root = set(range(n)) for i in range(n): l = list(map(int, input().split())) tree[l[0]] = [l[2:], None, None] root -= set(l[2:]) set_info(tree, ro...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
240
2
import collections def search(node, elems, tree, depth): elems[node].append(depth) if elems[node][0] == -1: state = 'root' elif not tree[node]: state = 'leaf' else: state = 'internal node' elems[node].append(state) elems[node].append(tree[node]) depth += 1 for c ...
import collections def search(node, elems, tree, depth): elems[node].append(depth) if elems[node][0] == -1: state = 'root' elif not tree[node]: state = 'leaf' else: state = 'internal node' elems[node].append(state) elems[node].append(tree[node]) depth += 1 for c ...
[["+", 0, 57, 64, 196, 0, 7, 12, 652, 63, 22], ["+", 64, 196, 0, 7, 12, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
318
3
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'if ...
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'if ...
[["-", 0, 284, 205, 652, 63, 319, 500, 557, 0, 6], ["+", 0, 284, 205, 652, 63, 319, 500, 557, 0, 6]]
5
218
2
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): ...
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): ...
[["+", 8, 196, 0, 1, 0, 662, 31, 319, 500, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 319, 0, 131], ["+", 8, 196, 0, 1, 0, 662, 31, 319, 319, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 12, 22]]
5
478
5
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void setDepth(int, int); int setHeight(int); int getSibling(int); void print(int); int main() { int v, l, r, root = 0; int i; scanf("%d", &n); if (n...
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void setDepth(int, int); int setHeight(int); int getSibling(int); void print(int); int main() { int v, l, r, root = 0; int i; scanf("%d", &n); if (n...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
703
2
#include <stdio.h> #define Max 10000 #define NIL -1 typedef struct Node { int parent, l, r; } Node; Node T[Max]; int n, D[Max], H[Max]; void setDepth(int u, int d) { if (u == NIL) return; D[u] = d; setDepth(T[u].l, d + 1); setDepth(T[u].r, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if ...
#include <stdio.h> #define Max 10000 #define NIL -1 typedef struct Node { int parent, l, r; } Node; Node T[Max]; int n, D[Max], H[Max]; void setDepth(int u, int d) { if (u == NIL) return; D[u] = d; setDepth(T[u].l, d + 1); setDepth(T[u].r, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if ...
[["-", 64, 1, 0, 11, 31, 118, 28, 69, 71, 22], ["+", 64, 1, 0, 11, 31, 118, 28, 69, 71, 22]]
0
654
2
#include <stdio.h> #define MAX 10000 typedef struct { int parent, left, right; } Node; Node T[MAX]; int n, dep[MAX], hei[MAX]; void setdep(int value, int p) { if (value == -1) return; dep[value] = p; setdep(T[value].left, p + 1); setdep(T[value].right, p + 1); } int sethei(int value) { int hl = 0, hr...
#include <stdio.h> #define MAX 10000 typedef struct { int parent, left, right; } Node; Node T[MAX]; int n, dep[MAX], hei[MAX]; void setdep(int value, int p) { if (value == -1) return; dep[value] = p; setdep(T[value].left, p + 1); setdep(T[value].right, p + 1); } int sethei(int value) { int hl = 0, hr...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
633
2
#include <stdio.h> #define NIL -1 int setHeight(int); void setDepth(int, int); int getSibling(int); typedef struct { int parent, left_child, right_child, height, depth; } Tree; Tree Node[25]; int n; int main(void) { int i, j, node, left, right, degree; scanf("%d", &n); i = 0; while (i < n) { Node[i].pa...
// Binary Tree #include <stdio.h> #define NIL -1 int setHeight(int); void setDepth(int, int); int getSibling(int); typedef struct { int parent, left_child, right_child, height, depth; } Tree; Tree Node[25]; int n; int main(void) { int i, j, node, left, right, degree; scanf("%d", &n); i = 0; while (i < n) {...
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
0
685
3
#include <stdio.h> #include <stdlib.h> #define N 100000 #define NIL -1 typedef struct t { int id; int parent; int degree; int depth; int child[2]; int sibling; int height; } Tree; void depthcalculation(int, int); void heightcalculation(int); Tree T[N]; int maxdepth = 0; int main() { int treenum, i,...
#include <stdio.h> #include <stdlib.h> #define N 100000 #define NIL -1 typedef struct t { int id; int parent; int degree; int depth; int child[2]; int sibling; int height; } Tree; void depthcalculation(int, int); void heightcalculation(int); Tree T[N]; int maxdepth = 0; int main() { int treenum, i,...
[["-", 15, 23, 0, 16, 31, 69, 28, 118, 119, 120], ["-", 0, 57, 15, 23, 0, 16, 31, 69, 0, 70], ["-", 0, 57, 15, 23, 0, 16, 31, 69, 71, 13], ["-", 0, 57, 15, 23, 0, 16, 31, 69, 0, 73], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 22], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]]
0
698
7
#include <stdio.h> #define MAX 100000 struct Node { int parent, left, right; }; struct Node T[MAX]; int dep[MAX], h[MAX]; void SetDepth(int u, int d) { if (u == -1) return; dep[u] = d; SetDepth(T[u].left, d + 1); SetDepth(T[u].right, d + 1); } int SetHeight(int u) { int h1 = 0, h2 = 0; if (T[u].le...
#include <stdio.h> #define MAX 100000 struct Node { int parent, left, right; }; struct Node T[MAX]; int dep[MAX], h[MAX]; void SetDepth(int u, int d) { if (u == -1) return; dep[u] = d; SetDepth(T[u].left, d + 1); SetDepth(T[u].right, d + 1); } int SetHeight(int u) { int h1 = 0, h2 = 0; if (T[u].le...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
653
2
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int parent; int left; int right; } node; node T[MAX]; int n, D[MAX], H[MAX]; void Depth(int, int); int Height(int); int getSibling(int); void print(int); int main() { int v, l, r, i, root = 0; scanf("%d", &n); for (i = 0; i < n; i++)...
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int parent; int left; int right; } node; node T[MAX]; int n, D[MAX], H[MAX]; void Depth(int, int); int Height(int); int getSibling(int); void print(int); int main() { int v, l, r, i, root = 0; scanf("%d", &n); for (i = 0; i < n; i++)...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
687
2
#include <stdio.h> int v; int parent[100001]; int sibling[100001]; int degree[100001]; int Depth(int i); int Height(int i); int main() { int i, j; int id, l, r; scanf("%d", &v); for (i = 0; i < v; ++i) { parent[i] = -1; sibling[i] = -1; degree[i] = 0; } for (i = 0; i < v; ++i) { scanf("%d %d...
#include <stdio.h> int v; int parent[100001]; int sibling[100001]; int degree[100001]; int Depth(int i); int Height(int i); int main() { int i, j; int id, l, r; scanf("%d", &v); for (i = 0; i < v; ++i) { parent[i] = -1; sibling[i] = -1; degree[i] = 0; } for (i = 0; i < v; ++i) { scanf("%d %d...
[["-", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6]]
0
394
2
#include <stdio.h> #include <stdlib.h> typedef struct { int id; int parents; int left; int right; } Node; int height(Node *A, int i) { int tmp = 0, count = 0; if (A[i].right != -1) { count = height(A, A[i].right); } if (A[i].left != -1) { tmp = height(A, A[i].left); if (tmp > count) { ...
#include <stdio.h> #include <stdlib.h> typedef struct { int id; int parents; int left; int right; } Node; int height(Node *A, int i) { int tmp = 0, count = 0; if (A[i].right != -1) { count = height(A, A[i].right); } if (A[i].left != -1) { tmp = height(A, A[i].left); if (tmp > count) { ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
649
6
#include <stdio.h> #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; int getdepth(int u) { int d = 0; while (1) { u = T[u].p; if (u == NIL) { break; } d++; } return d; } int getsibling(int u) { if (T[u].p == NIL) { ...
#include <stdio.h> #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; int getdepth(int u) { int d = 0; while (1) { u = T[u].p; if (u == NIL) { break; } d++; } return d; } int getsibling(int u) { if (T[u].p == NIL) { ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
641
2
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define NIL -1 int parent[MAX], left[MAX], right[MAX]; int n, D[MAX], H[MAX]; int getDepth(int u) { int d = 0; while (parent[u] != NIL) { u = parent[u]; d++; } return d; } void setDepth(int u, int p) { D[u] = p; if (right[u] != NIL) { se...
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define NIL -1 int parent[MAX], left[MAX], right[MAX]; int n, D[MAX], H[MAX]; int getDepth(int u) { int d = 0; while (parent[u] != NIL) { u = parent[u]; d++; } return d; } void setDepth(int u, int p) { D[u] = p; if (right[u] != NIL) { se...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
666
3
#include <stdio.h> #define N 100001 #define Gard -1 typedef struct { int parent; int leftch; int rightch; } Tree; int Calheight(int); Tree Binary[N]; int main() { int loop, freq, lchild, rchild, count, change; int i; scanf("%d", &loop); for (i = 0; i < loop; i++) { Binary[i].parent = Gard; } ...
#include <stdio.h> #define N 100001 #define Gard -1 typedef struct { int parent; int leftch; int rightch; } Tree; int Calheight(int); Tree Binary[N]; int main() { int loop, freq, lchild, rchild, count, change; int i; scanf("%d", &loop); for (i = 0; i < loop; i++) { Binary[i].parent = Gard; } ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
609
6
#include <stdio.h> #include <stdlib.h> #define N 10000 #define NIL -1 typedef struct node { int parent; int right; int left; } Node; Node T[N]; int n, D[N], H[N]; void setDepth(int, int); void print(int); int setHeight(int); int getSibling(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); fo...
#include <stdio.h> #include <stdlib.h> #define N 10000 #define NIL -1 typedef struct node { int parent; int right; int left; } Node; Node T[N]; int n, D[N], H[N]; void setDepth(int, int); void print(int); int setHeight(int); int getSibling(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); fo...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
698
2
// Binary Trees #include <stdio.h> #define MAX 25 // 接点の個数の上限 #define NIL -1 // 接点番号として使われない値を設定(とりあえず-1としておく) struct node { int parent; // 接点の親を参照 int left; // 左の子を参照 int right; // 右の子を参照 }; struct node T[MAX]; int getDegree(int); int getDepth(int); int getSibling(int); int getHeight(int); int printNodeType...
// Binary Trees #include <stdio.h> #define MAX 25 // 接点の個数の上限 #define NIL -1 // 接点番号として使われない値を設定(とりあえず-1としておく) struct node { int parent; // 接点の親を参照 int left; // 左の子を参照 int right; // 右の子を参照 }; struct node T[MAX]; int getDegree(int); int getDepth(int); int getSibling(int); int getHeight(int); int printNodeType...
[["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 106], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 98]]
0
604
2
#include <stdio.h> #include <stdlib.h> #include <string.h> struct treetype { int parent; int sibling; int degree; int depth; int height; char type[20]; int left; int right; }; int main(void) { int n; struct treetype tree[26]; int i, j, k; int depthmax = 0; int number = 0; int roottr = 0; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> struct treetype { int parent; int sibling; int degree; int depth; int height; char type[20]; int left; int right; }; int main(void) { int n; struct treetype tree[26]; int i, j, k; int depthmax = 0; int number = 0; int roottr = 0; ...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 20], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 20], ["-", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 61, 0, 5, 0, 44]]
0
670
7
#include <stdio.h> #define MAX 10000 #define NIL -1 struct NODE { int p, left, right; }; struct NODE Tree[MAX]; int n, Depth[MAX], Height[MAX]; void makedepth(int, int); int makeheight(int); int makesibling(int); int main() { int i, j, v, l, r, deg, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { Tre...
#include <stdio.h> #define MAX 10000 #define NIL -1 struct NODE { int p, left, right; }; struct NODE Tree[MAX]; int n, Depth[MAX], Height[MAX]; void makedepth(int, int); int makeheight(int); int makesibling(int); int main() { int i, j, v, l, r, deg, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { Tre...
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79]]
0
661
4
#include <stdio.h> #define MAX 25 typedef struct node { int p; int left; int right; int sib; int deg; } Node; int Depth[MAX]; int Height[MAX]; Node node[MAX]; void depth(int x, int y) { Depth[x] = y; if (node[x].left != -1) depth(node[x].left, y + 1); if (node[x].right != -1) depth(node[x].ri...
#include <stdio.h> #define MAX 25 typedef struct node { int p; int left; int right; int sib; int deg; } Node; int Depth[MAX]; int Height[MAX]; Node node[MAX]; void depth(int x, int y) { Depth[x] = y; if (node[x].left != -1) depth(node[x].left, y + 1); if (node[x].right != -1) depth(node[x].ri...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
0
676
2
#include <stdio.h> #define MAX 10000 #define NIL -1 #define t 1 struct Node { int p, q, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; int getdepth(int u) { int d1 = 0; while (t) { u = T[u].p; if (u == NIL) { break; } d1++; } return d1; } int getsibling(int u) { if (T[u].p == NI...
#include <stdio.h> #define MAX 10000 #define NIL -1 #define t 1 struct Node { int p, q, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; int getdepth(int u) { int d1 = 0; while (t) { u = T[u].p; if (u == NIL) { break; } d1++; } return d1; } int getsibling(int u) { if (T[u].p == NI...
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
0
666
2
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Nodes { int parent; int left; int right; }; struct Nodes Node[MAX]; int Depth[MAX]; int Height[MAX]; int getS(int a) { if (Node[a].parent == NIL) return NIL; if (Node[Node[a].parent].left != a && Node[Node[a].parent].left != NIL) { return N...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Nodes { int parent; int left; int right; }; struct Nodes Node[MAX]; int Depth[MAX]; int Height[MAX]; int getS(int a) { if (Node[a].parent == NIL) return NIL; if (Node[Node[a].parent].left != a && Node[Node[a].parent].left != NIL) { return N...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
659
8
#include <stdio.h> #define MAX 1000005 #define NIL -1 struct Node { int p, l, r; }; struct Node tree[MAX]; int n, D[MAX], H[MAX]; int getSibling(int u) { if (tree[u].p == NIL) { return NIL; } if (tree[tree[u].p].l != u && tree[tree[u].p].l != NIL) { return tree[tree[u].p].l; } if (tree[tree[u].p]....
#include <stdio.h> #define MAX 1000005 #define NIL -1 struct Node { int p, l, r; }; struct Node tree[MAX]; int n, D[MAX], H[MAX]; int getSibling(int u) { if (tree[u].p == NIL) { return NIL; } if (tree[tree[u].p].l != u && tree[tree[u].p].l != NIL) { return tree[tree[u].p].l; } if (tree[tree[u].p]....
[["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22]]
0
674
2
#include <stdio.h> #include <stdlib.h> #define MAX 100000 struct node { int parent; int left; int right; }; struct node t[MAX]; int n, D[MAX], H[MAX]; void setdepth(int u, int d) { if (u == -1) return; D[u] = d; setdepth(t[u].left, d + 1); setdepth(t[u].right, d + 1); } int setheight(int u) { i...
#include <stdio.h> #include <stdlib.h> #define MAX 100000 struct node { int parent; int left; int right; }; struct node t[MAX]; int n, D[MAX], H[MAX]; void setdepth(int u, int d) { if (u == -1) return; D[u] = d; setdepth(t[u].left, d + 1); setdepth(t[u].right, d + 1); } int setheight(int u) { i...
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
0
650
4
#include <stdio.h> #define NIL -1 #define MAX 100000 typedef struct Node { int parent, lf, rg; } node; node ttt[MAX]; int k, ddd[MAX], hhh[MAX]; void Dep(int u, int p) { if (u = NIL) return; ddd[u] = p; Dep(ttt[u].lf, p + 1); Dep(ttt[u].rg, p + 1); } int Height(int u) { int p1 = 0, p2 = 0; if (t...
#include <stdio.h> #define NIL -1 #define MAX 100000 typedef struct Node { int parent, lf, rg; } node; node ttt[MAX]; int k, ddd[MAX], hhh[MAX]; void Dep(int u, int p) { if (u == NIL) return; ddd[u] = p; Dep(ttt[u].lf, p + 1); Dep(ttt[u].rg, p + 1); } int Height(int u) { int p1 = 0, p2 = 0; if (...
[["-", 8, 9, 0, 57, 15, 23, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60]]
0
669
2
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; int right; } node; void initNode(node *a, int length) { int i; for (i = 0; i < length; i++) { a[i].parent = -1; } } void scanNode(node *a, int length) { int i, id; for (i = 0; i < length; i++) { scanf("%d", &id); ...
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; int right; } node; void initNode(node *a, int length) { int i; for (i = 0; i < length; i++) { a[i].parent = -1; } } void scanNode(node *a, int length) { int i, id; for (i = 0; i < length; i++) { scanf("%d", &id); ...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
0
687
4
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; int right; } Node; Node T[25]; int n; void maigoCenter(void); int findSibling(int); int countDegree(int); int findDepth(int); int findHeight(int); void printType(int); int main() { int i, id; scanf("%d", &n); for (i = 0; i <...
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; int right; } Node; Node T[25]; int n; void maigoCenter(void); int findSibling(int); int countDegree(int); int findDepth(int); int findHeight(int); void printType(int); int main() { int i, id; scanf("%d", &n); for (i = 0; i <...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22]]
0
668
2
#include <stdio.h> #include <string.h> typedef struct D { int n, r, l, d, p, dep, h, sub, deg; } D; D node[30]; int i, j, N, r, l, n; int dfs(int p, int d) { int a, b; if (p == -1) return -1; node[p].dep = d; a = dfs(node[p].r, d + 1); b = dfs(node[p].l, d + 1); if (a == -1 && b == -1) node[p]....
#include <stdio.h> #include <string.h> typedef struct D { int n, r, l, d, p, dep, h, sub, deg; } D; D node[30]; int i, j, N, r, l, n; int dfs(int p, int d) { int a, b; if (p == -1) return -1; node[p].dep = d; a = dfs(node[p].r, d + 1); b = dfs(node[p].l, d + 1); if (a == -1 && b == -1) node[p]....
[["-", 0, 41, 75, 41, 15, 16, 31, 16, 17, 79], ["+", 0, 41, 75, 41, 15, 16, 31, 16, 17, 60], ["-", 0, 41, 75, 41, 15, 16, 12, 16, 17, 79], ["+", 0, 41, 75, 41, 15, 16, 12, 16, 17, 60]]
0
440
4
#include <stdio.h> #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, depth[MAX], height[MAX]; void Depth(int, int); int Height(int); int Sibling(int); void print(int); int main() { int i; int id, left, right, tmp = 0; scanf("%d", &n); for (i = 0; i < n; i++) ...
#include <stdio.h> #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, depth[MAX], height[MAX]; void Depth(int, int); int Height(int); int Sibling(int); void print(int); int main() { int i; int id, left, right, tmp = 0; scanf("%d", &n); for (i = 0; i < n; i++) ...
[["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 12, 22]]
0
649
2
#include <stdio.h> #define N 10000 int Height(int); void print(int); int Sibling(int); void Depth(int, int); struct Node { int parent; int left; int right; }; struct Node T[N]; int n, D[N], H[N]; int main() { int p, l, r, root = 0, i; scanf("%d", &n); for (i = 0; i < n; i++) T[i].parent = -1; for (i ...
#include <stdio.h> #define N 10000 int Height(int); void print(int); int Sibling(int); void Depth(int, int); struct Node { int parent; int left; int right; }; struct Node T[N]; int n, D[N], H[N]; int main() { int p, l, r, root = 0, i; scanf("%d", &n); for (i = 0; i < n; i++) T[i].parent = -1; for (i ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
678
6
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p, l, r; } Node; void setdepth(int, int); int setheight(int); void print(int); int getsibling(int); Node T[MAX]; int n, D[MAX], H[MAX]; int main() { int v, l, r, i, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = N...
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p, l, r; } Node; void setdepth(int, int); int setheight(int); void print(int); int getsibling(int); Node T[MAX]; int n, D[MAX], H[MAX]; int main() { int v, l, r, i, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = N...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
682
2
#include <stdio.h> void getH(int, int); typedef struct { int parent; int child; int brother; int child2; int deg; } node; node n[100000]; int H; int main() { int a, c, d, e, i, j, num, depth; scanf("%d", &num); for (i = 0; i < num; i++) { n[i].parent = -1; n[i].brother = -1; n[i].child = -...
#include <stdio.h> void getH(int, int); typedef struct { int parent; int child; int brother; int child2; int deg; } node; node n[100000]; int H; int main() { int a, c, d, e, i, j, num, depth; scanf("%d", &num); for (i = 0; i < num; i++) { n[i].parent = -1; n[i].brother = -1; n[i].child = -...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
504
2
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define MIN -1 typedef struct { int p, l, r; } Node; Node node[MAX]; int n, height[MAX], depth[MAX]; int Height(int); int Sibling(int); void Depth(int, int); void Print(int); int Height(int u) { int h1 = 0, h2 = 0; if (node[u].l != MIN) { h1 = Hei...
#include <stdio.h> #include <stdlib.h> #define MAX 10000 #define MIN -1 typedef struct { int p, l, r; } Node; Node node[MAX]; int n, height[MAX], depth[MAX]; int Height(int); int Sibling(int); void Depth(int, int); void Print(int); int Height(int u) { int h1 = 0, h2 = 0; if (node[u].l != MIN) { h1 = Hei...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
665
2
#include <stdio.h> #define N 25 #define EMPTY -1 typedef struct { int parent; int left; int right; } Node; int depth[N]; int height[N]; Node node[N]; void depthcount(int x, int d) { if (x == EMPTY) return; depth[x] = d; depthcount(node[x].right, d + 1); depthcount(node[x].left, d + 1); } int heigh...
#include <stdio.h> #define N 25 #define EMPTY -1 typedef struct { int parent; int left; int right; } Node; int depth[N]; int height[N]; Node node[N]; void depthcount(int x, int d) { if (x == EMPTY) return; depth[x] = d; depthcount(node[x].right, d + 1); depthcount(node[x].left, d + 1); } int heigh...
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
0
650
3
#include <stdio.h> #define N 10000 #define Nil -1 typedef struct { int p, l, r; } Node; Node T[N]; int n, D[N], H[N]; void setDepth(int, int); int setHeight(int); int getSibling(int); void print(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = Nil; for ...
#include <stdio.h> #define N 10000 #define Nil -1 typedef struct { int p, l, r; } Node; Node T[N]; int n, D[N], H[N]; void setDepth(int, int); int setHeight(int); int getSibling(int); void print(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = Nil; for ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
647
2
#include <stdio.h> #define MAX 100000 struct Node { int p, l, r; }; struct Node T[MAX]; int D[MAX], H[MAX]; int Sibling(int); void Depth(int, int); int Height(int); void print(int); int main() { int i, n, left, right, id, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = -1; } for (i...
#include <stdio.h> #define MAX 100000 struct Node { int p, l, r; }; struct Node T[MAX]; int D[MAX], H[MAX]; int Sibling(int); void Depth(int, int); int Height(int); void print(int); int main() { int i, n, left, right, id, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = -1; } for (i...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
666
3
/* * Binary Tree * output 1)node_number, 2)parent_number, 3)depth, 4)kind_of_node, 5)child_list */ /* inclution */ #include <stdio.h> /* Definition */ #define MAX 100000 #define NIL -1 /* Prototype */ void printTree(int); void setDepth(int, int); int setHeight(int); int getSibling(int); int getDegree(int); /* Gl...
/* * Binary Tree * output 1)node_number, 2)parent_number, 3)depth, 4)kind_of_node, 5)child_list */ /* inclution */ #include <stdio.h> /* Definition */ #define MAX 100000 #define NIL -1 /* Prototype */ void printTree(int); void setDepth(int, int); int setHeight(int); int getSibling(int); int getDegree(int); /* Gl...
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
0
839
4
#include <stdio.h> #define MAX 25 typedef struct { int parent; int left; int right; } node; node nodes[MAX] = {0}; int H[MAX]; int getDepth(int num) { int d = 0; while (nodes[num].parent != -1) { num = nodes[num].parent; ++d; } return d; } int getDegree(int num) { if (nodes[num].left == -1 ...
#include <stdio.h> #define MAX 25 typedef struct { int parent; int left; int right; } node; node nodes[MAX] = {0}; int H[MAX]; int getDepth(int num) { int d = 0; while (nodes[num].parent != -1) { num = nodes[num].parent; ++d; } return d; } int getDegree(int num) { if (nodes[num].left == -1 ...
[["-", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13]]
0
645
2
#include <stdio.h> #define M 10000 #define NIL -1 typedef struct { int parent, left, right; } Node; Node T[M]; int n, D[M], H[M]; void setDepth(int a, int b) { if (a == NIL) return; D[a] = b; setDepth(T[a].left, b + 1); setDepth(T[a].right, b + 1); } int setHeight(int a) { int h1 = 0; int h2 = 0; ...
#include <stdio.h> #define M 10000 #define NIL -1 typedef struct { int parent, left, right; } Node; Node T[M]; int n, D[M], H[M]; void setDepth(int a, int b) { if (a == NIL) return; D[a] = b; setDepth(T[a].left, b + 1); setDepth(T[a].right, b + 1); } int setHeight(int a) { int h1 = 0; int h2 = 0; ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
663
2
#include <stdio.h> #include <string.h> #define MAX 100005 typedef struct { int parent; int left; int right; } Roll; int max(int h1, int h2) { if (h1 > h2) return h1; else return h2; } int Depth(int root, int d, int *Dep, Roll *Tree) { if (root == -1) return -1; Dep[root] = d; Depth(Tree[...
#include <stdio.h> #include <string.h> #define MAX 100005 typedef struct { int parent; int left; int right; } Roll; int max(int h1, int h2) { if (h1 > h2) return h1; else return h2; } int Depth(int root, int d, int *Dep, Roll *Tree) { if (root == -1) return -1; Dep[root] = d; Depth(Tree[...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
740
2
#include <stdio.h> #define Max 10000 #define None -1 typedef struct { int parent, left, right; } Node; Node Tree[Max]; int n, Depth[Max], Height[Max]; int Dep(int, int); int Hei(int); void print_out(int); int Sibling(int); int main() { int v, l, r, i; int root = 0; scanf("%d", &n); for (i = 0; i < n; i++) ...
#include <stdio.h> #define Max 10000 #define None -1 typedef struct { int parent, left, right; } Node; Node Tree[Max]; int n, Depth[Max], Height[Max]; int Dep(int, int); int Hei(int); void print_out(int); int Sibling(int); int main() { int v, l, r, i; int root = 0; scanf("%d", &n); for (i = 0; i < n; i++) ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
686
4
#include <stdio.h> #define N 25 #define NIL -1 typedef struct { int p, l, r; } Node_t; Node_t T[N]; int n, D[N], H[N]; void setDep(int u, int d) { //??±?????\??? if (u == NIL) return; D[u] = d; setDep(T[u].l, d + 1); setDep(T[u].r, d + 1); } int setHe(int u) { //????????\??? int h1 = 0, h2 = 0; if...
#include <stdio.h> #define N 25 #define NIL -1 typedef struct { int p, l, r; } Node_t; Node_t T[N]; int n, D[N], H[N]; void setDep(int u, int d) { //??±?????\??? if (u == NIL) return; D[u] = d; setDep(T[u].l, d + 1); setDep(T[u].r, d + 1); } int setHe(int u) { //????????\??? int h1 = 0, h2 = 0; if...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
632
2
#include <stdio.h> #define N 10000 void sD(int, int); int sH(int); int gS(int); typedef struct { int p, l, r; } Node; Node T[N]; int n; int D[N], H[N]; void sD(int a, int b) { if (a == -1) return; D[a] = b; sD(T[a].l, b + 1); sD(T[a].r, b + 1); } int sH(int a) { int x = 0, y = 0; if (T[a].l != -1)...
#include <stdio.h> #define N 10000 void sD(int, int); int sH(int); int gS(int); typedef struct { int p, l, r; } Node; Node T[N]; int n; int D[N], H[N]; void sD(int a, int b) { if (a == -1) return; D[a] = b; sD(T[a].l, b + 1); sD(T[a].r, b + 1); } int sH(int a) { int x = 0, y = 0; if (T[a].l != -1)...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
657
2
#include <stdio.h> #define N 100000 #define NIL -1 int depth(int); int height(int); struct Node { int parent; int left; int right; }; struct Node T[N]; int main() { int n, i, id; scanf("%d", &n); for (i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL; for (i = 0; i < n; i++) { ...
#include <stdio.h> #define N 100000 #define NIL -1 int depth(int); int height(int); struct Node { int parent; int left; int right; }; struct Node T[N]; int main() { int n, i, id; scanf("%d", &n); for (i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL; for (i = 0; i < n; i++) { ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
598
2
#include <stdio.h> struct Node { int parent, left, right; }; struct Node T[10000]; int n, D[10000], H[10000]; void Depth(int u, int d) { if (u == -1) return; D[u] = d; Depth(T[u].left, d + 1); Depth(T[u].right, d + 1); } int Height(int u) { int h1 = 0; int h2 = 0; if (T[u].left != -1) { h1 = ...
#include <stdio.h> struct Node { int parent, left, right; }; struct Node T[10000]; int n, D[10000], H[10000]; void Depth(int u, int d) { if (u == -1) return; D[u] = d; Depth(T[u].left, d + 1); Depth(T[u].right, d + 1); } int Height(int u) { int h1 = 0; int h2 = 0; if (T[u].left != -1) { h1 = ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
651
2
#include <stdio.h> #define MAX 25 struct Node { int parent; int right; int left; int degree; }; int n; struct Node u[MAX]; int sibling(int); int depth(int); int height(int); int main() { int i, id, r, l; scanf("%d", &n); for (i = 0; i < n; i++) { u[i].parent = -1; u[i].right = -1; u[i]....
#include <stdio.h> #define MAX 25 struct Node { int parent; int right; int left; int degree; }; int n; struct Node u[MAX]; int sibling(int); int depth(int); int height(int); int main() { int i, id, r, l; scanf("%d", &n); for (i = 0; i < n; i++) { u[i].parent = -1; u[i].right = -1; u[i]....
[["-", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120], ["-", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 12, 13]]
0
588
4
#include <stdio.h> #define NIL -1 #define MAX 10000 struct Node { int p; int l; int r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void setDepth(int, int); int setHeight(int); int getSibling(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = NIL; for (i = ...
#include <stdio.h> #define NIL -1 #define MAX 10000 struct Node { int p; int l; int r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void setDepth(int, int); int setHeight(int); int getSibling(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = NIL; for (i = ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
635
4
# ALDS1_7_B: Binary Tree class Node class << self def bind(parent, left, right) parent.set_children(left, right) left.set_parent(parent, :left) right.set_parent(parent, :right) end end attr_accessor :id, :left, :right attr_reader :depth, :height def initialize(id) @id = id ...
# ALDS1_7_B: Binary Tree class Node class << self def bind(parent, left, right) parent.set_children(left, right) left.set_parent(parent, :left) right.set_parent(parent, :right) end end attr_accessor :id, :left, :right attr_reader :depth, :height def initialize(id) @id = id ...
[["-", 0, 662, 12, 738, 31, 739, 0, 754, 64, 22], ["-", 0, 662, 12, 738, 31, 739, 0, 754, 0, 102], ["+", 0, 662, 12, 738, 31, 739, 0, 754, 0, 102], ["+", 0, 662, 12, 738, 31, 739, 0, 754, 75, 22]]
4
434
4
#binary_tree class Node attr_accessor :myname,:parent,:left,:right,:depth,:height def initialize(n) @myname = n @parent = nil @left = nil @right = nil @depth = 0 end def add_left(child) self.left = child child.parent = self end def add_right(child) self.right ...
#binary_tree class Node attr_accessor :myname,:parent,:left,:right,:depth,:height def initialize(n) @myname = n @parent = nil @left = nil @right = nil @depth = 0 end def add_left(child) self.left = child child.parent = self end def add_right(child) self.right ...
[["-", 0, 121, 15, 739, 0, 738, 31, 652, 735, 22], ["+", 0, 121, 15, 739, 0, 738, 31, 652, 735, 22], ["-", 8, 734, 0, 121, 15, 738, 12, 748, 17, 33], ["-", 8, 734, 0, 121, 15, 738, 12, 748, 439, 612], ["+", 8, 734, 0, 121, 15, 738, 12, 477, 0, 477], ["-", 36, 36, 36, 36, 0, 493, 0, 662, 12, 612], ["+", 36, 36, 36, 36, ...
4
554
7
$arr=Array.new() class BinaryTree attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children def initialize(id,children,degree) @id=id @parent=-1 @sibling=-1 @degree=degree @height=0 @children=children @type=(children==[-1,-1] ? 'leaf' :'internal node') end def print ...
$arr=Array.new() class BinaryTree attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children def initialize(id,children,degree) @id=id @parent=-1 @sibling=-1 @degree=degree @height=0 @children=children @type=(children==[-1,-1] ? 'leaf' :'internal node') end def print ...
[["-", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 8, 736, 0, 652, 3, 4, 0, 557, 0, 6]]
4
364
2
class Node attr_reader :id, :left, :right attr_accessor :parent def initialize(id) @id = id @parent = nil @left = nil @right = nil end def left=(child) child.parent = self @left = child end def right=(child) child.parent = self @right = child end def sibling ret...
class Node attr_reader :id, :left, :right attr_accessor :parent def initialize(id) @id = id @parent = nil @left = nil @right = nil end def left=(child) child.parent = self @left = child end def right=(child) child.parent = self @right = child end def sibling ret...
[["+", 0, 735, 8, 736, 0, 652, 486, 652, 735, 22], ["+", 8, 736, 0, 735, 8, 736, 0, 652, 17, 131]]
4
320
2
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 if left != -1: binary_tree[left]["parent"] = id if r...
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 if left != -1: binary_tree[left]["parent"] = id if r...
[["-", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22]]
5
521
2
class Node: def __init__(self, id): self.id = id self.left = None self.right = None self.sibling = None self.degree = 0 self.parent = None self.depth = -1 self.nodeType = '' def __repr__(self): return self.__str__() def __str__(self):...
class Node: def __init__(self, id): self.id = id self.left = None self.right = None self.sibling = None self.degree = 0 self.parent = None self.depth = -1 self.nodeType = '' def __repr__(self): return self.__str__() def __str__(self):...
[["-", 31, 657, 31, 657, 31, 657, 12, 557, 0, 6], ["+", 31, 657, 31, 657, 31, 657, 12, 557, 0, 6]]
5
562
2
#coding:UTF-8 def depth(leaf,A,d): for i in range(len(A)): if A[i][1]==leaf or A[i][2]==leaf: return depth(A[i][0],A,d+1) return d def height(n,A,h): if n[1]!=-1 and n[2]!=-1: return max(height(A[n[1]],A,h+1),height(A[n[2]],A,h+1)) return h def BT(A,n): for i in range(n...
#coding:UTF-8 def depth(leaf,A,d): for i in range(len(A)): if A[i][1]==leaf or A[i][2]==leaf: return depth(A[i][0],A,d+1) return d def height(n,A,h): if n[1]!=-1 or n[2]!=-1: return max(height(A[n[1]],A,h+1),height(A[n[2]],A,h+1)) return h def BT(A,n): for i in range(n)...
[["-", 0, 14, 8, 196, 0, 57, 15, 679, 17, 355], ["+", 0, 14, 8, 196, 0, 57, 15, 679, 17, 354]]
5
762
2
def part(a, q, r) x = a[r][1] i = q - 1 for j in 0...r - q if a[q + j][1] <= x i += 1 a[i], a[q + j] = a[q + j], a[i] end end a[i + 1], a[r] = a[r], a[i + 1] return i + 1 end def qsort(a, q = nil, r = nil) q, r = 0, a.length - 1 if !q if q < r x = part(a, q, r) qsort(a, q, x ...
def part(a, q, r) x = a[r][1] i = q - 1 for j in 0...r - q if a[q + j][1] <= x i += 1 a[i], a[q + j] = a[q + j], a[i] end end a[i + 1], a[r] = a[r], a[i + 1] return i + 1 end def qsort(a, q = nil, r = nil) q, r = 0, a.length - 1 if !q if q < r x = part(a, q, r) qsort(a, q, x ...
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22]]
4
279
2
def q a,l,r l<r&&( i=0 (l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)} a[i],a[r]=a[r],a[i] q a,l,i-1 q a,i+1,r ) end gets a=$<.to_a b=a.dup q b,n=0,b.size-1 puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
def q a,l,r l<r&&( i=l (l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)} a[i],a[r]=a[r],a[i] q a,l,i-1 q a,i+1,r ) end gets a=$<.to_a b=a.dup q b,n=0,b.size-1 puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
[["-", 8, 736, 0, 738, 12, 739, 0, 662, 12, 612], ["+", 8, 736, 0, 738, 12, 739, 0, 662, 12, 22]]
4
171
2
def partition(a, p, r) x = a[r][1] i = p-1 p.upto(r-1) do |j| if a[j][1] <= x i += 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i+1 end def quickSort(a, p, r) if p < r q = partition(a, p, r) quickSort(a, p, q-1) quickSort(a, q+1, r) end end INFTY = 9999999999 def merge...
def partition(a, p, r) x = a[r][1] i = p-1 p.upto(r-1) do |j| if a[j][1] <= x i += 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i+1 end def quickSort(a, p, r) if p < r q = partition(a, p, r) quickSort(a, p, q-1) quickSort(a, q+1, r) end end INFTY = 9999999999 def merge...
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22]]
4
497
2
def partition(a, p, r) unused, x = a[r].split(' ') i = p - 1 p.upto(r-1) do |j| unused, aj = a[j].split(' ') if aj.to_i <= x.to_i i = i + 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i + 1 end def quickSort(a, p, r) if p < r q = partition(a, p, r) q...
def partition(a, p, r) unused, x = a[r].split(' ') i = p - 1 p.upto(r-1) do |j| unused, aj = a[j].split(' ') if aj.to_i <= x.to_i i = i + 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i + 1 end def quickSort(a, p, r) if p < r q = partition(a, p, r) q...
[["-", 8, 736, 0, 652, 486, 739, 0, 738, 17, 33], ["-", 8, 736, 0, 652, 486, 739, 0, 738, 12, 612]]
4
351
2
def partition(a, p ,r) x = a[r][1] i = p-1 (p...r).each do |j| if a[j][1] <= x i += 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i+1 end def quick_sort(a, p, r) if p < r q = partition(a, p, r) quick_sort(a, p, q-1) quick_sort(a, q+1, r) end end n...
def partition(a, p ,r) x = a[r][1] i = p-1 (p...r).each do |j| if a[j][1] <= x i += 1 a[i], a[j] = a[j], a[i] end end a[i+1], a[r] = a[r], a[i+1] return i+1 end def quick_sort(a, p, r) if p < r q = partition(a, p, r) quick_sort(a, p, q-1) quick_sort(a, q+1, r) end end n...
[["-", 0, 745, 8, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 745, 8, 652, 3, 4, 0, 557, 0, 6]]
4
313
2
Card = Struct.new(:suit, :value) do include Comparable def <=>(other) value <=> other.value end def to_s [suit, value].join(' ') end end def merge_sort(arr) return arr if arr.size <= 1 mid = arr.size / 2 arr1 = arr[0...mid] arr2 = arr[mid..-1] merge(merge_sort(arr1), merge_sort(arr2)) ...
Card = Struct.new(:suit, :value) do include Comparable def <=>(other) value <=> other.value end def to_s [suit, value].join(' ') end end def merge_sort(arr) return arr if arr.size <= 1 mid = arr.size / 2 arr1 = arr[0...mid] arr2 = arr[mid..-1] merge(merge_sort(arr1), merge_sort(arr2)) ...
[["+", 0, 493, 0, 121, 64, 749, 0, 662, 31, 22], ["+", 0, 493, 0, 121, 64, 749, 0, 662, 0, 32]]
4
406
2
def solve(n, cards) a = [] b = [] p cards for j in 0..(n-1) m = cards[j][0] i = cards[j][1].to_i a.push([m, i]) b.push([m, i]) end qsort(a, 0, n-1) stable = true (0..n-2).each do |i| if (a[i][1] == a[i+1][1]) if b.index(a[i]) > b.index(a[i+1]) ...
def solve(n, cards) a = [] b = [] for j in 0..(n-1) m = cards[j][0] i = cards[j][1].to_i a.push([m, i]) b.push([m, i]) end qsort(a, 0, n-1) stable = true (0..n-2).each do |i| if (a[i][1] == a[i+1][1]) if b.index(a[i]) > b.index(a[i+1]) sta...
[["-", 0, 493, 0, 735, 8, 736, 0, 652, 735, 22], ["-", 0, 735, 8, 736, 0, 652, 3, 4, 0, 22]]
4
353
2
class Card def initialize(mark, number) @mark = mark @number = number.to_i end def to_s "#{mark} #{number}" end attr_accessor :number, :mark end def partition(array, p, r) x = array[r].number i = p - 1 p.upto(r - 1) do |index| if array[index].number <= x i += 1 array[i], a...
class Card def initialize(mark, number) @mark = mark @number = number.to_i end def to_s "#{mark} #{number}" end attr_accessor :number, :mark end def partition(array, p, r) x = array[r].number i = p - 1 p.upto(r - 1) do |index| if array[index].number <= x i += 1 array[i], a...
[["-", 196, 737, 8, 736, 0, 121, 15, 738, 17, 18], ["+", 196, 737, 8, 736, 0, 121, 15, 738, 17, 19]]
4
441
2
def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q-1) quick_sort(q+1, r) def merge(left, ...
def partition(p, r): i = p for j in range(p, r): if A[r][1] >= A[j][1]: A[i], A[j] = A[j], A[i] i += 1 A[r], A[i] = A[i], A[r] return i def quick_sort(p, r): if p < r: q = partition(p, r) quick_sort(p, q-1) quick_sort(q+1, r) def merge(left, ...
[["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 147]]
5
410
3
def InputData(): sequence_len = int(input()) sequence = [input().split(" ") for _ in range(sequence_len)] sequence_m = [(a[0], int(a[1])) for a in sequence] sequence_q = [(a[0], int(a[1])) for a in sequence] return sequence_len, sequence_m, sequence_q def partition(sequence, p, r): x = seq...
def InputData(): sequence_len = int(input()) sequence = [input().split(" ") for _ in range(sequence_len)] sequence_m = [(a[0], int(a[1])) for a in sequence] sequence_q = [(a[0], int(a[1])) for a in sequence] return sequence_len, sequence_m, sequence_q def partition(sequence, p, r): x = seq...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
500
2
import copy INF = 10000000000 def merge(A, left, mid, right): count = 0 L = A[left:mid] + [(INF,INF)] R = A[mid:right] + [(INF,INF)] i, j = 0, 0 for k in range(left, right): count = count + 1 if L[i][1] <= R[j][1]: A[k] = L[i] i = i + 1 else: ...
import copy INF = 10000000000 def merge(A, left, mid, right): count = 0 L = A[left:mid] + [(INF,INF)] R = A[mid:right] + [(INF,INF)] i, j = 0, 0 for k in range(left, right): count = count + 1 if L[i][1] <= R[j][1]: A[k] = L[i] i = i + 1 else: ...
[["-", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22]]
5
463
4
#coding:utf-8 #1_6_C def partition(A, p, r): x = int(A[r][1]) i = p - 1 for j in range(p, r): if int(A[j][1]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) ...
#coding:utf-8 #1_6_C def partition(A, p, r): x = int(A[r][1]) i = p - 1 for j in range(p, r): if int(A[j][1]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) ...
[["-", 0, 57, 64, 196, 0, 37, 0, 557, 0, 6], ["+", 0, 57, 64, 196, 0, 37, 0, 557, 0, 6]]
5
367
2
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Input: 6 D 3 H 2 D 1 S 3 D 2 C 1 Output: Not stable / Stable D 1 C 1 D 2 H 2 D 3 S 3 """ import sys import copy def partition(array, start, end): x = int(array[end][2:]) i = start - 1 assert start <= end for j in range(start, end): if int(arr...
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Input: 6 D 3 H 2 D 1 S 3 D 2 C 1 Output: Not stable / Stable D 1 C 1 D 2 H 2 D 3 S 3 """ import sys import copy def partition(array, start, end): x = int(array[end][2:]) i = start - 1 assert start <= end for j in range(start, end): if int(arr...
[["-", 8, 196, 0, 57, 15, 666, 0, 657, 17, 72], ["-", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["+", 12, 652, 3, 4, 0, 653, 51, 657, 17, 33], ["+", 12, 652, 3, 4, 0, 653, 51, 657, 12, 612]]
5
478
4
def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = A[left:mid] R = A[mid:right] L.appen...
def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = A[left:mid] R = A[mid:right] L.appen...
[["+", 0, 14, 8, 196, 0, 37, 0, 657, 17, 72], ["+", 0, 14, 8, 196, 0, 37, 0, 657, 12, 612]]
5
476
2
def mergesort(A, s, e): if s + 1 < e: m = (e + s) // 2 mergesort(A, s, m) mergesort(A, m, e) merge(A, s, m, e) def merge(A, s, m, e): L = A[s:m] + [('*', 1E10)] R = A[m:e] + [('*', 1E10)] ix_l = ix_r = 0 for ix in range(s, e): if L[ix_l][1] < R[ix_r][1]: ...
def mergesort(A, s, e): if s + 1 < e: m = (e + s) // 2 mergesort(A, s, m) mergesort(A, m, e) merge(A, s, m, e) def merge(A, s, m, e): L = A[s:m] + [('*', 1E10)] R = A[m:e] + [('*', 1E10)] ix_l = ix_r = 0 for ix in range(s, e): if L[ix_l][1] <= R[ix_r][1]: ...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 64, 196, 0, 1, 0, 662, 12, 206, 0, 70], ["+", 0, 1, 0, 662, 12, 206, 206, 663, 0, 102], ["+", 64, 196, 0, 1, 0, 662, 12, 206, 0, 73], ["-", 15, 652, 3, 4, 0, 658, 8, 666, 0, 612], ["+", 15, 652, 3, 4, 0, 658, 8, 666, 0, 2...
5
444
7
# -*- coding:utf-8 -*- import sys class Card(object): def __init__(self, card): self._suit = card[0] self._value = int(card[1]) def __eq__(self, other): if other is None: return False return self.__dict__ == other.__dict__ def __lt__(self, other): if o...
# -*- coding:utf-8 -*- import sys class Card(object): def __init__(self, card): self._suit = card[0] self._value = int(card[1]) def __eq__(self, other): if other is None: return False return self.__dict__ == other.__dict__ def __lt__(self, other): if o...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22]]
5
604
2
import copy def num_from_card(card): return int(card[2:]) def partition(A, p, r): x = num_from_card(A[r]) i = p-1 for j in range(p, r): if num_from_card(A[j]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 def quick_sort(A, p, r): ...
import copy def num_from_card(card): return int(card[2:]) def partition(A, p, r): x = num_from_card(A[r]) i = p-1 for j in range(p, r): if num_from_card(A[j]) <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 def quick_sort(A, p, r): ...
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
413
2
def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L, R = A[left: left + n1], A[mid: mid + n2] L.append([0,2000000000]) R.append([0,2000000000]) i, j = 0, 0 for k in range(left, right): #print("k", k, "l", left, "m", mid, "r", right, "L", L, "R", R) if L[i][1]...
def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L, R = A[left: left + n1], A[mid: mid + n2] L.append([0,2000000000]) R.append([0,2000000000]) i, j = 0, 0 for k in range(left, right): #print("k", k, "l", left, "m", mid, "r", right, "L", L, "R", R) if L[i][1]...
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
437
2
#coding:utf-8 from copy import deepcopy n = int(input()) A = [] for i in range(n): ch, num = input().split() A.append([ch, int(num)]) B = deepcopy(A) def Merge(A, left, mid, right): L = A[left:mid] R = A[mid:right] L.append(["S",20000000]) R.append(["S",20000000]) i,j = 0,0 for k in ...
#coding:utf-8 from copy import deepcopy n = int(input()) A = [] for i in range(n): ch, num = input().split() A.append([ch, int(num)]) B = deepcopy(A) def Merge(A, left, mid, right): L = A[left:mid] R = A[mid:right] L.append(["S",2000000000]) R.append(["S",2000000000]) i,j = 0,0 for k...
[["-", 0, 1, 0, 652, 3, 4, 0, 634, 0, 612], ["+", 0, 1, 0, 652, 3, 4, 0, 634, 0, 612], ["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
400
6
#!/usr/bin/env python from sys import stdin def patition(a, p, r): x = a[r][0] i = p - 1 for j in range(p, r): if a[j][0] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i+1], a[r] = a[r], a[i+1] return i + 1 def quick_sort(a, p, r): if p < r: q = patition(a, ...
#!/usr/bin/env python from sys import stdin def patition(a, p, r): x = a[r][0] i = p - 1 for j in range(p, r): if a[j][0] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i+1], a[r] = a[r], a[i+1] return i + 1 def quick_sort(a, p, r): if p < r: q = patition(a, ...
[["-", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22], ["+", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22]]
5
286
2
#include <algorithm> #include <cstdio> #include <iostream> #include <sstream> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define max 100001 struct node { int p, l, r; }; struct node t[max]; int d[max]; void getdepth(int i, int j) { d[i] = j; if (t[i].r != -1) getdepth(t[i].r,...
#include <algorithm> #include <cstdio> #include <iostream> #include <sstream> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define max 100001 struct node { int p, l, r; }; struct node t[max]; int d[max]; void getdepth(int i, int j) { d[i] = j; if (t[i].r != -1) getdepth(t[i].r,...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
477
2
#include <stdio.h> #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void print(int u) { int i, c; printf("node %d:", u); printf("parent = %d, ", T[u].p); printf("depth = %d, ", D[u]); if (T[u].p == NIL) printf("root, "); else if (T[u].l == ...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX], H[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d, ", T[u].p); printf("depth = %d, ", D[u]); if (T[u].p == NIL) printf("root, "); else if (T[u].l =...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
483
4
#include <iostream> #include <vector> struct Node { Node() : // constracter parent(-1), id(-1), depth(0) {} int id; int depth; int parent; std::vector<Node *> children; // stack,pointa }; int FindRoot(Node *nodes, int n) { for (int i = 0; i < n; i++) { if (nodes[i].parent == -1) { ...
#include <iostream> #include <vector> struct Node { Node() : // constracter parent(-1), id(-1), depth(0) {} int id; int depth; int parent; std::vector<Node *> children; // stack,pointa }; int FindRoot(Node *nodes, int n) { for (int i = 0; i < n; i++) { if (nodes[i].parent == -1) { ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
505
2
#include <iostream> using namespace std; #define MAX 1000000 typedef struct { int p, l, r; } Node; Node t[1000000]; int count, h, d[1000000]; void b(int); int main() { int n, id, k, c, l, r; cin >> n; for (int i = 0; i < n; i++) { t[i].p = -1; t[i].l = -1; t[i].r = -1; } for (int i = 0; i < n; ...
#include <iostream> using namespace std; #define MAX 1000000 typedef struct { int p, l, r; } Node; Node t[1000000]; int count, h, d[1000000]; void b(int); int main() { int n, id, k, c, l, r; cin >> n; for (int i = 0; i < n; i++) { t[i].p = -1; t[i].l = -1; t[i].r = -1; } for (int i = 0; i < n; ...
[["-", 75, 76, 0, 1, 0, 16, 12, 103, 0, 104], ["-", 75, 76, 0, 1, 0, 16, 12, 103, 0, 125], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6]]
1
538
12
#include <iostream> using namespace std; #define MAX 100005 #define HN -1 struct Node { int p, l, r; }; Node Ta[MAX]; int num, Da[MAX]; void express(int d) { int i, o; cout << "node " << d << ": "; cout << "parent = " << Ta[d].p << ", "; cout << "DEPTH = " << Da[d] << ", "; if (Ta[d].p == HN) { cout...
#include <iostream> using namespace std; #define MAX 100005 #define HN -1 struct Node { int p, l, r; }; Node Ta[MAX]; int num, Da[MAX]; void express(int d) { int i, o; cout << "node " << d << ": "; cout << "parent = " << Ta[d].p << ", "; cout << "depth = " << Da[d] << ", "; if (Ta[d].p == HN) { cout...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120]]
1
479
4
#include <stdio.h> using namespace std; #define NEL -1 struct tree { int p, l, r; }; tree a[100005]; int d[100005]; int re(int u, int p) { d[u] = p; if (a[u].r >= 0) re(a[u].r, p); if (a[u].l >= 0) re(a[u].l, p + 1); } void print(int n) { for (int i = 0; i < n; i++) { printf("node %d:", i); ...
#include <stdio.h> using namespace std; #define NEL -1 struct tree { int p, l, r; }; tree a[100005]; int d[100005]; int re(int u, int p) { d[u] = p; if (a[u].r >= 0) re(a[u].r, p); if (a[u].l >= 0) re(a[u].l, p + 1); } void print(int n) { for (int i = 0; i < n; i++) { printf("node %d:", i); ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
498
2
#include <iostream> using namespace std; struct Node { int parent, left, right; }; struct Node T[100001]; #define NIL -1 int D[100001], n, dim, child, v, l, s; void getDepth(int u, int p) { D[u] = p; if (T[u].right != NIL) getDepth(T[u].right, p); if (T[u].left != NIL) getDepth(T[u].left, p + 1); } void...
#include <iostream> using namespace std; struct Node { int parent, left, right; }; struct Node T[100001]; #define NIL -1 int D[100001], n, dim, child, v, l, s; void getDepth(int u, int p) { D[u] = p; if (T[u].right != NIL) getDepth(T[u].right, p); if (T[u].left != NIL) getDepth(T[u].left, p + 1); } void...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
500
2
#include <iostream> #include <string> using namespace std; #define MAX 100000 #define NIL -1 struct Node { int parent; int left; int right; }; Node T[MAX]; int n, D[MAX]; void setDepth(int u, int p) { D[u] = p; if (T[u].right != NIL) { setDepth(T[u].right, p); } if (T[u].left != NIL) { setDepth...
#include <iostream> #include <string> using namespace std; #define MAX 100000 #define NIL -1 struct Node { int parent; int left; int right; }; Node T[MAX]; int n, D[MAX]; void setDepth(int u, int p) { D[u] = p; if (T[u].right != NIL) { setDepth(T[u].right, p); } if (T[u].left != NIL) { setDepth...
[["+", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
504
3
#include <cstdio> #include <cstdlib> typedef struct tree_ { int parent; int depth; int noc; int *child; } tree; void setDepth(tree *node, int id, int depth) { node[id].depth = depth; for (int i = 0; i < node[id].noc; i++) setDepth(node, node[id].child[i], depth + 1); return; } int main() { int i,...
#include <cstdio> #include <cstdlib> typedef struct tree_ { int parent; int depth; int noc; int *child; } tree; void setDepth(tree *node, int id, int depth) { node[id].depth = depth; for (int i = 0; i < node[id].noc; i++) setDepth(node, node[id].child[i], depth + 1); return; } int main() { int i,...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
457
2
#include <iostream> #include <stdio.h> using namespace std; #define MAX 1000005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d", T[u].p); printf(", "); printf("depth = %d", D[u]); printf(", "); if (T[...
#include <iostream> #include <stdio.h> using namespace std; #define MAX 1000005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d", T[u].p); printf(", "); printf("depth = %d", D[u]); printf(", "); if (T[...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
526
2
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int N; int parent[100000], Left[100000], Right[100000]; int d[100000]; void rec(int u, int p) { d[u] = p; if (Right[u] != -1) re...
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int N; int parent[100000], Left[100000], Right[100000]; int d[100000]; void rec(int u, int p) { d[u] = p; if (Right[u] != -1) re...
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
1
500
2
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstdlib> #include <iostream> #include <math.h> #include <string> using namespace std; #define MAX 100000 #define NIL -1 struct node { int p, l, r; }; node A[MAX]; int D[MAX]; void setDepth(int v, int d) { if (v == NIL) return; D[v] ...
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstdlib> #include <iostream> #include <math.h> #include <string> using namespace std; #define MAX 100000 #define NIL -1 struct node { int p, l, r; }; node A[MAX]; int D[MAX]; void setDepth(int v, int d) { if (v == NIL) return; D[v] ...
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 16, 12, 69, 341, 342, 0, 22]]
1
437
4
#include <iostream> #include <string> #include <vector> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int depth(int i) { int count = 0; int c = i; while (T[c].parent != NIL) { c = T[c].parent; count++; } return count; } string node...
#include <iostream> #include <string> #include <vector> using namespace std; #define MAX 100000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int depth(int i) { int count = 0; int c = i; while (T[c].parent != NIL) { c = T[c].parent; count++; } return count; } string nod...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 11, 31, 118, 28, 69, 341, 342, 0, 22], ["+", 0, 11, 31, 118, 28, 69, 341, 342, 0, 22]]
1
483
4
#include <bits/stdc++.h> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n, D[MAX]; void print(int u) { int c; cout << "node" << u << ": "; cout << "parent = " << T[u].p << ", "; cout << "depth = " << D[u] << ", "; if (T[u].p == NIL) cout << "roo...
#include <bits/stdc++.h> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n, D[MAX]; void print(int u) { int c; cout << "node " << u << ": "; cout << "parent = " << T[u].p << ", "; cout << "depth = " << D[u] << ", "; if (T[u].p == NIL) cout << "ro...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
461
2
#include <bits/stdc++.h> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int getDepth(int u) { int d = 0; while (T[u].parent != NIL) { u = T[u].parent; d++; } return d; }; vector<int> D(MAX, 0); void setDepth(int u, int p) { D[u] = p;...
#include <bits/stdc++.h> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int getDepth(int u) { int d = 0; while (T[u].parent != NIL) { u = T[u].parent; d++; } return d; }; vector<int> D(MAX, 0); void setDepth(int u, int p) { D[u] = p;...
[["-", 15, 339, 51, 16, 31, 118, 28, 69, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 118, 17, 131], ["-", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120]]
1
572
4
#include <iostream> #include <string> using namespace std; const int N = 100000; const int NIL = -1; struct Node { int parent, left, right; }; void set_depth(int id, int d, Node T[], int depth[]) { depth[id] = d; if (T[id].left != NIL) set_depth(T[id].left, d + 1, T, depth); if (T[id].right != NIL) s...
#include <iostream> #include <string> using namespace std; const int N = 100000; const int NIL = -1; struct Node { int parent, left, right; }; void set_depth(int id, int d, Node T[], int depth[]) { depth[id] = d; if (T[id].left != NIL) set_depth(T[id].left, d + 1, T, depth); if (T[id].right != NIL) s...
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
545
3
#include <iostream> #include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n, D[MAX]; void rec(int u, int p) { D[u] = p; if (T[u].right != NIL) rec(T[u].right, p); if (T[u].left != NIL) rec(T[u].left, p + 1); } void printChildren(int id) { p...
#include <iostream> #include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n, D[MAX]; void rec(int u, int p) { D[u] = p; if (T[u].right != NIL) rec(T[u].right, p); if (T[u].left != NIL) rec(T[u].left, p + 1); } void printChildren(int id) { p...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
479
2
#include <iostream> using namespace std; #define MAX 100001 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int D[MAX]; void rec(int u, int p) { D[u] = p; if (T[u].r != NIL) rec(T[u].r, p); if (T[u].l != NIL) rec(T[u].l, p + 1); } void print(int u) { cout << "node " << u << ": parent...
#include <iostream> using namespace std; #define MAX 100001 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int D[MAX]; void rec(int u, int p) { D[u] = p; if (T[u].r != NIL) rec(T[u].r, p); if (T[u].l != NIL) rec(T[u].l, p + 1); } void print(int u) { cout << "node " << u << ": parent...
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
461
4
#include <iostream> using namespace std; class Node { public: int depth; int parent; int degree; int *children; }; void Depth(Node *node, int cur, int dp) { node[cur].depth = dp; for (int i = 0; i < node[cur].degree; ++i) { Depth(node, node[cur].children[i], dp + 1); } } int main() { int n; ...
#include <iostream> using namespace std; class Node { public: int depth; int parent; int degree; int *children; }; void Depth(Node *node, int cur, int dp) { node[cur].depth = dp; for (int i = 0; i < node[cur].degree; ++i) { Depth(node, node[cur].children[i], dp + 1); } } int main() { int n; ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
1
412
2
#include <iostream> #include <vector> using namespace std; struct Node { Node(int k) : depth(0), parentId(-1) { vChildId.resize(k, -1); } int depth; int parentId; vector<int> vChildId; }; void SetNodeDepthRecursive(Node *n, vector<Node *> &vNode) { int s = n->vChildId.size(); if (0 == s) return; for ...
#include <iostream> #include <vector> using namespace std; struct Node { Node(int k) : depth(0), parentId(-1) { vChildId.resize(k, -1); } int depth; int parentId; vector<int> vChildId; }; void SetNodeDepthRecursive(Node *n, vector<Node *> &vNode) { int s = n->vChildId.size(); if (0 == s) return; for ...
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6]]
1
567
2
#include <iostream> using namespace std; typedef struct { int id; int parent; int depth; int child_num; int *children; } node; node *tree; void update_depth(int node_id, int depth) { node nod = tree[node_id]; tree[node_id].depth = depth; int child_num = nod.child_num; for (int i = 0; i < child_num...
#include <iostream> using namespace std; typedef struct { int id; int parent; int depth; int child_num; int *children; } node; node *tree; void update_depth(int node_id, int depth) { node nod = tree[node_id]; tree[node_id].depth = depth; int child_num = nod.child_num; for (int i = 0; i < child_num...
[["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
455
4