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
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 8 insert 30 insert 88 insert 12 insert 1 insert 20 insert 17 insert 25 print output: in_order + pre_order 1 12 17 20 25 30 88 30 12 1 20 17 25 88 def pre_order(node): if node is not None: print('', node.data, end='') pre_order(node.left) ...
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 8 insert 30 insert 88 insert 12 insert 1 insert 20 insert 17 insert 25 print output: in_order + pre_order 1 12 17 20 25 30 88 30 12 1 20 17 25 88 def pre_order(node): if node is not None: print('', node.data, end='') pre_order(node.left) ...
[["-", 36, 36, 0, 656, 0, 1, 0, 557, 0, 6], ["+", 36, 36, 0, 656, 0, 1, 0, 557, 0, 6], ["-", 75, 665, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 75, 665, 64, 196, 0, 1, 0, 652, 63, 22]]
5
363
23
#BinarySearchTree class TreeNode(): def __init__(self): self.key = None self.parent = None self.left = None self.right = None def inoder(self): r=[] if self.left: r += self.left.inoder() r += [self.key] if self.right: r += s...
#BinarySearchTree class TreeNode(): def __init__(self): self.key = None self.parent = None self.left = None self.right = None def inoder(self): r=[] if self.left: r += self.left.inoder() r += [self.key] if self.right: r += s...
[["-", 0, 1, 0, 677, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 677, 12, 652, 63, 319, 319, 22]]
5
351
4
import sys class Node: def __init__(self, x): self.data = x self.left = None self.right = None def insert(node, x): if node == None: return Node(x) #============================================================================== # elif x == node.data: # ...
import sys class Node: def __init__(self, x): self.data = x self.left = None self.right = None def insert(node, x): if node == None: return Node(x) #============================================================================== # elif x == node.data: # ...
[["-", 0, 1, 0, 677, 12, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 677, 12, 652, 63, 319, 319, 22]]
5
755
4
class Node(): def __init__(self, key): self.parent = None self.left = None self.right = None self.key = key class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: ...
class Node(): def __init__(self, key): self.parent = None self.left = None self.right = None self.key = key class Tree(): def __init__(self): self.root = None def insert(self, key): z = Node(key) y = None x = self.root while x: ...
[["-", 64, 196, 0, 1, 0, 652, 63, 319, 319, 22], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 319, 22]]
5
329
4
# -*- coding: utf-8 -*- class Node(): def __init__(self, key, parent=None, left=None, right=None): self.key = key self.parent = parent self.left = left self.right = right class BinarySearchTree(list): def __init__(self): list.__init__(self) self.root = ...
# -*- coding: utf-8 -*- class Node(): def __init__(self, key, parent=None, left=None, right=None): self.key = key self.parent = parent self.left = left self.right = right class BinarySearchTree(list): def __init__(self): list.__init__(self) self.root = ...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
352
3
import sys class Node: __slots__ = ['key', 'left', 'right'] def __init__(self, key): self.key = key self.left = self.right = None class BST: def __init__(self): self.root = None def insert(self, key): x, y = self.root, None while x != None: x, y = x.left if key ...
import sys class Node: __slots__ = ['key', 'left', 'right'] def __init__(self, key): self.key = key self.left = self.right = None class BST: def __init__(self): self.root = None def insert(self, key): x, y = self.root, None while x != None: x, y = x.left if key ...
[["-", 75, 76, 8, 196, 0, 1, 0, 662, 12, 22], ["+", 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, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
269
5
# Binary Search Tree class Node: def __init__(self, v): self.value = v self.parent = None self.left = None self.right = None # 木の根を引数として受け取り,データを挿入した新しい木の根を返す def insert_(node, x): if node is None: return Node(x) elif x == node.value: return node elif x <...
# Binary Search Tree class Node: def __init__(self, v): self.value = v self.parent = None self.left = None self.right = None # 木の根を引数として受け取り,データを挿入した新しい木の根を返す def insert_(node, x): if node is None: return Node(x) elif x == node.value: return node elif x <...
[["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
326
3
class Tree: def __init__(self, orders): self.root = None for order in orders: if len(order) == 1: self.inorder_print() self.preorder_print() else: self.insert(int(order[1])) def insert(self, key): z = Node(key) ...
class Tree: def __init__(self, orders): self.root = None for order in orders: if len(order) == 1: self.inorder_print() self.preorder_print() else: self.insert(int(order[1])) def insert(self, key): z = Node(key) ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
333
4
import sys tree={} np = -1 home=0 tree[home]=[None, None, None] def search(p, x): while p != None: tmp = tree[p] if tmp[0] == x: return True if x < tmp: p = tmp[1] else: p = tmp[2] return False def node(x): global np np += 1 tree[np] = [x, ...
import sys tree={} np = -1 home=0 tree[home]=[None, None, None] def search(p, x): while p != None: tmp = tree[p] if tmp[0] == x: return True if x < tmp[0]: p = tmp[1] else: p = tmp[2] return False def node(x): global np np += 1 tree[np] = [...
[["+", 8, 196, 0, 57, 15, 666, 0, 206, 0, 70], ["+", 8, 196, 0, 57, 15, 666, 0, 206, 206, 612], ["+", 8, 196, 0, 57, 15, 666, 0, 206, 0, 73], ["+", 0, 57, 75, 665, 15, 666, 0, 206, 0, 70], ["+", 0, 57, 75, 665, 15, 666, 0, 206, 206, 612], ["+", 0, 57, 75, 665, 15, 666, 0, 206, 0, 73]]
5
382
6
package main import ( "fmt" "bufio" "os" "strconv" ) const INF = 2000000001 const MAX_ELE = 250 var heapArray []int func printParent(index int) { if index != 0 { fmt.Printf("parent kye = %d, ", heapArray[(index-1)/2]) } } func printLeft(parent int) { index := parent*2 + 1 if parent < 250 && heapArray[ind...
package main import ( "fmt" "bufio" "os" "strconv" ) const INF = 2000000001 const MAX_ELE = 250 var heapArray []int func printParent(index int) { if index != 0 { fmt.Printf("parent key = %d, ", heapArray[(index-1)/2]) } } func printLeft(parent int) { index := parent*2 + 1 if index < 250 && heapArray[inde...
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
7
327
6
(function main() { const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'); const n = Number(lines.shift()); const arr = lines.shift().split(' '); function buildMaxHeap(arr) { const n = arr.length; const maxHeapify = (i) => { let left, right, largest = i; left...
(function main() { const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n'); const n = Number(lines.shift()); const arr = lines.shift().split(' '); function buildMaxHeap(arr) { const n = arr.length; const maxHeapify = (i) => { let left, right, largest = i; left...
[["-", 0, 11, 12, 16, 12, 23, 0, 563, 12, 555], ["+", 12, 16, 12, 23, 0, 563, 12, 557, 0, 62]]
2
260
3
import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in); static int n = s.nextInt(); public static void main(String[] args) { StringBuilder sb = new StringBuilder(); int[] a = new int[n + 1]; for (int i = 1; i < n; i++) { a[i] = s.nextInt(); } bui...
import java.util.Scanner; public class Main { private static Scanner s = new Scanner(System.in); static int n = s.nextInt(); public static void main(String[] args) { StringBuilder sb = new StringBuilder(); int[] a = new int[n + 1]; for (int i = 1; i < n + 1; i++) { a[i] = s.nextInt(); } ...
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 499], ["-", 0, 1, 0, 492, 3, 4, 0, 492, 0, 131], ["-", 0, 1, 0, 492, 3, 4, 0, 492, 141, 22], ["-", 0, 492, 3, 4, 0, 492, 3, 4, 0, 24], ["-", 0, 492, 3, 4, 0, 492, 3, 4, 0, 25]]
3
307
6
#include <stdio.h> int Array[500000]; int H; void maxHeapify(int i) { int left = 2 * (i + 1) - 1; int right = 2 * (i + 1); int largest; // select the node which has the maximum value if (left <= H && Array[left] > Array[i]) largest = left; else largest = i; if (right <= H && Array[right] > Array...
#include <stdio.h> int Array[500000]; int H; void maxHeapify(int i) { int left = 2 * (i + 1) - 1; int right = 2 * (i + 1); int largest; if (left <= H && Array[left] > Array[i]) largest = left; else largest = i; if (right <= H && Array[right] > Array[largest]) largest = right; if (largest !=...
[["+", 10, 43, 49, 50, 51, 16, 31, 23, 0, 24], ["+", 10, 43, 49, 50, 51, 16, 31, 23, 0, 25], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20]]
0
260
6
#include <stdio.h> #define MAX 2000000 int H, A[MAX + 1], a; void maxH(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = r; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (largest != i) { a = A[i]; A[i] = A[largest]; A...
#include <stdio.h> #define MAX 2000000 int H, A[MAX + 1], a; void maxH(int i) { int l, r, largest; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (largest != i) { a = A[i]; A[i] = A[largest]; A...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
0
230
2
#include <stdio.h> #define MAX 500000 #define NIL -1 //#define SWAP(a,b) {typeof(a) temp = a; a = b; b = temp; } typedef struct node { int leftid; //親がもっている左側のid int rightid; //親がもっている右側のid int left; //親がもっている左側のkey int right; //親がもっている右側のkey int key; //自身のkey int p; //自身の親のkey } Node; void...
#include <stdio.h> #define MAX 500000 #define NIL -1 //#define SWAP(a,b) {typeof(a) temp = a; a = b; b = temp; } typedef struct node { int leftid; //親がもっている左側のid int rightid; //親がもっている右側のid int left; //親がもっている左側のkey int right; //親がもっている右側のkey int key; //自身のkey int p; //自身の親のkey } Node; void...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 8, 9, 0, 57, 15, 23, 0, 34, 0, 21], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 98]]
0
609
8
#include <stdio.h> #include <stdlib.h> #define MAX 100000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; int tmp; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (largest != i) { t...
#include <stdio.h> #include <stdlib.h> #define MAX 1000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, largest; int tmp; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (largest != i) { ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
243
4
#include <stdio.h> #define N 2000000 int Heap, A[N]; void maxHeapify(int i) { int left, right, L, tmp; left = 2 * i; right = 2 * i * 1; if (left <= Heap && A[left] > A[i]) { L = left; } else { L = i; } if (right <= Heap && A[right] > A[L]) { L = right; } if (L != i) { tmp = A[i]; ...
#include <stdio.h> #define N 2000000 int Heap, A[N]; void maxHeapify(int i) { int left, right, L, tmp; left = 2 * i; right = 2 * i + 1; if (left <= Heap && A[left] > A[i]) { L = left; } else { L = i; } if (right <= Heap && A[right] > A[L]) { L = right; } if (L != i) { tmp = A[i]; ...
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
0
238
2
#include <stdio.h> #define MAX 500001 int heap[MAX]; int main() { int i, H; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &heap[i]); } buildMaxHeap(heap, H); for (i = 1; i <= H; i++) { printf(" %d", heap[i]); } printf("\n"); return 0; } maxHeapify(int *A, int i, int H) { int l, r,...
#include <stdio.h> #define MAX 500001 int heap[MAX]; int main() { int i, H; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &heap[i]); } buildMaxHeap(heap, H); for (i = 1; i <= H; i++) { printf(" %d", heap[i]); } printf("\n"); return 0; } maxHeapify(int *A, int i, int H) { int l, r,...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 19]]
0
269
2
#include <stdio.h> #define H 500000 int A[H], l; void maxHeapify(int i) { int left, right, largest, x; left = 2 * i; right = 2 * i + 1; if (left <= l && A[l] > A[i]) { largest = left; } else { largest = i; } if (right <= l && A[right] > A[largest]) { largest = right; } if (largest != i) ...
#include <stdio.h> #define H 500000 int A[H], l; void maxHeapify(int i) { int left, right, largest, x; left = 2 * i; right = 2 * i + 1; if (left <= l && A[left] > A[i]) { largest = left; } else { largest = i; } if (right <= l && A[right] > A[largest]) { largest = right; } if (largest != ...
[["-", 15, 23, 0, 16, 12, 16, 31, 69, 71, 22], ["+", 15, 23, 0, 16, 12, 16, 31, 69, 71, 22]]
0
242
2
#include <stdio.h> #define MAX 2000000000 int H, A[MAX]; void maxHeapify(int i); int main() { int i; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &A[i]); } for (i = H / 2; i >= 1; i--) { maxHeapify(i); } for (i = 1; i <= H; i++) { if (i == H) { printf("%d\n", A[i]); } e...
#include <stdio.h> #define MAX 20000000 int H, A[MAX]; void maxHeapify(int i); int main() { int i; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &A[i]); } for (i = H / 2; i >= 1; i--) { maxHeapify(i); } for (i = 1; i <= H; i++) { if (i == H) { printf(" %d\n", A[i]); } el...
[["-", 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]]
0
263
6
#include <stdio.h> #include <stdlib.h> /* struct node{ struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root, NIL; void insert(int k){ int N; Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z -> key = k; z -> left ...
#include <stdio.h> #include <stdlib.h> /* struct node{ struct node *right; struct node *left; struct node *parent; int key; }; typedef struct node *Node; Node root, NIL; void insert(int k){ int N; Node y = NIL; Node x = root; Node z; z = malloc(sizeof(struct node)); z -> key = k; z -> left ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21]]
0
238
2
#include <stdio.h> int T[500000]; int size; void maxHeapify(int i) { int l, r, max = 0, tmp; l = left(i); r = right(i); if (l <= size && T[1] > T[i]) { max = l; } else { max = i; } if (r <= size && T[r] > T[max]) { max = r; } if (max != i) { tmp = T[i]; T[i] = T[max]; T[max] =...
#include <stdio.h> int T[500000]; int size; void maxHeapify(int i) { int l, r, max = 0, tmp; l = left(i); r = right(i); if (l <= size && T[l] > T[i]) { max = l; } else { max = i; } if (r <= size && T[r] > T[max]) { max = r; } if (max != i) { tmp = T[i]; T[i] = T[max]; T[max] =...
[["-", 15, 23, 0, 16, 12, 16, 31, 69, 71, 13], ["+", 15, 23, 0, 16, 12, 16, 31, 69, 71, 22]]
0
280
2
#include <stdio.h> #define heap_max 500000 int inHeap; long heap[heap_max]; void maxHeapify(long A[], int i) { int l, r, largest; long temp; l = i * 2; r = i * 2 + 1; if (inHeap >= 1 && A[l] > A[i]) largest = l; else largest = i; if (inHeap >= r && A[r] > A[largest]) largest = r; if (larges...
#include <stdio.h> #define heap_max 500000 int inHeap; long heap[heap_max]; void maxHeapify(long A[], int i) { int l, r, largest; long temp; l = i * 2; r = i * 2 + 1; if (inHeap >= l && A[l] > A[i]) largest = l; else largest = i; if (inHeap >= r && A[r] > A[largest]) largest = r; if (larges...
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 79], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 40]]
0
261
7
#include <stdio.h> #define MAX 500000 int A[MAX]; int heap_size; void maxHeapify(int i) { int l, r, largest, tmp; l = 2 * i; r = l + 1; if (l <= heap_size && A[l] > A[i]) largest = l; else largest = i; if (r <= heap_size && A[r] > A[largest]) largest = r; if (largest != i) { tmp = A[i];...
#include <stdio.h> #define MAX 500001 int A[MAX]; int heap_size; void maxHeapify(int i) { int l, r, largest, tmp; l = 2 * i; r = l + 1; if (l <= heap_size && A[l] > A[i]) largest = l; else largest = i; if (r <= heap_size && A[r] > A[largest]) largest = r; if (largest != i) { tmp = A[i];...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
247
4
#include <stdio.h> #define H 5000000 int A[H], n; void maxHeapify(int *A, int i) { int r, l, largest, a; l = 2 * i; r = (2 * i) + l; if (l <= n && A[l] > A[i]) largest = l; else largest = i; if (r <= n && A[r] > A[largest]) largest = r; if (largest != i) { a = A[i]; A[i] = A[la...
#include <stdio.h> #define H 5000000 int A[H], n; void maxHeapify(int *A, int i) { int r, l, largest, a; l = 2 * i; r = (2 * i) + 1; if (l <= n && A[l] > A[i]) largest = l; else largest = i; if (r <= n && A[r] > A[largest]) largest = r; if (largest != i) { a = A[i]; A[i] = A[la...
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 64, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["+", 64, 9, 0, 1, 0, 11, 31, 69, 71, 22]]
0
253
4
#include <stdio.h> #include <stdlib.h> void maxHeap(int *, int, int); int main(void) { int i, num; int H[500000]; scanf("%d", &num); for (i = 1; i <= num; i++) scanf("%d", &H[i]); for (i = num / 2; i > 0; i--) maxHeap(&H, i, num); for (i = 1; i <= num; i++) printf(" %d", H[i]); printf("\...
#include <stdio.h> #include <stdlib.h> void maxHeap(int *, int, int); int main(void) { int i, num; int H[500000]; scanf("%d", &num); for (i = 1; i <= num; i++) scanf("%d", &H[i]); for (i = num / 2; i > 0; i--) maxHeap(H, i, num); for (i = 1; i <= num; i++) printf(" %d", H[i]); printf("\n...
[["-", 8, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
0
294
2
#include <stdio.h> int i, H, A[1000]; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int *A, int i) { int largest, tmp; int l = left(i), r = right(i); if (l <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (r <= H && A[r] > A[largest]) { ...
#include <stdio.h> int i, H, A[2000000]; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void maxHeapify(int *A, int i) { int largest, tmp; int l = left(i), r = right(i); if (l <= H && A[l] > A[i]) { largest = l; } else { largest = i; } if (r <= H && A[r] > A[largest]) {...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
0
281
4
#include <stdio.h> #define H 500000 int n; int s[H]; void maxHeapify(int); void buildMaxHeap(); int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &s[i]); } buildMaxHeap(); for (i = 1; i <= n; i++) printf(" %d", s[i]); printf("\n"); return 0; } void buildMaxHeap...
#include <stdio.h> #define H 5000000 int n; int s[H]; void maxHeapify(int); void buildMaxHeap(); int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &s[i]); } buildMaxHeap(); for (i = 1; i <= n; i++) printf(" %d", s[i]); printf("\n"); return 0; } void buildMaxHea...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 12, 22]]
0
253
6
#include <stdio.h> #define MAX 5000005 void maxHeapify(int *, int); void swap(int *, int *); int H; int main() { int i, A[MAX]; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &A[i]); } for (i = H / 2; i > 0; i--) { maxHeapify(A, i); } for (i = 1; i <= H; i++) { printf(" %d",...
#include <stdio.h> #define MAX 2000000 void maxHeapify(int *, int); void swap(int *, int *); int H; int main() { int i, A[MAX]; scanf("%d", &H); for (i = 1; i <= H; i++) { scanf("%d", &A[i]); } for (i = H / 2; i > 0; i--) { maxHeapify(A, i); } for (i = 1; i <= H; i++) { printf(" %d",...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
279
2
#include <iostream> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, target; l = 2 * i; r = 2 * i + 1; //从左子节点,自身,右子节点中选出最大的节点值 if (l <= H && A[l] > A[i]) target = l; else target = i; if (r <= H && A[i] < A[r]) target = r; if (target != i...
#include <iostream> using namespace std; #define MAX 2000000 int H, A[MAX + 1]; void maxHeapify(int i) { int l, r, target; l = 2 * i; r = 2 * i + 1; //从左子节点,自身,右子节点中选出最大的节点值 if (l <= H && A[l] > A[i]) target = l; else target = i; if (r <= H && A[target] < A[r]) target = r; if (target...
[["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22]]
1
208
2
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxx = 500100; int A[maxx]; int n; void max_heap(int i) { int left = 2 * i, right = left + 1, x; if (left <= n && A[left] > A[i]) x = left; else x = i; if (right <= n && A[right] > A[i]) x = right; if (x != ...
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxx = 500100; int A[maxx]; int n; void max_heap(int i) { int left = 2 * i, right = 2 * i + 1, x; if (left <= n && A[left] > A[i]) x = left; else x = i; if (right <= n && A[right] > A[x]) x = right; if (x !=...
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 31, 13], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 17, 48], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 12, 22], ["-", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 51, 16, 12, 16, 12, 69, 341, 342, 0, 22]]
1
205
6
class Node include Comparable def initialize(id, key) @id = id @key = key end def <=>(other) @key <=> other.key end DUMMY = Node.new(-1, -1) attr_accessor :id, :key end def maxHeapify(array, i) left = (i*2 < array.size) ? array[i*2] : Node::DUMMY right = (i*2+1 < array.size) ? array[i...
class Node include Comparable def initialize(id, key) @id = id @key = key end def <=>(other) @key <=> other.key end DUMMY = Node.new(-1, -2_000_000_001) attr_accessor :id, :key end def maxHeapify(array, i) left = (i*2 < array.size) ? array[i*2] : Node::DUMMY right = (i*2+1 < array.siz...
[["-", 0, 662, 12, 652, 3, 4, 0, 748, 439, 612], ["+", 0, 662, 12, 652, 3, 4, 0, 748, 439, 612]]
4
322
2
def maxHeapify(x) l = 2*x r = 2*x+1 if l <= $n && $heap[l] > $heap[x] largest = l else largest = x end if r <= $n && $heap[r] > $heap[largest] largest = r end if largest != x $heap[x], $heap[largest] = $heap[largest], $heap[x] maxHeapify(largest) end end def buildMaxHeap ($n/2).d...
def maxHeapify(x) l = 2*x r = 2*x+1 if l <= $n && $heap[l] > $heap[x] largest = l else largest = x end if r <= $n && $heap[r] > $heap[largest] largest = r end if largest != x $heap[x], $heap[largest] = $heap[largest], $heap[x] maxHeapify(largest) end end def buildMaxHeap ($n/2).d...
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22]]
4
147
2
def get_left_index(A, i): if len(A) > 2 * i: return 2 * i else: return None def get_right_index(A, i): if len(A) > 2 * i + 1: return 2 * i + 1 else: return None def max_heapfy(A, i): left = get_left_index(A, i) right = get_right_index(A, i) largest = i i...
def get_left_index(A, i): if len(A) > 2 * i: return 2 * i else: return None def get_right_index(A, i): if len(A) > 2 * i + 1: return 2 * i + 1 else: return None def max_heapfy(A, i): left = get_left_index(A, i) right = get_right_index(A, i) largest = i i...
[["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
235
4
#coding:UTF-8 def maxHeapify(A,i,n): print(i) l=2*i r=2*i+1 if l <=n and A[l]>A[i] : largest=l else: largest=i if r<=n and A[r]>A[largest]: largest=r if largest!=i: A[i],A[largest]=A[largest],A[i] maxHeapify(A,largest,n) def MH(A,n): for i in rang...
#coding:UTF-8 def maxHeapify(A,i,n): l=2*i r=2*i+1 if l <=n and A[l]>A[i] : largest=l else: largest=i if r<=n and A[r]>A[largest]: largest=r if largest!=i: A[i],A[largest]=A[largest],A[i] maxHeapify(A,largest,n) def MH(A,n): for i in range(int(n/2),0,...
[["-", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
243
4
#include <bits/stdc++.h> using namespace std; #define MAX 25 #define NIL -1 struct node { int parent, left, right; }; node T[MAX]; int n, D[MAX], H[MAX]; void insert() { int i; for (i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL; for (i = 0; i < n; i++) { int id; scanf("%d", &id...
#include <bits/stdc++.h> using namespace std; #define MAX 25 #define NIL -1 struct node { int parent, left, right; }; node T[MAX]; int n, D[MAX], H[MAX]; void insert() { int i; for (i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL; for (i = 0; i < n; i++) { int id; scanf("%d", &id...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
453
2
#include <iostream> #include <stdio.h> #include <stdlib.h> #define MAX 100000 #define NIL -1 using namespace std; typedef struct { int right; int left; int parent; } Node; Node T[MAX]; void inorder(int x) { if (x == NIL) return; inorder(T[x].left); cout << " " << x; inorder(T[x].right); } void pr...
#include <iostream> #include <stdio.h> #include <stdlib.h> #define MAX 100000 #define NIL -1 using namespace std; typedef struct { int right; int left; int parent; } Node; Node T[MAX]; void inorder(int x) { if (x == NIL) return; inorder(T[x].left); cout << " " << x; inorder(T[x].right); } void pr...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
377
2
#include <iostream> using ll = long long; using namespace std; /* initialize */ struct Node { int p, l, r; }; struct Node T[10000]; int n; void preorder(int v) { if (v == -1) return; printf(" %d", v); preorder(T[v].l); preorder(T[v].r); }; void inorder(int v) { if (v == -1) return; inorder(T[v]....
#include <iostream> using ll = long long; using namespace std; /* initialize */ struct Node { int p, l, r; }; struct Node T[10000]; int n; void preorder(int v) { if (v == -1) return; printf(" %d", v); preorder(T[v].l); preorder(T[v].r); }; void inorder(int v) { if (v == -1) return; inorder(T[v]....
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
394
2
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> using namespace std; typedef long long ll; typedef unsigned long long ull; const int MAX_N = 100000; const int INF = 0x3f3f3f3f; #define maxn...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> using namespace std; typedef long long ll; typedef unsigned long long ull; const int MAX_N = 100000; const int INF = 0x3f3f3f3f; #define maxn...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
412
6
#include <bits/stdc++.h> using namespace std; #define NIL -1 struct node { int p, r, l; }; node tree[30]; int n; void preorder(int u) { if (u == NIL) return; cout << " " << u; preorder(tree[u].r); preorder(tree[u].l); } void inorder(int u) { if (u == NIL) return; inorder(tree[u].r); cout <<...
#include <bits/stdc++.h> using namespace std; #define NIL -1 struct node { int p, r, l; }; node tree[30]; int n; void preorder(int u) { if (u == NIL) return; cout << " " << u; preorder(tree[u].r); preorder(tree[u].l); } void inorder(int u) { if (u == NIL) return; inorder(tree[u].r); cout <<...
[["-", 0, 11, 31, 118, 28, 69, 341, 342, 0, 22], ["+", 0, 11, 31, 118, 28, 69, 341, 342, 0, 22]]
1
362
4
#include <iostream> #include <map> #include <set> using namespace std; typedef struct node { int id; node *left, *right; node(int id) : id(id), left(NULL), right(NULL) {} } Node; class Solution { private: map<int, Node *> hashMapping; set<int> rootCandidates, nonRootNodes; Node *createNode(int ID) { if...
#include <iostream> #include <map> #include <set> using namespace std; typedef struct node { int id; node *left, *right; node(int id) : id(id), left(NULL), right(NULL) {} } Node; class Solution { private: map<int, Node *> hashMapping; set<int> rootCandidates, nonRootNodes; Node *createNode(int ID) { if...
[["-", 8, 9, 0, 52, 8, 9, 0, 57, 0, 121], ["+", 8, 9, 0, 52, 8, 9, 0, 52, 0, 89], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94]]
1
671
4
#include <iostream> using namespace std; int P[26] = {}; int L[26] = {}; int R[26] = {}; void preorder(int root) { if (root < 0) return; cout << " " << root; preorder(L[root]); preorder(R[root]); } void inorder(int root) { if (root < 0) return; inorder(L[root]); cout << " " << root; inorder(R[...
#include <iostream> using namespace std; int P[26] = {}; int L[26] = {}; int R[26] = {}; void preorder(int root) { if (root < 0) return; cout << " " << root; preorder(L[root]); preorder(R[root]); } void inorder(int root) { if (root < 0) return; inorder(L[root]); cout << " " << root; inorder(R[...
[["-", 0, 52, 15, 339, 51, 16, 12, 69, 28, 22], ["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 70], ["-", 51, 16, 12, 69, 341, 342, 0, 69, 28, 22], ["-", 12, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["-", 12, 69, 341, 342, 0, 69, 341, 342, 0, 73], ["-", 15, 339, 51, 16, 12, 69, 341, 342, 0, 73]]
1
336
6
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp...
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
572
2
#include <cstdio> #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct 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 ...
#include <cstdio> #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct 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 ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
397
4
// ALDS1_7_C #include <algorithm> #include <iostream> #include <vector> using namespace std; struct Node { int parent; int children[2]; }; void pre_walk(vector<Node> Tree, int p) { cout << " " << p; for (int i = 0; i < 2; i++) if (Tree[p].children[i] != -1) pre_walk(Tree, Tree[p].children[i]); } v...
// ALDS1_7_C #include <algorithm> #include <iostream> #include <vector> using namespace std; struct Node { int parent; int children[2]; }; void pre_walk(vector<Node> Tree, int p) { cout << " " << p; for (int i = 0; i < 2; i++) if (Tree[p].children[i] != -1) pre_walk(Tree, Tree[p].children[i]); } v...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
478
4
#include <algorithm> #include <cstdio> using namespace std; const int NIL = -1; struct node { int parent; int left; int right; }; node nodes[100000]; void preorder(int v) { if (v == NIL) return; printf(" %d", v); preorder(nodes[v].left); preorder(nodes[v].right); } void inorder(int v) { if (v ==...
#include <algorithm> #include <cstdio> using namespace std; const int NIL = -1; struct node { int parent; int left; int right; }; node nodes[100000]; void preorder(int v) { if (v == NIL) return; printf(" %d", v); preorder(nodes[v].left); preorder(nodes[v].right); } void inorder(int v) { if (v ==...
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
409
3
#include <algorithm> #include <iostream> using namespace std; struct node { node() : p(-1), l(-1), r(-1) {} int p, l, r; }; void preorder(node t[], int id) { if (id == -1) return; cout << ' ' << id; preorder(t, t[id].l); preorder(t, t[id].r); } void inorder(node t[], int id) { if (id == -1) retu...
#include <algorithm> #include <iostream> using namespace std; struct node { node() : p(-1), l(-1), r(-1) {} int p, l, r; }; void preorder(node t[], int id) { if (id == -1) return; cout << ' ' << id; preorder(t, t[id].l); preorder(t, t[id].r); } void inorder(node t[], int id) { if (id == -1) retu...
[["-", 8, 9, 0, 7, 15, 16, 31, 16, 17, 151], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 18]]
1
390
2
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; struct node { int parent, left, right; }; node t[100]; int n, NIL =...
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <stack> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; struct node { int parent, left, right; }; node t[100]; int n, NIL =...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
398
4
/* * File: main.cpp * Author: masa * * Created on 2016/03/12, 7:31 */ #include <cstdlib> #include <string> //#include <fstream> #include <iostream> using namespace std; #define MAX 26 #define NIL -1 struct Node { int parent; int left; int right; }; Node treeNodes[MAX]; /* * */ void printPreOrder(i...
/* * File: main.cpp * Author: masa * * Created on 2016/03/12, 7:31 */ #include <cstdlib> #include <string> //#include <fstream> #include <iostream> using namespace std; #define MAX 26 #define NIL -1 struct Node { int parent; int left; int right; }; Node treeNodes[MAX]; /* * */ void printPreOrder(i...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
464
6
#include <stdio.h> int n, v, a[25][2], r; bool f[25]; void p1(int u) { if (~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); } void p2(int u) { if (~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); } void p3(int u) { if (~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); } int m...
#include <stdio.h> int n, v, a[25][2], r; bool f[25]; void p1(int u) { if (!~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); } void p2(int u) { if (!~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); } void p3(int u) { if (!~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); } in...
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111]]
1
324
8
#include <stdio.h> int n, v, a[25][2], r; bool f[25]; void p1(int u) { if (~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); } void p2(int u) { if (~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); } void p3(int u) { if (~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); } int m...
#include <stdio.h> int n, v, a[25][2], r, f[25]; void p1(int u) { if (!~u) return; printf(" %d", u), p1(a[u][0]), p1(a[u][1]); } void p2(int u) { if (!~u) return; p2(a[u][0]), printf(" %d", u), p2(a[u][1]); } void p3(int u) { if (!~u) return; p3(a[u][0]), p3(a[u][1]), printf(" %d", u); } int mai...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 0, 35], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 0, 21], ["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["-", 0, 34, 12, 34, 12, 11, 12, 11, 12, 146], ["+", 0, 34, 12, 34, 12, 11, 12, 11, 12, 13]]
1
324
8
#include <bits/stdc++.h> using namespace std; struct node { int p, l, r; }; node N[30]; void dfs1(int x) { if (x == -1) return; cout << " " << x; dfs1(N[x].l); dfs1(N[x].r); } void dfs2(int x) { if (x == -1) return; dfs2(N[x].l); cout << " " << x; dfs2(N[x].r); } void dfs3(int x) { if (x ...
#include <bits/stdc++.h> using namespace std; struct node { int p, l, r; }; node N[30]; void dfs1(int x) { if (x == -1) return; cout << " " << x; dfs1(N[x].l); dfs1(N[x].r); } void dfs2(int x) { if (x == -1) return; dfs2(N[x].l); cout << " " << x; dfs2(N[x].r); } void dfs3(int x) { if (x ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
362
2
// ALDS1_7C #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u]....
// ALDS1_7C #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u]....
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
367
6
#include <cstdio> #include <iostream> using namespace std; static const int MAX_NUM = 25; static const int NOELEM = -1; struct stNode { int parent; int left; int right; }; void Preoder(stNode elem[], int root) { if (root != NOELEM) { printf(" %d", root); Preoder(elem, elem[root].left); Preoder(el...
#include <cstdio> #include <iostream> using namespace std; static const int MAX_NUM = 25; static const int NOELEM = -1; struct stNode { int parent; int left; int right; }; void Preoder(stNode elem[], int root) { if (root != NOELEM) { printf(" %d", root); Preoder(elem, elem[root].left); Preoder(el...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
453
6
#include <iostream> using namespace std; struct Node { int p, l, r; }; struct Node T[10000]; int n; //先行順巡回 void preParse(int u) { if (u == -1) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } //中間順巡回 void inParse(int u) { if (u == -1) return; inParse(T[u].l); cout << " " << u...
#include <iostream> using namespace std; struct Node { int p, l, r; }; struct Node T[10000]; int n; //先行順巡回 void preParse(int u) { if (u == -1) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } //中間順巡回 void inParse(int u) { if (u == -1) return; inParse(T[u].l); cout << " " << u...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
364
2
#include <iostream> using namespace std; static const int NIL = -1; struct node { int p; int r; int l; }; node tree[9999]; int depth(int u) { int d = 0; while (tree[u].p != NIL) { u = tree[u].p; d++; } return d; } int printh(int u) { int h1, h2; h1 = h2 = 0; if (tree[u].l != NIL) h1...
#include <iostream> using namespace std; static const int NIL = -1; struct node { int p; int r; int l; }; node tree[9999]; int depth(int u) { int d = 0; while (tree[u].p != NIL) { u = tree[u].p; d++; } return d; } int printh(int u) { int h1, h2; h1 = h2 = 0; if (tree[u].l != NIL) h1...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
732
4
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; struct TNode { int Id; TNode *Parent; TNode *LChild; TNode *RChild; }; //???????????????????????????TNode*???????????????(vector??????????????¢?????????????????????) class TTable { private: vector<TNode *> FNod...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; struct TNode { int Id; TNode *Parent; TNode *LChild; TNode *RChild; }; //???????????????????????????TNode*???????????????(vector??????????????¢?????????????????????) class TTable { private: vector<TNode *> FNod...
[["+", 54, 55, 0, 56, 49, 84, 49, 352, 0, 67]]
1
647
1
// ????????¨????????? #include <cmath> #include <cstdio> #include <iostream> using namespace std; #define MAX 30 #define NIL -1 struct Node { int parent, leftChild, rightSibling; }; Node tree[MAX]; void preorder(int root) { printf(" %d", root); if (tree[root].leftChild != NIL) { preorder(tree[root].leftCh...
// ????????¨????????? #include <cmath> #include <cstdio> #include <iostream> using namespace std; #define MAX 30 #define NIL -1 struct Node { int parent, leftChild, rightSibling; }; Node tree[MAX]; void preorder(int root) { printf(" %d", root); if (tree[root].leftChild != NIL) { preorder(tree[root].leftCh...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
433
4
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define NIL -1 #define N 100005 struct Node { int p, l, r; }; Node T[N]; int n, D[N], H[N]; void preorder(int u) { if (NIL == u) ...
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define NIL -1 #define N 100005 struct Node { int p, l, r; }; Node T[N]; int n, D[N], H[N]; void preorder(int u) { if (NIL == u) ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
401
2
#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 preorder(int u) { if (u == -1) return; printf(" %d", u); preorder(T[u].l); preorder(T[u].r); } void inorder(int u) { if (u == -1...
#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 preorder(int u) { if (u == -1) return; printf(" %d", u); preorder(T[u].l); preorder(T[u].r); } void inorder(int u) { if (u == -1...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
354
6
#include <cstdio> #define MAX 10000 #define NIL -1 using namespace std; struct Node { int p; int l; int r; }; 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...
#include <cstdio> #define MAX 10000 #define NIL -1 using namespace std; struct Node { int p; int l; int r; }; 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...
[["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
1
393
2
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u].l); ...
#include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) return; inParse(T[u].l); ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
364
6
#include <cstdio> #include <iostream> #define MAX 25 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].left); preParse(T[u].right); } void inParse(int u) { if (u == NIL) return; inParse(T[u].left); ...
#include <cstdio> #include <iostream> #define MAX 25 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].left); preParse(T[u].right); } void inParse(int u) { if (u == NIL) return; inParse(T[u].left); ...
[["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
1
419
3
#include <iostream> #include <memory> #include <vector> using namespace std; enum { NA = -1, }; struct node { int id; int l; int r; node() : id(NA), l(NA), r(NA) {} }; inline void show_preorder(vector<node> v, int node_id) { cout << " " << v[node_id].id; if (v[node_id].l != NA) show_preorder(v, v[...
#include <iostream> #include <memory> #include <vector> using namespace std; enum { NA = -1, }; struct node { int id; int l; int r; node() : id(NA), l(NA), r(NA) {} }; inline void show_preorder(vector<node> v, int node_id) { cout << " " << v[node_id].id; if (v[node_id].l != NA) show_preorder(v, v[...
[["-", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2...
1
504
10
#include <cstdio> #include <vector> class Node { public: int id; int left_id; int right_id; int parent_id; Node(); }; Node::Node() { id = -1; left_id = -1; right_id = -1; parent_id = -1; } int search_root(std::vector<Node> &data, int id) { if (data[id].parent_id == -1) { return id; } else {...
#include <cstdio> #include <vector> class Node { public: int id; int left_id; int right_id; int parent_id; Node(); }; Node::Node() { id = -1; left_id = -1; right_id = -1; parent_id = -1; } int search_root(std::vector<Node> &data, int id) { if (data[id].parent_id == -1) { return id; } else {...
[["-", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120]]
1
537
2
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].left); preParse(T[u].right); } void inParse(int u) { if (u == NIL) return; inParse(T[u].left); printf(...
#include <cstdio> #define MAX 10000 #define NIL -1 struct Node { int parent, left, right; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) return; printf(" %d", u); preParse(T[u].left); preParse(T[u].right); } void inParse(int u) { if (u == NIL) return; inParse(T[u].left); printf(...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
386
4
#include <bits/stdc++.h> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p; int left; int right; }; Node tree[MAX]; // int num; void preParse(int); void inParse(int); void postParse(int); int main() { int num; int i, v, left, right, root; cin >> num; for (i = 0; i < num; i++) ...
#include <bits/stdc++.h> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p; int left; int right; }; Node tree[MAX]; // int num; void preParse(int); void inParse(int); void postParse(int); int main() { int num; int i, v, left, right, root; cin >> num; for (i = 0; i < num; i++) ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
398
2
#include <bits/stdc++.h> #define ll long long int #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, n) #define MAX 10000 #define NIL -1 using namespace std; struct Node { int p, l, r; }; struct Node T[MAX]; int n; void preParse(int u) { if (u ...
#include <bits/stdc++.h> #define ll long long int #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, n) #define MAX 10000 #define NIL -1 using namespace std; struct Node { int p, l, r; }; struct Node T[MAX]; int n; void preParse(int u) { if (u ...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
370
6
#include <bits/stdc++.h> using namespace std; #define NIL -1 int n; struct node { int p, l, r; }; node tree[26]; /*先行順巡回*/ void Preorder(int u) { if (u == NIL) return; //左がないので戻る cout << " " << u; Preorder(tree[u].l); Preorder(tree[u].r); } /*中間順巡回*/ void Inorder(int u) { if (u == NIL) return; I...
#include <bits/stdc++.h> using namespace std; #define NIL -1 int n; struct node { int p, l, r; }; node tree[26]; /*先行順巡回*/ void Preorder(int u) { if (u == NIL) return; //左がないので戻る cout << " " << u; Preorder(tree[u].l); Preorder(tree[u].r); } /*中間順巡回*/ void Inorder(int u) { if (u == NIL) return; I...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
367
4
#include <iostream> using namespace std; struct node { int parent, left, right; }; node t[10001]; int n; //ここから先行順巡回 void preparse(int u) { if (u == -1) return; cout << " " << u; preparse(t[u].left); preparse(t[u].right); } //ここから中間順巡回 void inparse(int u) { if (u == -1) return; inparse(t[u].left...
#include <iostream> using namespace std; struct node { int parent, left, right; }; node t[10001]; int n; //ここから先行順巡回 void preparse(int u) { if (u == -1) return; cout << " " << u; preparse(t[u].left); preparse(t[u].right); } //ここから中間順巡回 void inparse(int u) { if (u == -1) return; inparse(t[u].left...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
364
2
#include <cstring> #include <iostream> using namespace std; int pro(int now); int ino(int now); int poo(int now); typedef struct { int p, l, r; } node; int pr[100001], in[100001], po[100001]; node tree[100001]; int main() { cin.tie(0); memset(tree, -1, sizeof(tree)); int n, v, r, l; cin >> n; for (int i = 0...
#include <cstring> #include <iostream> using namespace std; int pro(int now); int ino(int now); int poo(int now); typedef struct { int p, l, r; } node; int pr[100001], in[100001], po[100001]; node tree[100001]; int main() { cin.tie(0); memset(tree, -1, sizeof(tree)); int n, v, r, l; cin >> n; for (int i = 0...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
413
2
#include <iostream> #include <vector> using namespace std; vector<vector<int>> c; void pre(int id) { if (id == -1) return; cout << " " << id; pre(c[id][0]); pre(c[id][1]); } void in(int id) { if (id == -1) return; in(c[id][0]); cout << " " << id; in(c[id][1]); } void post(int id) { if (id ...
#include <iostream> #include <vector> using namespace std; vector<vector<int>> c; void pre(int id) { if (id == -1) return; cout << " " << id; pre(c[id][0]); pre(c[id][1]); } void in(int id) { if (id == -1) return; in(c[id][0]); cout << " " << id; in(c[id][1]); } void post(int id) { if (id ...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
1
359
4
#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]; // void preorder(int u) { cout << " " << u; if (T[u].left != NIL) preorder(T[u].left); if (T[u].right != NIL) preorder(T[u].right)...
#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]; // void preorder(int u) { cout << " " << u; if (T[u].left != NIL) preorder(T[u].left); if (T[u].right != NIL) preorder(T[u].right)...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
384
2
#include <cstdio> #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) { return; } cout << " " << u << flush; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) { re...
#include <cstdio> #include <iostream> using namespace std; #define MAX 10000 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int n; void preParse(int u) { if (u == NIL) { return; } cout << " " << u << flush; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == NIL) { re...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
403
6
#include <algorithm> #include <cstdio> #include <iostream> #include <math.h> #define Lens 250 #define Nil -1 using namespace std; struct Node { int p, l, r; }; int N, sum; Node Tr[Lens]; void maketree() { int m, l, r; for (int i = 0; i < N; i++) { cin >> m >> l >> r; Tr[m].l = l; Tr[l].p = m; ...
#include <algorithm> #include <cstdio> #include <iostream> #include <math.h> #define Lens 250 #define Nil -1 using namespace std; struct Node { int p, l, r; }; int N, sum; Node Tr[Lens]; void maketree() { int m, l, r; for (int i = 0; i < N; i++) { cin >> m >> l >> r; Tr[m].l = l; Tr[l].p = m; ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
387
4
#include <cstdio> #define MAX 10005 #define NIL -1 typedef struct pp { 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(" ...
#include <cstdio> #define MAX 10005 #define NIL -1 typedef struct pp { 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(" ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
386
4
#include <iostream> using namespace std; int nil = -1; struct Node { int p, l, r; }; // pはparent,lはleftchild,rはrightchild Node T[10000]; int n; void preParse(int u) { if (u == nil) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == nil) return; inPa...
#include <iostream> using namespace std; int nil = -1; struct Node { int p, l, r; }; // pはparent,lはleftchild,rはrightchild Node T[10000]; int n; void preParse(int u) { if (u == nil) return; cout << " " << u; preParse(T[u].l); preParse(T[u].r); } void inParse(int u) { if (u == nil) return; inPa...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
362
2
#include <cstdio> #define NIL -1 #define MAX 10000 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 NIL -1 #define MAX 10000 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, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22]]
1
645
4
#include <algorithm> #include <iostream> #include <sstream> #include <vector> using namespace std; struct binarytree { int parent, left, right; }; int order(vector<binarytree> &node, int i, int mode) { int e1, e2; if (mode == 0) cout << " " << i; e1 = node[i].left; if (e1 != -1) order(node, e1, mo...
#include <algorithm> #include <iostream> #include <sstream> #include <vector> using namespace std; struct binarytree { int parent, left, right; }; int order(vector<binarytree> &node, int i, int mode) { int e1, e2; if (mode == 0) cout << " " << i; e1 = node[i].left; if (e1 != -1) order(node, e1, mo...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
389
2
import java.io.*; import java.util.*; public class Main { static int c = 0, H[]; public static void main(String[] args) { Scanner in = new Scanner(System.in); H = new int[2000000]; PrintWriter out = new PrintWriter(System.out); while (true) { String odr = in.next(); if (odr.equals("end...
import java.io.*; import java.util.*; public class Main { static int c = 0, H[]; public static void main(String[] args) { Scanner in = new Scanner(System.in); H = new int[2000000]; PrintWriter out = new PrintWriter(System.out); while (true) { String odr = in.next(); if (odr.equals("en...
[["+", 0, 195, 8, 196, 0, 1, 0, 27, 0, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 27, 0, 68], ["+", 8, 498, 0, 195, 8, 196, 0, 1, 0, 35]]
3
419
3
#include <stdio.h> #include <string.h> #define MAX 2000001 int heap[MAX]; int size; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int parent(int i) { return i / 2; } void maxHeapify(int i) { int l, r, x, largest; l = left(i); r = right(i); if (l <= size && heap[l] > heap[i]) { ...
#include <stdio.h> #include <string.h> #define MAX 2000001 int heap[MAX]; int size; int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } int parent(int i) { return i / 2; } void maxHeapify(int i) { int l, r, x, largest; l = left(i); r = right(i); if (l <= size && heap[l] > heap[i]) { ...
[["-", 0, 52, 15, 23, 0, 16, 31, 16, 12, 13], ["+", 0, 52, 15, 23, 0, 16, 31, 16, 12, 13]]
0
442
2
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL 2000000001 int n = 0; int parent(int i) { return 1 / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void heapIncreaseKey(int *h, int i, int key) { int tmp; h[i] = key; while (i > 1 && h[parent(i)] < h[i]...
#include <stdio.h> #include <stdlib.h> #include <string.h> #define NIL 2000000001 int n = 0; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void heapIncreaseKey(int *h, int i, int key) { int tmp; h[i] = key; while (i > 1 && h[parent(i)] < h[i]...
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 31, 13], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 31, 22]]
0
480
2
#include <limits.h> #include <stdio.h> #define M 500000 int n; int S[M]; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void heapIncreaseKey(int i, int k) { int tmp; if (k < S[i]) { printf("error"); return; } S[i] = k; while (i > 1 && S[...
#include <limits.h> #include <stdio.h> #define M 2000000 int n; int S[M]; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void heapIncreaseKey(int i, int k) { int tmp; if (k < S[i]) { printf("error"); return; } S[i] = k; while (i > 1 && S...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
436
5
#include <stdio.h> #define N 500000000 int n; int p(int i) { return i / 2; } int l(int i) { return 2 * i; } int r(int i) { return 2 * i + 1; } void maxheapify(int h[], int i) { int largest = 0, aa, le, ri; le = l(i); ri = r(i); if (le <= n && h[le] > h[i]) { largest = le; } else { largest = i; }...
#include <stdio.h> #define N 2000000 int n; int p(int i) { return i / 2; } int l(int i) { return 2 * i; } int r(int i) { return 2 * i + 1; } void maxheapify(int h[], int i) { int largest = 0, aa, le, ri; le = l(i); ri = r(i); if (le <= n && h[le] > h[i]) { largest = le; } else { largest = i; } ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
516
2
#include <stdio.h> #include <stdlib.h> #include <string.h> void swap(long *A, long i, long j) { long tmp; tmp = A[i]; A[i] = A[j]; A[j] = tmp; } void up_heap(long *A, long i, long H) { long l, r, largest; if (i <= 0) return; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> void swap(long *A, long i, long j) { long tmp; tmp = A[i]; A[i] = A[j]; A[j] = tmp; } void up_heap(long *A, long i, long H) { long l, r, largest; if (i <= 0) return; l = 2 * i; r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; ...
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
0
436
2
#include <stdio.h> #include <stdlib.h> #include <string.h> int n = 0; void maxHeapify(int node[], int i) { int l = 2 * i; int r = 2 * i + 1; int largest; int temp; if (l <= n && node[l] > node[i]) { largest = l; } else { largest = i; } if (r <= n && node[r] > node[largest]) { largest = r; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> int n = 0; void maxHeapify(int node[], int i) { int l = 2 * i; int r = 2 * i + 1; int largest; int temp; if (l <= n && node[l] > node[i]) { largest = l; } else { largest = i; } if (r <= n && node[r] > node[largest]) { largest = r; ...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
0
492
2
#include <limits.h> #include <stdio.h> #define MAX_H 200000000 int H; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void MaxHeapif(int A[], int i) { int l, r, largest, tmp; l = left(i); r = right(i); if (l <= H && A[l] > A[i]) { largest = l; ...
#include <limits.h> #include <stdio.h> #define MAX_H 2000000 int H; int parent(int i) { return i / 2; } int left(int i) { return 2 * i; } int right(int i) { return 2 * i + 1; } void MaxHeapif(int A[], int i) { int l, r, largest, tmp; l = left(i); r = right(i); if (l <= H && A[l] > A[i]) { largest = l; ...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
525
2
#include <stdio.h> #include <stdlib.h> #define MAX 2000000000 #define nINF -1 int parent(int); int left(int); int right(int); void maxHeapify(int *, int); void buildMaxHeap(int *); void insert(int *, int); void heapIncreaseKey(int *, int); int extractMax(int *); int n = 0; int main() { int *T, key; char func[7]; ...
#include <stdio.h> #include <stdlib.h> #define MAX 2000000 #define nINF -1 int parent(int); int left(int); int right(int); void maxHeapify(int *, int); void buildMaxHeap(int *); void insert(int *, int); void heapIncreaseKey(int *, int); int extractMax(int *); int n = 0; int main() { int *T, key; char func[7]; T =...
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
0
571
2
#include <iostream> #include <queue> #include <string> using namespace std; int main() { string com; priority_queue<int> PQ; while (1) { cin >> com; if (com == "insert") { int key; cin >> key; PQ.push(key); } else if (com == "extract") { cout << PQ.top(); PQ.pop(); ...
#include <iostream> #include <queue> #include <string> using namespace std; int main() { string com; priority_queue<int> PQ; while (1) { cin >> com; if (com == "insert") { int key; cin >> key; PQ.push(key); } else if (com == "extract") { cout << PQ.top() << endl; PQ.po...
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
1
100
2
#include <iostream> #include <queue> #include <string> using namespace std; int main() { string cmd; priority_queue<int> Q; while (cin >> cmd && cmd != "end") { if (cmd == "insert") { int n; cin >> n; Q.push(n); } else if (cmd == "extract") { cout << Q.top(); Q.pop(); } ...
#include <iostream> #include <queue> #include <string> using namespace std; int main() { string cmd; priority_queue<int> Q; while (cin >> cmd && cmd != "end") { if (cmd == "insert") { int n; cin >> n; Q.push(n); } else if (cmd == "extract") { cout << Q.top() << endl; Q.pop();...
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
1
88
2
#include <iostream> #include <string> using namespace std; #define MAX 2000000 #define INFTY (1 << 30) int H, i, A[MAX + 1]; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } void maxHeapify(int i) { int l, r, largest; l = left(i); r = right(i); i...
#include <iostream> #include <string> using namespace std; #define MAX 2000000 #define INFTY (1 << 30) int H, i, A[MAX + 1]; int parent(int i) { return i / 2; } int left(int i) { return i * 2; } int right(int i) { return i * 2 + 1; } void maxHeapify(int i) { int l, r, largest; l = left(i); r = right(i); i...
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13]]
1
395
2
#include <iostream> #include <queue> #include <string> using namespace std; int main(void) { priority_queue<int> queue; string command; int num; while (true) { cin >> command; if (command == "end") { break; } if (command == "extract") { cout << queue.top(); queue.pop(); ...
#include <iostream> #include <queue> #include <string> using namespace std; int main(void) { priority_queue<int> queue; string command; int num; while (true) { cin >> command; if (command == "end") { break; } if (command == "extract") { cout << queue.top() << endl; queue.po...
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
1
92
2
#include <iostream> #include <queue> using namespace std; int main() { priority_queue<int> PQ; char com[20]; while (1) { cin >> com; if (com[0] == 'i') { int key; cin >> key; PQ.push(key); } else if (com[1] == 'x') { cout << PQ.top(); PQ.pop(); } else { ...
#include <iostream> #include <queue> using namespace std; int main() { priority_queue<int> PQ; char com[20]; while (1) { cin >> com; if (com[0] == 'i') { int key; cin >> key; PQ.push(key); } else if (com[1] == 'x') { cout << PQ.top() << "\n"; PQ.pop(); } else ...
[["+", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["+", 64, 9, 0, 1, 0, 16, 12, 5, 0, 44]]
1
99
4
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int INF = 2100000000; class Heap { public: vector<int> a; Heap(int n) { a.resize(n + 1, INF); } int get_parent(int x) { return a[(x) / 2]; } int get_left(int x) { if (x * 2 < a.size() - 1) { return a[x * 2]; ...
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int INF = 2100000000; class Heap { public: vector<int> a; Heap(int n) { a.resize(n + 1, INF); } int get_parent(int x) { return a[(x) / 2]; } int get_left(int x) { if (x * 2 < a.size() - 1) { return a[x * 2]; ...
[["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 45], ["-", 0, 353, 8, 123, 0, 14, 8, 9, 0, 46], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
1
592
6
#include <iostream> using namespace std; int A[2000000], hsize = 0; void insert(int key) { int i = hsize; A[i] = key; hsize++; while (i > 0 && A[i] > A[(i - 1) / 2]) { swap(A[i], A[(i - 1) / 2]); i = (i - 1) / 2; } } void modheap(int i) { int l = i * 2 + 1; int r = i * 2 + 2; int larger = i; ...
#include <iostream> using namespace std; int A[2000000], hsize = 0; void insert(int key) { int i = hsize; A[i] = key; hsize++; while (i > 0 && A[i] > A[(i - 1) / 2]) { swap(A[i], A[(i - 1) / 2]); i = (i - 1) / 2; } } void modheap(int i) { int l = i * 2 + 1; int r = i * 2 + 2; int larger = i; ...
[["+", 0, 14, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
305
3
#include <iostream> using namespace std; #define MAX 2000000 #define INFTY (1 << 30) long long key; int H, A[MAX]; void maxHeapify(int i) { int l = 2 * i, largest; int r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (larg...
#include <iostream> using namespace std; #define MAX 2000000 #define INFTY (1 << 30) long long key; int H, A[MAX]; void maxHeapify(int i) { int l = 2 * i, largest; int r = 2 * i + 1; if (l <= H && A[l] > A[i]) largest = l; else largest = i; if (r <= H && A[r] > A[largest]) largest = r; if (larg...
[["+", 0, 11, 12, 69, 341, 342, 0, 27, 17, 68]]
1
340
1
#define _CRT_SECURE_NO_WARNINGS #include <cassert> #include <cstddef> #include <cstdint> #include <functional> #include <memory> #include <utility> template <class TotallyOrderedSet> class pairing_heap { public: using set_type = TotallyOrderedSet; using value_type = typename set_type::value_type; using const_re...
#define _CRT_SECURE_NO_WARNINGS #include <cassert> #include <cstddef> #include <cstdint> #include <functional> #include <memory> #include <utility> template <class TotallyOrderedSet> class pairing_heap { public: using set_type = TotallyOrderedSet; using value_type = typename set_type::value_type; using const_re...
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 20]]
1
1,017
2
#define _CRT_SECURE_NO_WARNINGS #include <cassert> #include <cstddef> #include <functional> #include <memory> #include <type_traits> #include <utility> template <class TotallyOrderedSet> class pairing_heap { public: using set_type = TotallyOrderedSet; using value_type = typename set_type::value_type; using cons...
#define _CRT_SECURE_NO_WARNINGS #include <cassert> #include <cstddef> #include <functional> #include <memory> #include <type_traits> #include <utility> template <class TotallyOrderedSet> class pairing_heap { public: using set_type = TotallyOrderedSet; using value_type = typename set_type::value_type; using cons...
[["-", 0, 371, 0, 2, 3, 4, 0, 16, 17, 19], ["+", 0, 371, 0, 2, 3, 4, 0, 16, 17, 20], ["-", 0, 14, 8, 9, 0, 37, 0, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 20]]
1
1,043
4
#include <iostream> #include <stdio.h> #include <string> #define MAX 1000000 #define INFTY (1 << 30) int n, H[MAX]; void maxHeap(int i) { int left = i * 2; int right = i * 2 + 1; if (left > n) return; int max = left; if (right <= n) max = H[left] >= H[right] ? left : right; max = H[i] >= H[max]...
#include <iostream> #include <stdio.h> #include <string> #define MAX 100000000 #define INFTY (1 << 30) int n, H[MAX]; void maxHeap(int i) { int left = i * 2; int right = i * 2 + 1; if (left > n) return; int max = left; if (right <= n) max = H[left] >= H[right] ? left : right; max = H[i] >= H[ma...
[["-", 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], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
373
6
#include <algorithm> #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; class Heap { public: Heap() { array = new int[2000000]; n = 0; } void insert(int data) { array[n] = data; int tmp = n; while (tmp != 0 && array[tmp] > array[(tmp - 1) / 2]) { std::swap(a...
#include <algorithm> #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; class Heap { public: Heap() { array = new int[2000000]; n = 0; } void insert(int data) { array[n] = data; int tmp = n; while (tmp != 0 && array[tmp] > array[(tmp - 1) / 2]) { std::swap(a...
[["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
1
386
2