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
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; #define MAX_N 25 #define NIL -1 struct Node { int parent; int left; int right; }; Node *N; int *D; int *H; int *B; int max(int x, int y) { if (x > y) return x; return y; } void print(int i) { int deg = (N[i].left != 0) ...
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; #define MAX_N 25 #define NIL -1 struct Node { int parent; int left; int right; }; Node *N; int *D; int *H; int *B; int max(int x, int y) { if (x > y) return x; return y; } void print(int i) { int deg = (N[i].left != NIL...
[["-", 49, 50, 51, 16, 31, 23, 0, 16, 12, 13], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 12, 22], ["-", 49, 50, 51, 16, 12, 23, 0, 16, 12, 13], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22]]
1
648
4
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <iostream> #include <stack> using namespace std; const int num = 25, NIL = -1; struct Node { int l, r, p, si; }; Node T[num]; int Dp[num], Dg[num], H[num]; inline void getDepth(int u, int p) { Dp[u] = p; if (...
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <iostream> #include <stack> using namespace std; const int num = 25, NIL = -1; struct Node { int l, r, p, si; }; Node T[num]; int Dp[num], Dg[num], H[num]; inline void getDepth(int u, int p) { Dp[u] = p; if (...
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72]]
1
646
4
#include <bits/stdc++.h> #define MAX 10000 #define r(i, n) for (int i = 0; i < n; i++) using namespace std; struct Node { int p, l, r; }; Node T[MAX]; int D[MAX], H[MAX]; void setDepth(int u, int d) { if (u == -1) return; D[u] == d; setDepth(T[u].l, d + 1); setDepth(T[u].r, d + 1); } int setHeight(int u) ...
#include <bits/stdc++.h> #define MAX 10000 #define r(i, n) for (int i = 0; i < n; i++) using namespace std; struct Node { int p, l, r; }; Node T[MAX]; int D[MAX], H[MAX]; void setDepth(int u, int d) { if (u == -1) return; D[u] = d; setDepth(T[u].l, d + 1); setDepth(T[u].r, d + 1); } int setHeight(int u) {...
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 60], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32]]
1
593
2
#include <cstdio> #include <iostream> using namespace std; #define MAX 30 #define NIL -1 struct Node { int parent; int left; int right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } i...
#include <cstdio> #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent; int left; int right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); }...
[["-", 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
659
4
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; enum { NA = -1, // option is better? C++17 }; struct node { int id; int parent; int right; int left; int sibling; int degree; int depth; int height; string state; node() : parent(NA), left(NA...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; enum { NA = -1, // option is better? C++17 }; struct node { int id; int parent; int right; int left; int sibling; int degree; int depth; int height; string state; node() : parent(NA), left(NA...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60]]
1
869
2
#include "stdio.h" #include <string> using namespace std; #define MAX 25 class Node { public: enum TYPE { ROOT, INTERNAL_NODE, LEAF }; Node(int ID, Node *PARENT) { id = ID; parent = PARENT; } ~Node(){}; Node *parent = 0; Node *sibling = 0; Node *left = 0; Node *right = 0; int id; int degree...
#include "stdio.h" #include <string> using namespace std; #define MAX 25 class Node { public: enum TYPE { ROOT, INTERNAL_NODE, LEAF }; Node(int ID, Node *PARENT) { id = ID; parent = PARENT; } ~Node(){}; Node *parent = 0; Node *sibling = 0; Node *left = 0; Node *right = 0; int id; int degree...
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
1,037
4
#include <iostream> #include <vector> using namespace std; class Node { public: int p = -1, s = -1, l, r, d, h; }; int getDepth(vector<Node> &nodes, Node &cur, int d) { cur.d = d; int hl = 0, hr = 0; if (cur.l != -1) hl = getDepth(nodes, nodes.at(cur.l), ++d) + 1; if (cur.r != -1) hr = getDepth(node...
#include <iostream> #include <vector> using namespace std; class Node { public: int p = -1, s = -1, l, r, d, h; }; int getDepth(vector<Node> &nodes, Node &cur, int d) { cur.d = d; int hl = 0, hr = 0; if (cur.l != -1) hl = getDepth(nodes, nodes.at(cur.l), d + 1) + 1; if (cur.r != -1) hr = getDepth(no...
[["-", 12, 16, 31, 2, 3, 4, 0, 27, 17, 29], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 17, 72], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
1
478
5
#include <stdio.h> #define N 25 typedef struct { int p, l, r, s; } Node; int depth(Node *, int, int); int height(Node *, int, int, int); int depth(Node *node, int num, int con) { if (node[num].p == -1) return con; con++; con = depth(node, node[num].p, con); return con; } int height(Node *node, int num...
#include <stdio.h> #define N 25 typedef struct { int p, l, r, s; } Node; int depth(Node *, int, int); int height(Node *, int, int, int); int depth(Node *node, int num, int con) { if (node[num].p == -1) return con; con++; con = depth(node, node[num].p, con); return con; } int height(Node *node, int num...
[["-", 0, 1, 0, 2, 3, 4, 0, 118, 119, 120], ["+", 0, 1, 0, 2, 3, 4, 0, 118, 119, 120]]
1
660
2
#include <algorithm> #include <iostream> using namespace std; int n, D[25], H[25]; struct node { int parent, left, right; } nodes[25]; int setheight(int r) { int h1, h2; h1 = h2 = 0; if (nodes[r].left != -1) h1 = setheight(nodes[r].left) + 1; if (nodes[r].right != -1) h2 = setheight(nodes[r].right)...
#include <algorithm> #include <iostream> using namespace std; int n, D[25], H[25]; struct node { int parent, left, right; } nodes[25]; int setheight(int r) { int h1, h2; h1 = h2 = 0; if (nodes[r].left != -1) h1 = setheight(nodes[r].left) + 1; if (nodes[r].right != -1) h2 = setheight(nodes[r].right)...
[["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22]]
1
634
2
#include <iostream> using namespace std; #define NIL -1 #define MAX 10000 struct Node { int parent, left, right; }; //???????????? Node T[MAX]; int n, D[MAX], H[MAX]; int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u].right != NIL) h1 = setHeight(T[u].right) + 1; if (T[u].left != NIL) h2 = setHeight(T...
#include <iostream> using namespace std; #define NIL -1 #define MAX 10000 struct Node { int parent, left, right; }; //???????????? Node T[MAX]; int n, D[MAX], H[MAX]; int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u].right != NIL) h1 = setHeight(T[u].right) + 1; if (T[u].left != NIL) h2 = setHeight(T...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
652
2
#include <stdio.h> #define N 25 #define NILL -1 struct Tree { int parent, right, left; }; struct Tree T[N]; int D[N]; int H[N]; int n; int root; void setdepth(int u, int p) { D[u] = p; if (T[u].left != NILL) setdepth(T[u].left, p + 1); if (T[u].right != NILL) setdepth(T[u].right, p + 1); } int Heig...
#include <stdio.h> #define N 25 #define NILL -1 struct Tree { int parent, right, left; }; struct Tree T[N]; int D[N]; int H[N]; int n; int root; void setdepth(int u, int p) { D[u] = p; if (T[u].left != NILL) setdepth(T[u].left, p + 1); if (T[u].right != NILL) setdepth(T[u].right, p + 1); } int Heig...
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 106]]
1
615
2
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n, H[MAX], D[MAX]; int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u].left != NIL) h1 = setHeight(T[u].left) + 1; if (T[u].right != NIL) h2 = setHeight(T[u].right) + 1; return H[u] = (h1 >...
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n, H[MAX], D[MAX]; int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u].left != NIL) h1 = setHeight(T[u].left) + 1; if (T[u].right != NIL) h2 = setHeight(T[u].right) + 1; return H[u] = (h1 >...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
630
2
#include <cstdio> #define MAX 26 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u]...
#include <cstdio> #define MAX 26 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if (T[u]...
[["+", 8, 9, 0, 37, 0, 11, 31, 69, 28, 22], ["+", 0, 37, 0, 11, 31, 69, 341, 342, 0, 70], ["+", 0, 37, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 37, 0, 11, 31, 69, 341, 342, 0, 73], ["+", 0, 14, 8, 9, 0, 37, 0, 11, 17, 32]]
1
606
5
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if (T...
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int h1 = 0, h2 = 0; if (T...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
631
4
#include <stdio.h> #include <stdlib.h> #define MAX 25 #define NIL -1 using namespace std; struct Node { int parent, left, right; }; Node T[MAX]; int D[MAX], H[MAX]; int root = 0; int getDepth(int node) { int d = 0; while (T[node].parent != NIL) { node = T[node].parent; d++; } return d; } int get...
#include <stdio.h> #include <stdlib.h> #define MAX 25 #define NIL -1 using namespace std; struct Node { int parent, left, right; }; Node T[MAX]; int D[MAX], H[MAX]; int root = 0; int getDepth(int node) { int d = 0; while (T[node].parent != NIL) { node = T[node].parent; d++; } return d; } int get...
[["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
648
7
#include <cstdio> using namespace std; #define MAX_N 25 #define NIL -1 struct Node { int parent; int left; int right; int depth; int height; int degree; Node() : parent(NIL), left(NIL), right(NIL), depth(NIL), height(NIL), degree(NIL) {} ~Node() {} }; Node tree[MAX_N]; // (tree index, ...
#include <cstdio> using namespace std; #define MAX_N 25 #define NIL -1 struct Node { int parent; int left; int right; int depth; int height; int degree; Node() : parent(NIL), left(NIL), right(NIL), depth(NIL), height(NIL), degree(NIL) {} ~Node() {} }; Node tree[MAX_N]; // (tree index, ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
715
2
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, x, n) for (int i = x; i < n; i++) #define pb push_back #define int long long #define MAX 10000 #define NIL -1 using namespace std; const int INF = 1000000007; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; struct node { int...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, x, n) for (int i = x; i < n; i++) #define pb push_back #define int long long #define MAX 10000 #define NIL -1 using namespace std; const int INF = 1000000007; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; struct node { int...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
672
2
//////////////////////////////////////// // ALDS1_7_B: Binary Trees // //??????????????????????????¨ //////////////////////////////////////// #include <algorithm> // next_permutation #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <list> #include <numeric> //accumulate #include <qu...
//////////////////////////////////////// // ALDS1_7_B: Binary Trees // //??????????????????????????¨ //////////////////////////////////////// #include <algorithm> // next_permutation #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <list> #include <numeric> //accumulate #include <qu...
[["-", 31, 16, 31, 16, 12, 23, 0, 41, 64, 13], ["+", 31, 16, 31, 16, 12, 23, 0, 41, 64, 13]]
1
629
2
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int ...
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int u) { int ...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
660
2
#include <cstdio> #define maxn 10000 #define NIL -1 #include <iostream> using namespace std; struct Node { int parent, left, right; } T[maxn]; int n, D[maxn], H[maxn]; void setDepth(int u, int d) { if (u == NIL) return; D[u] = d; setDepth(T[u].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight...
#include <cstdio> #define maxn 10000 #define NIL -1 #include <iostream> using namespace std; struct Node { int parent, left, right; } T[maxn]; int n, D[maxn], H[maxn]; void setDepth(int u, int d) { if (u == NIL) return; D[u] = d; setDepth(T[u].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
649
2
#include <stdio.h> #include <vector> using namespace std; struct node { int l; int r; int parent; int s; int depth; int d; int height; }; int max(int a, int b) { if (a > b) return a; return b; } void build(int now, node tree[]) { int l = 0, r = 0, d = 0; if (tree[now].l != -1) { tree[tree[...
#include <stdio.h> #include <vector> using namespace std; struct node { int l; int r; int parent; int s; int depth; int d; int height; }; int max(int a, int b) { if (a > b) return a; return b; } void build(int now, node tree[]) { int l = -1, r = -1, d = 0; if (tree[now].l != -1) { tree[tre...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
604
6
#include <iostream> using namespace std; // const int MAX = 25; const int NIL = -1; struct Node { int parent = NIL; int left = NIL; int right = NIL; }; Node T[MAX]; int D[MAX], H[MAX]; // void setDepth(int u, int d) { D[u] = d; if (T[u].left != NIL) setDepth(T[u].left, d + 1); if (T[u].right != NIL...
#include <iostream> using namespace std; // const int MAX = 25; const int NIL = -1; struct Node { int parent = NIL; int left = NIL; int right = NIL; }; Node T[MAX]; int D[MAX], H[MAX]; // void setDepth(int u, int d) { D[u] = d; if (T[u].left != NIL) setDepth(T[u].left, d + 1); if (T[u].right != NIL...
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98]]
1
657
2
#include <iostream> #include <stdio.h> using namespace std; // node最大量 #define MAX 100005 #define NIL -1 struct Node { int parent; int left; int right; }; // 配列で保持する Node gNode[MAX]; int gDepth[MAX], gHeight[MAX]; // 兄弟を返す int getSibiling(int u) { // rootの場合 if (gNode[u].parent == NIL) return NIL; //...
#include <iostream> #include <stdio.h> using namespace std; // node最大量 #define MAX 100005 #define NIL -1 struct Node { int parent; int left; int right; }; // 配列で保持する Node gNode[MAX]; int gDepth[MAX], gHeight[MAX]; // 兄弟を返す int getSibling(int u) { // rootの場合 if (gNode[u].parent == NIL) return NIL; // ...
[["-", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22]]
1
712
6
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; static const int MAX = 26; static const int NIL = -1; typedef struct Node { int parent, left, right; } 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].lef...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; static const int MAX = 26; static const int NIL = -1; typedef struct Node { int parent, left, right; } 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].lef...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
649
2
#include <algorithm> #include <iostream> #include <string> #include <vector> constexpr int nil = -1; struct Node { int id; int parent{nil}; int left{nil}; int right{nil}; int degree() const { return (left != nil ? 1 : 0) + (right != nil ? 1 : 0); } std::string type() const { if (parent == nil) ...
#include <algorithm> #include <iostream> #include <string> #include <vector> constexpr int nil = -1; struct Node { int id; int parent{nil}; int left{nil}; int right{nil}; int degree() const { return (left != nil ? 1 : 0) + (right != nil ? 1 : 0); } std::string type() const { if (parent == nil) ...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
810
2
#include <stdio.h> const static int MAX = 10000; const static int NIL = -1; typedef struct { int parent, left, right; } 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int...
#include <stdio.h> const static int MAX = 10000; const static int NIL = -1; typedef struct { int parent, left, right; } 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].left, d + 1); setDepth(T[u].right, d + 1); } int setHeight(int...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
572
2
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; static const string ROOT = "root"; static const string INTERNAL_NODE = "internal node"; static const string LEAF = "leaf"; struct Node { int id; int parent; int depth; int height; int left; ...
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; static const string ROOT = "root"; static const string INTERNAL_NODE = "internal node"; static const string LEAF = "leaf"; struct Node { int id; int parent; int depth; int height; int left; ...
[["-", 31, 118, 28, 69, 341, 342, 0, 118, 119, 120], ["+", 31, 118, 28, 69, 341, 342, 0, 118, 119, 120], ["-", 3, 4, 0, 69, 341, 342, 0, 118, 119, 120], ["+", 3, 4, 0, 69, 341, 342, 0, 118, 119, 120]]
1
840
4
#include <algorithm> #include <iostream> #define MAX 10000 #define NIL -1 using namespace std; struct Node { int partent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int...
#include <algorithm> #include <iostream> #define MAX 10000 #define NIL -1 using namespace std; struct Node { int partent, left, right; }; 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].left, d + 1); setDepth(T[u].right, d + 1); } int...
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
662
10
#include <cstdio> #define NIL -1 struct Node { int parent, left, right; }; Node *T; int *D, *H; // depth, height void setDepth(int u, int depth) { D[u] = depth; if (T[u].left != NIL) { setDepth(T[u].left, depth + 1); } if (T[u].right != NIL) { setDepth(T[u].right, depth + 1); } } int setHeight(i...
#include <cstdio> #define NIL -1 struct Node { int parent, left, right; }; Node *T; int *D, *H; // depth, height void setDepth(int u, int depth) { D[u] = depth; if (T[u].left != NIL) { setDepth(T[u].left, depth + 1); } if (T[u].right != NIL) { setDepth(T[u].right, depth + 1); } } int setHeight(i...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
717
2
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent; int left; int right; }; Node T[MAX]; int D[MAX], H[MAX]; void setDepth(int u, int d) { if (u == NIL) { return; } D[u] = d; setDepth(T[u].left, d + 1); setDepth(T[u].right, d + 1); } int setHeigh...
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int parent; int left; int right; }; Node T[MAX]; int D[MAX], H[MAX]; void setDepth(int u, int d) { if (u == NIL) { return; } D[u] = d; setDepth(T[u].left, d + 1); setDepth(T[u].right, d + 1); } int setHeigh...
[["-", 0, 7, 8, 9, 0, 1, 0, 34, 0, 21], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 152]]
1
692
2
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <limits> #include <map> #include <set> #include <stdio.h> #include <vector> using namespace std; map<int, int> mpa, mpb; #define MAX 10005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX...
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <limits> #include <map> #include <set> #include <stdio.h> #include <vector> using namespace std; map<int, int> mpa, mpb; #define MAX 10005 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
684
4
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <st...
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <st...
[["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13]]
1
496
2
/* AOJ Algorithms and Data Structures I - Tree - Binary Trees rooted tree と大体同じ。 まずは、木クラスを作っておく。 入力されたnを一周回れば、parentは全部埋まる。 そっからroot見つけて、それ使って再帰で子を辿って行ってdepthを埋めていく。 heightは再帰関数に返り値つけて戻して使う。 nodeは初期値に、?1とか入れて埋めておく。 new: inputのとこで、順番に入れてって、後でソートするのではなく、 最初にIDを添え字にして、目当てのところに入れる。 ( 子の数が2以下なので、 子が一つの時もありうる。 left r...
/* AOJ Algorithms and Data Structures I - Tree - Binary Trees rooted tree と大体同じ。 まずは、木クラスを作っておく。 入力されたnを一周回れば、parentは全部埋まる。 そっからroot見つけて、それ使って再帰で子を辿って行ってdepthを埋めていく。 heightは再帰関数に返り値つけて戻して使う。 nodeは初期値に、?1とか入れて埋めておく。 new: inputのとこで、順番に入れてって、後でソートするのではなく、 最初にIDを添え字にして、目当てのところに入れる。 ( 子の数が2以下なので、 子が一つの時もありうる。 left r...
[["-", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 61, 0, 5, 0, 6]]
1
691
2
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) struct b_tree { int left; int right; int sibling; int parent; }; int getDepth(b_tree *array, int index) { if (index == -1) return 0; if (array[index].left == -1 && array[index].right == -1) return 0; int r...
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) struct b_tree { int left; int right; int sibling; int parent; }; int getDepth(b_tree *array, int index) { if (index == -1) return 0; if (array[index].left == -1 && array[index].right == -1) return 0; int r...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
504
6
#include <stdio.h> #define MAX 10000 #define FALSE -1 typedef struct { int parent; int left; int right; } Tree; Tree A[MAX]; int n; void pPato(int k) { if (k == FALSE) return; printf(" %d", k); pPato(A[k].left); pPato(A[k].right); } void mPato(int k) { if (k == FALSE) return; mPato(A[k].le...
#include <stdio.h> #define MAX 10000 #define FALSE -1 typedef struct { int parent; int left; int right; } Tree; Tree A[MAX]; int n; void pPato(int k) { if (k == FALSE) return; printf(" %d", k); pPato(A[k].left); pPato(A[k].right); } void mPato(int k) { if (k == FALSE) return; mPato(A[k].le...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
386
4
#include <stdio.h> #define MAX 100000 struct node { int p, q, r; }; struct node T[MAX]; int n; void preorder(int u) { if (u == -1) return; printf(" %d", u); preorder(T[u].q); preorder(T[u].r); } void inorder(int u) { if (u == -1) return; inorder(T[u].q); printf(" %d", u); inorder(T[u].r); }...
#include <stdio.h> #define MAX 10000 struct node { int p, q, r; }; struct node T[MAX]; int n; void preorder(int u) { if (u == -1) return; printf(" %d", u); preorder(T[u].q); preorder(T[u].r); } void inorder(int u) { if (u == -1) return; inorder(T[u].q); printf(" %d", u); inorder(T[u].r); } ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 64, 1, 0, 11, 31, 118, 28, 69, 71, 22], ["+", 64, 1, 0, 11, 31, 118, 28, 69, 71, 22]]
0
381
4
// ConsoleApplication1.cpp : ??????????????? // ??¢????????±????????§????????¨????????? ????????????????????????????????? // #include "stdio.h" struct Node { int p, l, r; }; struct Node T[10000]; int n; void preParse(int u) { if (u == -1) return; printf(" %d", u); preParse(T[u].l); preParse(T[u].r); } ...
// ConsoleApplication1.cpp : ??????????????? // ??¢????????±????????§????????¨????????? ????????????????????????????????? // #include "stdio.h" struct Node { int p, l, r; }; struct Node T[10000]; int n; void preParse(int u) { if (u == -1) return; printf(" %d", u); preParse(T[u].l); preParse(T[u].r); } ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
0
385
8
#include <stdio.h> struct Node { int o, p, q; }; struct Node x[10000]; int n; void pre(int u) { if (u == -1) { return; } printf(" %d", u); pre(x[u].p); pre(x[u].q); } void in(int u) { if (u == -1) { return; } in(x[u].p); printf(" %d", u); in(x[u].q); } void post(int u) { if (u == -1)...
#include <stdio.h> struct Node { int o, p, q; }; struct Node x[10000]; int n; void pre(int u) { if (u == -1) { return; } printf(" %d", u); pre(x[u].p); pre(x[u].q); } void in(int u) { if (u == -1) { return; } in(x[u].p); printf(" %d", u); in(x[u].q); } void post(int u) { if (u == -1)...
[["-", 8, 9, 0, 1, 0, 11, 31, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 11, 31, 118, 119, 120]]
0
394
2
#include <stdio.h> #include <stdlib.h> struct node { int id; struct node *parentNode; struct node *leftChild; struct node *rightChild; struct node *sibling; }; void preorder(struct node *nd); void inorder(struct node *nd); void postorder(struct node *nd); struct node *createNode(int); struct node *searchNod...
#include <stdio.h> #include <stdlib.h> struct node { int id; struct node *parentNode; struct node *leftChild; struct node *rightChild; struct node *sibling; }; void preorder(struct node *nd); void inorder(struct node *nd); void postorder(struct node *nd); struct node *createNode(int); struct node *searchNo...
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22]]
0
646
2
#include <stdio.h> typedef struct _tree_t { int p, l, r; } tree_t; void print_preorder(int depth, tree_t tree[], int id, int n) { printf(" %d", id); if (tree[id].l != -1) print_preorder(depth + 1, tree, tree[id].l, n); if (tree[id].r != -1) print_preorder(depth + 1, tree, tree[id].r, n); } void print...
#include <stdio.h> typedef struct _tree_t { int p, l, r; } tree_t; void print_preorder(int depth, tree_t tree[], int id, int n) { printf(" %d", id); if (tree[id].l != -1) print_preorder(depth + 1, tree, tree[id].l, n); if (tree[id].r != -1) print_preorder(depth + 1, tree, tree[id].r, n); } void print...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
737
2
#include <stdio.h> struct Node { int p; int l; int r; }; struct Node T[100000]; void preorder(int id) { printf(" %d", id); if (T[id].l != -1) { preorder(T[id].l); } if (T[id].r != -1) { preorder(T[id].r); } } void inorder(int id) { if (T[id].l != -1) { inorder(T[id].l); } printf(" %...
#include <stdio.h> struct Node { int p; int l; int r; }; struct Node T[100000]; void preorder(int id) { printf(" %d", id); if (T[id].l != -1) { preorder(T[id].l); } if (T[id].r != -1) { preorder(T[id].r); } } void inorder(int id) { if (T[id].l != -1) { inorder(T[id].l); } printf(" %...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
442
2
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,...
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,...
[["-", 0, 57, 75, 665, 15, 666, 0, 652, 63, 22], ["-", 75, 665, 15, 666, 0, 652, 3, 4, 0, 24], ["-", 15, 666, 0, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 57, 75, 665, 15, 666, 0, 206, 51, 22], ["-", 75, 665, 15, 666, 0, 652, 3, 4, 0, 25]]
5
500
5
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...
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...
[["-", 0, 662, 12, 657, 12, 282, 0, 664, 17, 33], ["-", 0, 662, 12, 657, 12, 282, 0, 664, 28, 612], ["+", 0, 662, 12, 657, 12, 282, 0, 557, 0, 654], ["+", 0, 662, 12, 657, 12, 282, 0, 557, 0, 6], ["+", 0, 662, 12, 657, 12, 282, 0, 557, 0, 655]]
5
324
5
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...
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...
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["-", 36, 36, 0, 656, 0, 7, 12, 657, 12, 22], ["+", 36, 36, 0, 656, 0, 7, 12, 657, 12, 22], ["-", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22]]
5
323
6
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 {}...
N=int(input()) t=[0]*N r=set(range(N)) for _ in[0]*N: x,y,z=list(map(int,input().split())) t[x]=[y,z]+[0]*2+[(y!=-1)+(z!=-1)]+[0]*2 r-={y,z} def f(i,p,s,d): if i<0:return-1 l,r=t[i][:2] t[i][2:]=[p,s,t[i][4],d,max(f(l,i,r,d+1),f(r,i,l,d+1))+1] return t[i][-1] f(r.pop(),-1,-1,0) for i in range(N): print('node {}...
[["-", 12, 634, 0, 657, 31, 23, 0, 666, 0, 22], ["+", 12, 634, 0, 657, 31, 23, 0, 666, 0, 22], ["-", 12, 634, 0, 657, 12, 23, 0, 666, 0, 22], ["+", 12, 634, 0, 657, 12, 23, 0, 666, 0, 22]]
5
269
24
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 = {}, ...
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-=set(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 = {...
[["-", 8, 196, 0, 1, 0, 677, 12, 282, 0, 45], ["+", 8, 196, 0, 1, 0, 677, 12, 652, 63, 22], ["+", 0, 1, 0, 677, 12, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 677, 12, 282, 0, 46], ["+", 0, 1, 0, 677, 12, 652, 3, 4, 0, 25]]
5
254
42
class Tree: nodes = [] def __init__(self): self.root = None def insert(self, nodenum, leftnum, rightnum): if leftnum != -1: self.nodes[nodenum].left = self.nodes[leftnum] self.nodes[leftnum].type_ = "internal node" self.nodes[leftnum].parent = self.nodes[n...
class Tree: nodes = [] def __init__(self): self.root = None def insert(self, nodenum, leftnum, rightnum): if leftnum != -1: self.nodes[nodenum].left = self.nodes[leftnum] self.nodes[leftnum].type_ = "internal node" self.nodes[leftnum].parent = self.nodes[n...
[["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
654
4
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) type Node struct { id int parent int sibling int children []int // index of node or -1 depth int height int typ string } func main() { sc := bufio.NewScanner(os.Stdin) sc.Split(bufio.ScanWords) n, err := nextInt(sc) if err...
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) type Node struct { id int parent int sibling int children []int // index of node or -1 depth int height int typ string } func main() { sc := bufio.NewScanner(os.Stdin) sc.Split(bufio.ScanWords) n, err := nextInt(sc) if err...
[["-", 8, 196, 0, 1, 0, 2, 63, 438, 439, 22], ["-", 8, 196, 0, 1, 0, 2, 63, 438, 0, 131], ["-", 8, 196, 0, 1, 0, 2, 63, 438, 119, 120], ["-", 8, 196, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 36, 36, 0, 434, 0, 435, 8, 196, 0, 165]]
7
875
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { new Main().run(); } public void run() { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int n = Integ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { new Main().run(); } public void run() { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int n = Integ...
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
719
2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static class Node { int p = -1, l, r; } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputSt...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static class Node { int p = -1, l, r; } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputSt...
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
587
2
import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { new Main().run(); } private void run() throws NumberFormatException, IOException { Scanner scanner = new Scanner(System.in); int n = sc...
import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { new Main().run(); } private void run() throws NumberFormatException, IOException { Scanner scanner = new Scanner(System.in); int n = sc...
[["+", 0, 235, 8, 498, 0, 124, 49, 200, 0, 32], ["+", 8, 498, 0, 124, 49, 200, 51, 91, 17, 33], ["+", 8, 498, 0, 124, 49, 200, 51, 91, 439, 499]]
3
513
3
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int parent, left, right; } Node; Node Tree[MAX]; int Depth[MAX]; int degree[MAX]; int h; void preOrder(int); void inOrder(int); void postOrder(int); int main(void) { int i, n, root; int vertex; int child[2]; scanf("%d", &n); for (i ...
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int parent, left, right; } Node; Node Tree[MAX]; int Depth[MAX]; int degree[MAX]; int h; void preOrder(int); void inOrder(int); void postOrder(int); int main(void) { int i, n, root; int vertex; int child[2]; scanf("%d", &n); for (i ...
[["-", 15, 23, 0, 16, 31, 118, 28, 69, 71, 22], ["+", 15, 23, 0, 16, 31, 118, 28, 69, 71, 22], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
0
584
6
#include <stdio.h> #define Max 10000 #define NIL -1 typedef struct Node { int p, l, r; } Node; Node T[Max]; int n; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u].l); printf(" %d", ...
#include <stdio.h> #define Max 10000 #define NIL -1 typedef struct Node { int p, l, r; } Node; Node T[Max]; int n; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u].l); printf(" %d", ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
389
4
#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 preorder(int); void inorder(int); void postorder(int); int main() { int i, v, l, r, root = 0; scanf("%d", &n); for (i = 0; i < n; i++) ...
#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 preorder(int); void inorder(int); void postorder(int); int main() { int i, v, l, r, 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
431
6
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; //左の子 int right; //右の子 } Node; void preorder(Node **, int); void inorder(Node **, int); void postorder(Node **, int); main() { int n, i, id, root; Node **tree; scanf("%d", &n); tree = (Node **)malloc(sizeof(Node *) * n); ...
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int left; //????????? int right; //????????? } Node; void preorder(Node **, int); void inorder(Node **, int); void postorder(Node **, int); main() { int n, i, id, root; Node **tree; scanf("%d", &n); tree = (Node **)malloc(sizeof(Node...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
0
484
8
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int parent; int left; int right; }; struct Node T[MAX]; void Pre(int); void In(int); void Post(int); int main() { int n, k, root, node, child; int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].parent = NIL; T[i].left ...
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int parent; int left; int right; }; struct Node T[MAX]; void Pre(int); void In(int); void Post(int); int main() { int n, k, root, node, child; int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].parent = NIL; T[i].left ...
[["-", 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
480
9
#define dbg(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) #define dpri(x) dbg(#x ": %d\n", x) #define dprs(x) dbg(#x ": %s\n", x) #include <stdio.h> #include <string.h> typedef long long ll; const int MYINF = 1e9 + 7; typedef int bool; const bool true = 1; const bool false = 0; typedef struct node_st { int par; int ...
#define dbg(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) #define dpri(x) dbg(#x ": %d\n", x) #define dprs(x) dbg(#x ": %s\n", x) #include <stdio.h> #include <string.h> typedef long long ll; const int MYINF = 1e9 + 7; typedef int bool; const bool true = 1; const bool false = 0; typedef struct node_st { int par; int ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
418
2
#include <stdio.h> #define N 200000 #define NIL -1 typedef struct Node { int parent; int left; int right; } node; void preOrder(int); void inOrder(int); void postOrder(int); node tree[N]; int main() { int n, i, j, left, right, node, rooti; for (i = 0; i < N; i++) { tree[i].parent = NIL; tree[i].left =...
#include <stdio.h> #define N 200000 #define NIL -1 typedef struct Node { int parent; int left; int right; } node; void preOrder(int); void inOrder(int); void postOrder(int); node tree[N]; int main() { int n, i, j, left, right, node, rooti; for (i = 0; i < N; i++) { tree[i].parent = NIL; tree[i].left =...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
432
2
#include <stdio.h> #define N 25 #define EMPTY -1 typedef struct { int parent; int left; int right; } Node; Node node[N]; void preParse(int u) { if (u == EMPTY) return; printf(" %d", u); preParse(node[u].left); preParse(node[u].right); } void inParse(int u) { if (u == EMPTY) return; inParse...
#include <stdio.h> #define N 25 #define EMPTY -1 typedef struct { int parent; int left; int right; } Node; Node node[N]; void preParse(int u) { if (u == EMPTY) return; printf(" %d", u); preParse(node[u].left); preParse(node[u].right); } void inParse(int u) { if (u == EMPTY) return; inParse...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
407
2
/** * File: binary_tree.c * Author: ymiyamoto * * Created on Wed May 24 11:23:59 2017 */ #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #define UTIL_MAX(x, y) ((x) < (y) ? (y) : (x)) typedef struct binary_tree_t *binary_tree_t; typedef uint32_t binary_tree_id_t; #define BINARY_...
/** * File: binary_tree.c * Author: ymiyamoto * * Created on Wed May 24 11:23:59 2017 */ #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #define UTIL_MAX(x, y) ((x) < (y) ? (y) : (x)) typedef struct binary_tree_t *binary_tree_t; typedef uint32_t binary_tree_id_t; #define BINARY_...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
1,853
2
#include <stdio.h> typedef struct { int p; int l; int r; } Node; Node node[25]; void preorder(int p) { if (p != -1) { printf(" %d", p); preorder(node[p].l); preorder(node[p].r); } } void inorder(int p) { if (p != -1) { inorder(node[p].l); printf(" %d", p); inorder(node[p].r); }...
#include <stdio.h> typedef struct { int p; int l; int r; } Node; Node node[25]; void preorder(int p) { if (p != -1) { printf(" %d", p); preorder(node[p].l); preorder(node[p].r); } } void inorder(int p) { if (p != -1) { inorder(node[p].l); printf(" %d", p); inorder(node[p].r); }...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
394
2
#include <stdio.h> #define NIL -1 #define N 25 typedef struct node { int p, l, r; } Node; Node T[N]; void printPre(u) { if (u == NIL) return; printf(" %d", u); printPre(T[u].l); printPre(T[u].r); return; } void printIn(u) { if (u == NIL) return; printIn(T[u].l); printf(" %d", u); print...
#include <stdio.h> #define NIL -1 #define N 25 typedef struct node { int p, l, r; } Node; Node T[N]; void printPre(u) { if (u == NIL) return; printf(" %d", u); printPre(T[u].l); printPre(T[u].r); return; } void printIn(u) { if (u == NIL) return; printIn(T[u].l); printf(" %d", u); print...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
0
382
4
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <ut...
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <ut...
[["+", 75, 76, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60]]
1
474
2
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <ve...
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <ve...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
390
4
// C++の難しさ #include <iostream> #include <stdio.h> #define N_MAX 500000 using namespace std; // thik&solve easy //オブジェクトは変数でありその変数に記録されたデータそのもののことだ int n; // num of input class node { //将来を見据えて動的にしています public: int *key; node *parent; node *l_chld; node *r_chld; node(int n) { key = new int(n); parent...
// C++の難しさ #include <iostream> #include <stdio.h> #define N_MAX 500000 using namespace std; // thik&solve easy //オブジェクトは変数でありその変数に記録されたデータそのもののことだ int n; // num of input class node { //将来を見据えて動的にしています public: int *key; node *parent; node *l_chld; node *r_chld; node(int n) { key = new int(n); parent...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
489
4
#include <iostream> using namespace std; struct Node { int k; Node *r, *l, *p; }; Node *T; Node *NIL; void insert(int key) { Node *x = T; Node *y = NIL; Node *z; z = new Node; z->k = key; z->l = z->r = NIL; while (x != NIL) { y = x; if (z->k > x->k) { x = x->r; } else if (z->k <...
#include <iostream> using namespace std; struct Node { int k; Node *r, *l, *p; }; Node *T; Node *NIL; void insert(int key) { Node *x = T; Node *y = NIL; Node *z; z = new Node; z->k = key; z->l = z->r = NIL; while (x != NIL) { y = x; if (z->k > x->k) { x = x->r; } else if (z->k <...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
351
4
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; void print_preorder(const vector<pair<int, int>> &nodes, const vector<int> &node_val, const int r) { if (r < 0) return; cout << ' ' << node_val[r]; print_preorder(nodes, node_val, nodes[r].f...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; void print_preorder(const vector<pair<int, int>> &nodes, const vector<int> &node_val, const int r) { if (r < 0) return; cout << ' ' << node_val[r]; print_preorder(nodes, node_val, nodes[r].f...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
544
2
#include <cstdio> #include <cstdlib> typedef struct node { long v; node *parent; node *left; node *right; } Node; typedef struct { Node *root; } Tree; Tree T = {NULL}; void insertTree(Node *node) { Node *y = NULL; Node *x = T.root; while (x != NULL) { y = x; if (node->v < x->v) { x = x...
#include <cstdio> #include <cstdlib> typedef struct node { long v; node *parent; node *left; node *right; } Node; typedef struct { Node *root; } Tree; Tree T = {NULL}; void insertTree(Node *node) { Node *y = NULL; Node *x = T.root; while (x != NULL) { y = x; if (node->v < x->v) { x = x...
[["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]]
1
385
4
#include <iostream> #include <string> using namespace std; int a; struct NodeDiv2 { int key; NodeDiv2 *parent, *left, *right; }; NodeDiv2 *root, *NIL; void preTreeWalkDiv2(NodeDiv2 *u) { if (u == NIL) { return; } cout << ' ' << u->key; preTreeWalkDiv2(u->left); preTreeWalkDiv2(u->right); } void i...
/*Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2DDiv2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2iv2Div2Div2Div2 Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2DDiv2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2iv2Div2Div2Div2 Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2Div2DDiv2Div2Div...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
1
339
7
#include <iostream> using namespace std; struct Node { int key; Node *parent, *left, *right; }; Node *NIL, *root; void printPreOrder(Node *u); void printInOrder(Node *u); void insertTree(int k); int main() { int i, j, n, k; char com[10]; cin >> n; for (i = 0; i < n; i++) { cin >> com; if (com[0...
#include <iostream> using namespace std; struct Node { int key; Node *parent, *left, *right; }; Node *NIL, *root; void printPreOrder(Node *u); void printInOrder(Node *u); void insertTree(int k); int main() { int i, j, n, k; char com[10]; cin >> n; for (i = 0; i < n; i++) { cin >> com; if (com[0...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
348
4
#include <bits/stdc++.h> #define INF 2000000001 using namespace std; typedef struct node { node *p, *l, *r; int key; } Node; typedef Node *Nodepointer; Nodepointer T; void insert(int z) { Nodepointer t = (Node *)malloc(sizeof(Node)); t->l = NULL; t->r = NULL; t->key = z; if (T->key == INF) { T->ke...
#include <bits/stdc++.h> #define INF 2000000001 using namespace std; typedef struct node { node *p, *l, *r; int key; } Node; typedef Node *Nodepointer; Nodepointer T; void insert(int z) { Nodepointer t = (Node *)malloc(sizeof(Node)); t->l = NULL; t->r = NULL; t->key = z; if (T->key == INF) { T->ke...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 79], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 79]]
1
475
4
#include <iostream> using namespace std; struct Node { int key; Node *p, *l, *r; }; Node *nil; Node *root = nil; void insert(int k) { Node *y = nil; Node *x = root; Node *z = new Node; z->key = k; z->l = nil; z->r = nil; while (x != nil) { y = x; if (z->key < x->key) x = x->l; els...
#include <iostream> using namespace std; struct Node { int key; Node *p, *l, *r; }; Node *nil; Node *root = nil; void insert(int k) { Node *y = nil; Node *x = root; Node *z = new Node; z->key = k; z->l = nil; z->r = nil; while (x != nil) { y = x; if (z->key < x->key) x = x->l; els...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
333
4
#include <iostream> #include <string> using namespace std; struct Node { int key; Node *parent, *left, *right; }; Node *root, *NIL; void insert(int k) { Node *y = NIL; Node *x = root; Node *z; z = new Node; z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) { y = x; if (z->key...
#include <iostream> #include <string> using namespace std; struct Node { int key; Node *parent, *left, *right; }; Node *root, *NIL; void insert(int k) { Node *y = NIL; Node *x = root; Node *z; z = new Node; z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) { y = x; if (z->key...
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
340
4
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) { return NIL; } Node treeMaximum(Node x) { return NIL; } Node treeSearch(Node u, int k) { return NIL; ...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) { return NIL; } Node treeMaximum(Node x) { return NIL; } Node treeSearch(Node u, int k) { return NIL; ...
[["-", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125]]
1
518
8
#include "bits/stdc++.h" using namespace std; struct Node { int key; Node *right, *left, *parent; }; Node *root, *NIL; void insert(int k) { Node *y = NIL; // x?????? Node *x = root; // T?????? Node *z; z = (Node *)malloc(sizeof(Node)); z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) {...
#include "bits/stdc++.h" using namespace std; struct Node { int key; Node *right, *left, *parent; }; Node *root, *NIL; void insert(int k) { Node *y = NIL; // x?????? Node *x = root; // T?????? Node *z; z = (Node *)malloc(sizeof(Node)); z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) {...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
373
4
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) {} Node treeMaximum(Node x) {} Node treeSearch(Node u, int k) {} Node treeSuccessor(Node x) {} void ...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) {} Node treeMaximum(Node x) {} Node treeSearch(Node u, int k) {} Node treeSuccessor(Node x) {} void ...
[["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]]
0
520
4
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { int key; struct node *r; struct node *l; struct node *p; }; typedef struct node *Node; Node root; void insert(int v) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = v; z->l = NIL; z->r = NIL...
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { int key; struct node *r; struct node *l; struct node *p; }; typedef struct node *Node; Node root; void insert(int v) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = v; z->l = NIL; z->r = NIL...
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 14, 8, 9, 0, 7, 15, 34, 0, 21], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18]]
0
367
3
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL NULL typedef struct node { struct node *right; struct node *left; struct node *parent; int key; } * N; N root = NIL; void insert(int); void inorder(N); void preorder(N); int main() { int m, i, n; char str[32]; scanf("%d", &m); ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL NULL typedef struct node { struct node *right; struct node *left; struct node *parent; int key; } * N; N root = NIL; void insert(int); void inorder(N); void preorder(N); int main() { int m, i, n; char str[256]; scanf("%d", &m); ...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 12, 2, 3, 4, 0, 105, 51, 23, 0, 22], ["+", 3, 4, 0, 105, 39, 77, 39, 122, 0, 149], ["+", 3, 4, 0, 105, 39, 77, 39, 122, 141, 78]]
0
402
5
#include <stdio.h> #include <stdlib.h> typedef struct treeNode { int key; struct treeNode *right; struct treeNode *left; struct treeNode *parent; } Node; void printPreorder(Node *); void printInorder(Node *); void Insert(Node *); Node *T = NULL; int main() { int i, in, root, k; Node *temp; char s[10];...
#include <stdio.h> #include <stdlib.h> typedef struct treeNode { int key; struct treeNode *right; struct treeNode *left; struct treeNode *parent; } Node; void printPreorder(Node *); void printInorder(Node *); void insert(Node *); Node *T = NULL; int main() { int i, in, root, k; Node *temp; char s[10...
[["-", 36, 36, 0, 30, 0, 43, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 43, 49, 53, 49, 22], ["+", 0, 57, 15, 23, 0, 16, 12, 103, 0, 104], ["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["-", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22]]
0
414
8
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Node { int key; struct Node *right, *left, *parent; }; struct Node *root, *NIL; void insert(int); void inorder(struct Node *); void preorder(struct Node *); int main() { int m, i, z; char *s; scanf("%d", &m); for (i = 0; i < m; i++) { ...
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Node { int key; struct Node *right, *left, *parent; }; struct Node *root, *NIL; void insert(int); void inorder(struct Node *); void preorder(struct Node *); int main() { int m, i, z; char s[10]; scanf("%d", &m); for (i = 0; i < m; i++) {...
[["-", 0, 14, 8, 9, 0, 43, 49, 84, 0, 48], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 0, 70], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 0, 73]]
0
413
4
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root; void insert(int k) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = k; z->left...
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root; void insert(int k) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = k; z->left ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
404
2
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { struct node *left; struct node *right; struct node *parent; int key; }; struct node *T; void Insert(int); void Inorder(struct node *); void Preorder(struct node *); void Free(struct node *); int main() { int n, i, key; char func[6]; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { struct node *left; struct node *right; struct node *parent; int key; }; struct node *T; void Insert(int); void Inorder(struct node *); void Preorder(struct node *); void Free(struct node *); int main() { int n, i, key; char func[6]; ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
0
503
19
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL NULL struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root; void insert(int); void inorder(Node); void preorder(Node); int main() { int n, i, x; char s[10]; scanf...
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL NULL struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root; void insert(int); void inorder(Node); void preorder(Node); int main() { int n, i, x; char s[10]; scanf...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
0
394
4
#include <stdio.h> #include <stdlib.h> #define NIL NULL typedef struct Node { int key; struct Node *right, *left, *parent; } Node; Node *root; void insert(int k) { Node *y = NIL; Node *x = root; Node *z; z = malloc(sizeof(Node)); z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) { y ...
#include <stdio.h> #include <stdlib.h> #define NIL NULL typedef struct Node { int key; struct Node *right, *left, *parent; } Node; Node *root; void insert(int k) { Node *y = NIL; Node *x = root; Node *z; z = malloc(sizeof(Node)); z->key = k; z->left = NIL; z->right = NIL; while (x != NIL) { y ...
[["-", 64, 9, 0, 1, 0, 11, 31, 118, 119, 120], ["+", 64, 9, 0, 1, 0, 11, 31, 118, 119, 120]]
0
377
2
#include <stdio.h> #include <stdlib.h> typedef struct { int key; int left; int right; } Node; void insert(Node *, int, int); void print1(Node *, int); void print2(Node *, int); int main() { char s[10]; Node *t; int m; int a; int i; int cnt = 0; scanf("%d", &m); t = (Node *)malloc(sizeof(Node)...
#include <stdio.h> #include <stdlib.h> typedef struct { int key; int left; int right; } Node; void insert(Node *, int, int); void print1(Node *, int); void print2(Node *, int); int main() { char s[10]; Node *t; int m; int a; int i; int cnt = 0; scanf("%d", &m); t = (Node *)malloc(sizeof(Node)...
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22]]
0
508
4
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node *link; struct node { int key; link le, ri, pa; }; link head; void insert(int a); void inorder(link h); void preorder(link h); int main() { int m, k; char op[10]; int i; head = NULL; scanf("%d", &m); for (i = 0; i < m; i++...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node *link; struct node { int key; link le, ri, pa; }; link head; void insert(int a); void inorder(link h); void preorder(link h); int main() { int m, k; char op[10]; int i; head = NULL; scanf("%d", &m); for (i = 0; i < m; i++...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
0
391
4
#include <stdio.h> #include <stdlib.h> struct node { int id; struct node *parentNode; struct node *leftChild; struct node *rightChild; }; struct node *createNode(int); struct node *searchNode(int); void insert(struct node *); void printNodes(void); void preOrder(struct node *); void inOrder(struct node *); ...
#include <stdio.h> #include <stdlib.h> struct node { int id; struct node *parentNode; struct node *leftChild; struct node *rightChild; }; struct node *createNode(int); struct node *searchNode(int); void insert(struct node *); void printNodes(void); void preOrder(struct node *); void inOrder(struct node *); ...
[["-", 0, 30, 0, 43, 49, 84, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 84, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]]
0
556
10
#include <stdio.h> #include <string.h> #define N 500000 typedef struct { int key, left, right; } Node; Node tree[N + 1]; int size; void insert(int x) { int p = 0; while (1) { if (x < tree[p].key) { if (tree[p].left == -1) { tree[p].left = size; tree[size++].key = x; break; ...
#include <stdio.h> #include <string.h> #define N 500000 typedef struct { int key, left, right; } Node; Node tree[N + 1]; int size; void insert(int x) { int p = 0; while (1) { if (x < tree[p].key) { if (tree[p].left == -1) { tree[p].left = size; tree[size++].key = x; break; ...
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22]]
0
454
4
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; void treeDelete(Node z) { Node y; // node to be deleted Node x; // child of y } void insert(int k) { Node y = NIL; Node ...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; void treeDelete(Node z) { Node y; // node to be deleted Node x; // child of y } void insert(int k) { Node y = NIL; Node ...
[["+", 0, 1, 0, 2, 3, 4, 0, 118, 17, 143], ["+", 0, 1, 0, 2, 3, 4, 0, 118, 119, 120]]
0
396
4
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { struct node *l; struct node *r; struct node *p; int key; }; typedef struct node *Node; Node root; main() { int n, i, x; char str[20]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); if (str[0] == 'i') { ...
#include <stdio.h> #include <stdlib.h> #define NIL NULL struct node { struct node *l; struct node *r; struct node *p; int key; }; typedef struct node *Node; Node root; main() { int n, i, x; char str[20]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", str); if (str[0] == 'i') { ...
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22]]
0
404
2
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /*Node treeMinimum(Node x){ while(x->left!=NIL)x=x->left; return x; } Node treeSearch(Node u, int k){ /*while(u!=NIL && k...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /*Node treeMinimum(Node x){ while(x->left!=NIL)x=x->left; return x; } Node treeSearch(Node u, int k){ /*while(u!=NIL && k...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
392
4
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /* Node treeMinimum(Node x){ while(x->left != NIL){ x=x->right; } return x; } Node treeSearch(Node u, int k){ if(...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /* Node treeMinimum(Node x){ while(x->left != NIL){ x=x->right; } return x; } Node treeSearch(Node u, int k){ if(...
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
432
6
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; void insert(int k) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = k; z->left = NIL...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; void insert(int k) { Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z->key = k; z->left = NIL...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22]]
0
398
8
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /* Node treeMinimum(Node x){ } Node treeSearch(Node u, int k){ } Node treeSuccessor(Node x){ } */ Node treeMinimum(Node x...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; /* Node treeMinimum(Node x){ } Node treeSearch(Node u, int k){ } Node treeSuccessor(Node x){ } */ Node treeMinimum(Node x...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
518
4
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) { while (x->left != NIL) { x = x->left; } return x; } Node treeSearch(Node u, int k) { if (...
#include <stdio.h> #include <stdlib.h> struct node { struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; #define NIL NULL Node root; Node treeMinimum(Node x) { while (x->left != NIL) { x = x->left; } return x; } Node treeSearch(Node u, int k) { if (...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
646
4
#include <iostream> using namespace std; #include <stdio.h> #include <stdlib.h> void to_post(int *A, int *B, int *C, int h) { int x = A[0]; C[h - 1] = x; if (h < 2) return; int m = 0; while (B[m] != x) m++; if (m > 0) to_post(A + 1, B, C, m); if (h - m - 1 > 0) to_post(A + m + 1, B + m + ...
#include <iostream> using namespace std; #include <stdio.h> #include <stdlib.h> void to_post(int *A, int *B, int *C, int h) { int x = A[0]; C[h - 1] = x; if (h < 2) return; int m = 0; while (B[m] != x) m++; if (m > 0) to_post(A + 1, B, C, m); if (h - m - 1 > 0) to_post(A + m + 1, B + m + ...
[["-", 3, 4, 0, 66, 28, 69, 341, 342, 0, 22], ["+", 3, 4, 0, 66, 28, 69, 341, 342, 0, 22]]
1
323
2
#include <algorithm> #include <cstdio> #include <iostream> #include <iterator> #include <vector> using namespace std; vector<int> pre, in, post; int pos = 0; void constructPost(int l, int r) { if (l >= r) return; int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); con...
#include <algorithm> #include <cstdio> #include <iostream> #include <iterator> #include <vector> using namespace std; vector<int> pre, in, post; int pos = 0; void constructPost(int l, int r) { if (l >= r) return; int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); con...
[["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
259
3
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int n, pos; vector<int> pre, in, post; void rec(int l, int r) { if (l >= r) return; int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); rec(l, m); rec(m + 1, r); post.pu...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int n, pos; vector<int> pre, in, post; void rec(int l, int r) { if (l == r) return; int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); rec(l, m); rec(m + 1, r); post.pu...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
239
4
#include <algorithm> #include <cstring> #include <iostream> using namespace std; struct node { int left, right; } nodes[100]; int n, pre[105], in[105], inloc[105], cnt = 0; int rec(int s, int e) { if (s < e) { int m = inloc[pre[cnt++]]; int l = rec(s, m - 1); int r = rec(m + 1, e); nodes[in[m]].l...
#include <algorithm> #include <cstring> #include <iostream> using namespace std; struct node { int left, right; } nodes[100]; int n, pre[105], in[105], inloc[105], cnt = 0; int rec(int s, int e) { if (s < e) { int m = inloc[pre[cnt++]]; int l = rec(s, m - 1); int r = rec(m + 1, e); nodes[in[m]].l...
[["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["+", 75, 76, 0, 57, 64, 9, 0, 1, 0, 35]]
1
334
3
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int N, pos; vector<int> pre, in, post; void rec(int left, int right) { if (left >= right) { return; } int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); rec(left, m); ...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int N, pos; vector<int> pre, in, post; void rec(int left, int right) { if (left >= right) { return; } int root = pre[pos++]; int m = distance(in.begin(), find(in.begin(), in.end(), root)); rec(left, m); ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35]]
1
246
3