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
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp #partition def partition(target_list): x = target_list[-1] i = -1 for j in range(len(target_list))[:-1]: if target_list[j] <= x: i = i+1 tmp = target_list[i] target_list[i] = target_list...
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp #partition def partition(target_list): x = target_list[-1] i = -1 for j in range(len(target_list))[:-1]: if target_list[j] <= x: i = i+1 tmp = target_list[i] target_list[i] = target_list...
[["+", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
5
199
2
def partition(A, p, r): x = A[r - 1] i = p - 1 for j in range(p, r-1): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r-1] A[r-1] = temp return i if __name__ == '__main__': # ??????????????\???...
def partition(A, p, r): x = A[r - 1] i = p - 1 for j in range(p, r-1): if A[j] <= x: i += 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r-1] A[r-1] = temp return i if __name__ == '__main__': # ??????????????\???...
[["-", 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
220
25
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] < x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 if __name__ == '__main__': N = int(input().strip()) AA = [int(a) for a in input().strip().split()] i...
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 if __name__ == '__main__': N = int(input().strip()) AA = [int(a) for a in input().strip().split()] ...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19]]
5
206
2
def partition(A,p,r): x = A[r] i = p for j in range(p+1,r): if A[j] <= x: A[j],A[i] = A[i],A[j] i += 1 A[r],A[i] = A[i],A[r] return i n = int(input()) A = list(map(int,input().split())) i = partition(A,0,n-1) A[i] = "[{}]".format(A[i]) print(*A)
def partition(A,p,r): x = A[r] i = p for j in range(p,r): if A[j] <= x: A[j],A[i] = A[i],A[j] i += 1 A[r],A[i] = A[i],A[r] return i n = int(input()) A = list(map(int,input().split())) i = partition(A,0,n-1) A[i] = "[{}]".format(A[i]) print(*A)
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
140
2
def partition(A, p, r): x = A[r] i = p-1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 n = int(input()) A = list(map(int, input().split())) i = partition(A, 0, n) A[i] = "["+str(A[i])+"]" print(*A)
def partition(A, p, r): x = A[r] i = p-1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 n = int(input()) A = list(map(int, input().split())) i = partition(A, 0, n-1) A[i] = "["+str(A[i])+"]" print(*A)
[["+", 0, 662, 12, 652, 3, 4, 0, 657, 17, 33], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 12, 612]]
5
148
2
# -*- coding: utf-8 -*- def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i] return i + 1 def main(): n = int(input()) A = [int(e) for e in input().split()] p = 0 ...
# -*- coding: utf-8 -*- def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def main(): n = int(input()) A = [int(e) for e in input().split()] p = 0 ...
[["+", 0, 662, 12, 432, 0, 206, 206, 657, 17, 72], ["+", 0, 662, 12, 432, 0, 206, 206, 657, 12, 612]]
5
176
2
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i = i + 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r] A[r] = temp return i+1 if __name__ == "__main__": n = int(input()) B = li...
def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i = i + 1 temp = A[i] A[i] = A[j] A[j] = temp temp = A[i+1] A[i+1] = A[r] A[r] = temp return i+1 if __name__ == "__main__": n = int(input()) B = li...
[["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["-", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
198
4
n = int(input()) a = list(map(int, input().split())) def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r-1): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 x = partition(a, 0, n-1) for i in range(n): if i == x: ...
n = int(input()) a = list(map(int, input().split())) def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i+1 x = partition(a, 0, n-1) for i in range(n): if i == x: ...
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 33], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
186
2
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def partition(A,p=0, r=None): if r is None: r = len(A)-1 x = A[r] i = p-1 for j in range(p,r): while A[j] <= x: i += 1 swap(A,i,j) swap(A,i+1,r) return i+1 if __name__ == "__main__": input() ...
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def partition(A,p=0, r=None): if r is None: r = len(A)-1 x = A[r] i = p-1 for j in range(p,r): if A[j] <= x: i += 1 swap(A,i,j) swap(A,i+1,r) return i+1 if __name__ == "__main__": input() A ...
[["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121]]
5
187
2
n = int(input()) a = list(map(int,input().split())) x = a[-1] i = -1 for j in range(len(a)-1): if a[j] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i + 1], a[n] = "[" + str(a[n]) + "]", a[i + 1] print(*a)
n = int(input()) a = list(map(int,input().split())) x = a[-1] i = -1 for j in range(len(a)-1): if a[j] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i + 1], a[n - 1] = "[" + str(a[n - 1]) + "]", a[i + 1] print(*a)
[["+", 0, 662, 31, 684, 0, 206, 206, 657, 17, 33], ["+", 0, 662, 31, 684, 0, 206, 206, 657, 12, 612], ["+", 12, 652, 3, 4, 0, 206, 206, 657, 17, 33], ["+", 12, 652, 3, 4, 0, 206, 206, 657, 12, 612]]
5
118
4
def partition(A,p,r): x=A[r] i=p-1 for j in range(p,r): if A[j]<x: i+=1 A[i],A[j]=A[j],A[i] A[i+1],A[r]=A[r],A[i+1] return i+1 n=int(input()) A=list(map(int,input().split())) k=partition(A,0,len(A)-1) front=" ".join(map(str,A[:k])) back=" ".join(map(str,A[k+1:])) ans...
def partition(A,p,r): x=A[r] i=p-1 for j in range(p,r): if A[j]<=x: i+=1 A[i],A[j]=A[j],A[i] A[i+1],A[r]=A[r],A[i+1] return i+1 n=int(input()) A=list(map(int,input().split())) k=partition(A,0,len(A)-1) front=" ".join(map(str,A[:k])) back=" ".join(map(str,A[k+1:])) an...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19]]
5
193
2
n=int(input())-1 A=list(map(int,input().split())) i=0 for j in range(n): if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1 A[i],A[n]=A[n],A[i] print(" ".join(map(str,A[:k]))+" ["+str(A[i])+"] "+" ".join(map(str,A[k+1:])))
n=int(input())-1 A=list(map(int,input().split())) i=0 for j in range(n): if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1 A[i],A[n]=A[n],A[i] print(" ".join(map(str,A[:i]))+" ["+str(A[i])+"] "+" ".join(map(str,A[i+1:])))
[["-", 0, 652, 3, 4, 0, 206, 206, 663, 0, 22], ["+", 0, 652, 3, 4, 0, 206, 206, 663, 0, 22], ["-", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22]]
5
148
19
def partition(array, p, r): x = array[r] i = p-1 for j in range(p, r): if array[j] <= x: i += 1 array[i], array[j] = array[j], array[i] array[i+1], array[r] = array[r], array[i+1] a1 = array[:i+1] a2 = "[" + str(array[i+1]) + "]" a3 = array[i+1:] array = ...
def partition(array, p, r): x = array[r] i = p-1 for j in range(p, r): if array[j] <= x: i += 1 array[i], array[j] = array[j], array[i] array[i+1], array[r] = array[r], array[i+1] a1 = array[:i+1] a2 = "[" + str(array[i+1]) + "]" a3 = array[i+2:] array = ...
[["-", 0, 662, 12, 206, 206, 663, 0, 657, 12, 612], ["+", 0, 662, 12, 206, 206, 663, 0, 657, 12, 612]]
5
183
2
n = int(input()) A = list(map(int, input().split())) def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x : i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 b = partition(A, 0, n-1) A[b] = '[{0}]'.format(b) print(...
n = int(input()) A = list(map(int, input().split())) def partition(A, p, r): x = A[r] i = p - 1 for j in range(p, r): if A[j] <= x : i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 b = partition(A, 0, n-1) A[b] = '[{0}]'.format(A[b]) pri...
[["+", 0, 662, 12, 652, 3, 4, 0, 206, 51, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 206, 0, 70], ["+", 0, 662, 12, 652, 3, 4, 0, 206, 0, 73]]
5
154
3
def partition(A, p, r): x = A[-1] i = p-1 for j in range(p, r): if A[j] < x: i += 1 A[i], A[j] = A[j], A[i] i += 1 A[i], A[r] = A[r], A[i] return i n = eval(input()) x = list(map(int, input().split())) c = partition(x, 0, n-1) for i, e in enumerate(x): ...
def partition(A, p, r): x = A[-1] i = p-1 for j in range(p, r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] i += 1 A[i], A[r] = A[r], A[i] return i n = eval(input()) x = list(map(int, input().split())) c = partition(x, 0, n-1) for i, e in enumerate(x): ...
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19]]
5
167
2
#!/usr/bin/env python from sys import stdin def patition(a, p, r): x = a[r] i = p-1 for j in range(p, r): if a[j] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i+1], a[r] = a[r], a[i+1] return i+1 n = int(stdin.readline()) data = [int(s) for s in stdin.readline().split(...
#!/usr/bin/env python from sys import stdin def patition(a, p, r): x = a[r] i = p-1 for j in range(p, r): if a[j] <= x: i += 1 a[i], a[j] = a[j], a[i] a[i+1], a[r] = a[r], a[i+1] return i+1 n = int(stdin.readline()) data = [int(s) for s in stdin.readline().split(...
[["+", 12, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 652, 3, 4, 0, 206, 0, 70], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 662, 12, 652, 3, 4, 0, 206, 0, 73]]
5
175
5
package main import ( "bufio" "fmt" "os" "strconv" ) type card struct { mark string number int } // return 1 if x > y // return -1 if x < y // return 0 if x == y func compare(x, y card) int { if x.number > y.number { return 1 } else if x.number < y.number { return -1 } else { return 0 } } func isSam...
package main import ( "bufio" "fmt" "os" "strconv" ) type card struct { mark string number int } // return 1 if x > y // return -1 if x < y // return 0 if x == y func compare(x, y card) int { if x.number > y.number { return 1 } else if x.number < y.number { return -1 } else { return 0 } } func isSam...
[["-", 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
747
7
package main import ( "bufio" "fmt" "os" "strconv" ) type card struct { label string value int } // ----- Merge Sort ----- const max = 1000000001 var count = 0 func merge(as []card, bs []card) []card { var result []card as = append(as, card{value: max}) bs = append(bs, card{value: max}) i := 0 j := 0 f...
package main import ( "bufio" "fmt" "os" "strconv" ) type card struct { label string value int } // ----- Merge Sort ----- const max = 1000000001 var count = 0 func merge(as []card, bs []card) []card { var result []card as = append(as, card{value: max}) bs = append(bs, card{value: max}) i := 0 j := 0 f...
[["-", 12, 432, 0, 443, 444, 16, 31, 2, 63, 22], ["-", 0, 443, 444, 16, 31, 2, 3, 4, 0, 24], ["-", 0, 443, 444, 16, 31, 2, 3, 4, 0, 22], ["-", 0, 443, 444, 16, 31, 2, 3, 4, 0, 25], ["-", 0, 431, 12, 432, 0, 443, 444, 16, 17, 33], ["-", 0, 431, 12, 432, 0, 443, 444, 16, 12, 433], ["+", 8, 196, 0, 431, 12, 432, 0, 443, 4...
7
792
7
import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; // ALDS1_6_D public class Main { int binarySearch(int[] array, int n, int min, int max) { if (min > max) return -1; int mid = (max + min) / 2; if (array[mid] == n) return mid; if (arra...
import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; // ALDS1_6_D public class Main { int binarySearch(int[] array, int n, int min, int max) { if (min > max) return -1; int mid = (max + min) / 2; if (array[mid] == n) return mid; if (arra...
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 499], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["+", 64, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 64, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
3
740
6
#include <memory.h> #include <stdio.h> #define MIN(x, y) ((x) <= (y) ? (x) : (y)) int get_uint() { int n = 0; int c = getchar_unlocked(); if (c < 48 || 57 < c) return c; while (47 < c && c < 58) { n = 10 * n + (c & 0xf); c = getchar_unlocked(); } return n; } void put_uint(int n) { if (!n) { ...
#include <memory.h> #include <stdio.h> #define MIN(x, y) ((x) <= (y) ? (x) : (y)) int get_uint() { int n = 0; int c = getchar_unlocked(); if (c < 48 || 57 < c) return c; while (47 < c && c < 58) { n = 10 * n + (c & 0xf); c = getchar_unlocked(); } return n; } void put_uint(int n) { if (!n) { ...
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32]]
0
624
2
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
[["-", 12, 2, 3, 4, 0, 16, 12, 16, 12, 22], ["+", 12, 2, 3, 4, 0, 16, 12, 16, 12, 22]]
1
327
2
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) ...
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) ...
[["+", 12, 2, 3, 4, 0, 16, 31, 16, 12, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72]]
1
762
2
#include <bits/stdc++.h> using namespace std; #define fordebug \ int hoge; \ cin >> hoge; #define DEKAI 1000000007; #define INF 200000000 #define int long long #define lp(i, n) for (int ...
#include <bits/stdc++.h> using namespace std; #define fordebug \ int hoge; \ cin >> hoge; #define DEKAI 1000000007; #define INF 200000000 #define int long long #define lp(i, n) for (int ...
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 17, 48]]
1
333
2
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> #define FOR(i, l, r) for (i = (l); i < r; i++) using namespace std; typedef long long ll; #define MAX_N (1010) #define MAX_V (10010) int n; int A[MAX_N]; int g_min = MAX_V; ...
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> #define FOR(i, l, r) for (i = (l); i < r; i++) using namespace std; typedef long long ll; #define MAX_N (1010) #define MAX_V (10010) int n; int A[MAX_N]; int g_min = MAX_V; ...
[["-", 12, 69, 341, 342, 0, 69, 341, 342, 0, 22], ["+", 12, 69, 341, 342, 0, 69, 341, 342, 0, 22]]
1
375
2
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <vector> #define MAX 1000 #define INF 100000 using namespace std; //[0] = id, [1] = cost int A[MAX][2], SortedA[MAX][2], NumT[MAX]; bool comp[MAX] = {}; vector<int> Typelist[MAX]; int MIN = INF; void sorts(int n) ...
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <vector> #define MAX 1000 #define INF 100000 using namespace std; //[0] = id, [1] = cost int A[MAX][2], SortedA[MAX][2], NumT[MAX]; bool comp[MAX] = {}; vector<int> Typelist[MAX]; int MIN = INF; void sorts(int n) ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
610
2
#include <algorithm> #include <iostream> #include <map> using namespace std; int main() { int n, ans = 0; cin >> n; int arr[n], sorted[n]; bool visit[n] = {false}; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i]; sorted[i] = arr[i]; } sort(sorted, sorted + n); for (int i = 0;...
#include <algorithm> #include <iostream> #include <map> using namespace std; int main() { int n, ans = 0; cin >> n; int arr[n], sorted[n]; bool visit[n] = {false}; map<int, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i]; sorted[i] = arr[i]; } sort(sorted, sorted + n); for (int i = 0;...
[["-", 12, 2, 3, 4, 0, 69, 341, 342, 0, 22], ["+", 12, 2, 3, 4, 0, 69, 341, 342, 0, 22]]
1
363
2
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
[["-", 12, 2, 3, 4, 0, 16, 12, 16, 12, 22], ["+", 12, 2, 3, 4, 0, 16, 12, 16, 12, 22]]
1
315
2
#include <cstdio> #include <vector> using namespace std; #define MIN(a, b) ((a) < (b) ? (a) : (b)) void merge(vector<pair<int, int>> &w, int left, int mid, int right) { vector<pair<int, int>> L, R; int n1 = mid - left; int n2 = right - mid; int i = 0, j = 0, k; L.resize(n1 + 1); R.resize(n2 + 1); for (i...
#include <cstdio> #include <vector> using namespace std; #define MIN(a, b) ((a) < (b) ? (a) : (b)) void merge(vector<pair<int, int>> &w, int left, int mid, int right) { vector<pair<int, int>> L, R; int n1 = mid - left; int n2 = right - mid; int i = 0, j = 0, k; L.resize(n1 + 1); R.resize(n2 + 1); for (i...
[["-", 12, 16, 31, 118, 28, 69, 341, 342, 0, 22], ["+", 12, 16, 31, 118, 28, 69, 341, 342, 0, 13]]
1
607
2
#include <bits/stdc++.h> using namespace std; #define Vi vector<int> #define FOR(i, s, e) for (int i = s; i < e; i++) #define ITER(v) v.begin(), v.end() constexpr int MAX_N = 1000; constexpr int MAX_VAL = 10001; int minCostSort(int *w, int *ref, int n, int minval) { bool isfixed[MAX_N] = {0}; int cost = 0; FO...
#include <bits/stdc++.h> using namespace std; #define Vi vector<int> #define FOR(i, s, e) for (int i = s; i < e; i++) #define ITER(v) v.begin(), v.end() constexpr int MAX_N = 1000; constexpr int MAX_VAL = 10001; int minCostSort(int *w, int *ref, int n, int minval) { bool isfixed[MAX_N] = {0}; int cost = 0; FO...
[["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 25], ["-", 12, 2, 3, 4, 0, 16, 12, 16, 31, 13], ["-", 12, 2, 3, 4, 0, 16, 12, 16, 17, 48]]
1
350
6
#include <algorithm> #include <cassert> #include <climits> #include <fstream> #include <iostream> #include <stdint.h> #include <stdio.h> #include <vector> using namespace std; #define DEBUG (0) #if DEBUG #define DPRINTF(...) \ do { ...
#include <algorithm> #include <cassert> #include <climits> #include <fstream> #include <iostream> #include <stdint.h> #include <stdio.h> #include <vector> using namespace std; #define DEBUG (0) #if DEBUG #define DPRINTF(...) \ do { ...
[["-", 0, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 72], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
953
6
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int parent; int left; int right; } Node; Node T[MAX]; int n; void printChildren(int u) { int c = T[u].left; while (c != NIL) { printf("%d", c); c = T[c].right; if (c != NIL) printf(", "); } } void printLocation(int ...
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int parent; int left; int right; } Node; Node T[MAX]; int n; void printChildren(int u) { int c = T[u].left; while (c != NIL) { printf("%d", c); c = T[c].right; if (c != NIL) printf(", "); } } void printLocation(int ...
[["-", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120], ["+", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
460
8
#include <stdio.h> typedef struct Node { struct Node *parent; struct Node *next; struct Node *son; unsigned int id; } Node; int get_depth(Node *node) { if (node->parent == NULL) return 0; else return get_depth(node->parent) + 1; } int main() { int Node_num; scanf("%d", &Node_num); Node node...
#include <stdio.h> typedef struct Node { struct Node *parent; struct Node *next; struct Node *son; unsigned int id; } Node; int get_depth(Node *node) { if (node->parent == NULL) return 0; else return get_depth(node->parent) + 1; } int main() { int Node_num; scanf("%d", &Node_num); Node node...
[["-", 0, 14, 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, 6], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
0
508
7
#include <stdio.h> #include <stdlib.h> #include <string.h> int depth[100000]; struct node { int parent, child, sibling; }; struct node tree[100000]; void showInfo(int id) { char type[20]; if (tree[id].parent == -1) strcpy(type, "root"); else if (tree[id].child != -1) strcpy(type, "internal node"); ...
#include <stdio.h> #include <stdlib.h> #include <string.h> int depth[100000]; struct node { int parent, child, sibling; }; struct node tree[100000]; void showInfo(int id) { char type[20]; if (tree[id].parent == -1) strcpy(type, "root"); else if (tree[id].child != -1) strcpy(type, "internal node"); ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
0
525
4
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int u) { printf("node %d: ", u); printf("parent = %d, ", T[u].p); printf("depth = %d, ", D[u]); if (T[u].p == NIL) printf("root, "); else if (T[u].l == NIL) printf("le...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int u) { printf("node %d: ", u); printf("parent = %d, ", T[u].p); printf("depth = %d, ", D[u]); if (T[u].p == NIL) printf("root, "); else if (T[u].l == NIL) printf("le...
[["-", 10, 43, 49, 50, 51, 118, 28, 69, 71, 22], ["+", 10, 43, 49, 50, 51, 118, 28, 69, 71, 22], ["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
0
485
6
#include <stdio.h> #include <string.h> #define N 100000 typedef struct { int par, left_child, right_sibling, depth; char status[15]; } Node; Node tree[N]; int n, nchild[N]; char root[N]; void calc_depth(int p, int d) { tree[p].depth = d; if (tree[p].right_sibling != -1) calc_depth(tree[p].right_sibling,...
#include <stdio.h> #include <string.h> #define N 100000 typedef struct { int par, left_child, right_sibling, depth; char status[15]; } Node; Node tree[N]; int n, nchild[N]; char root[N]; void calc_depth(int p, int d) { tree[p].depth = d; if (tree[p].right_sibling != -1) calc_depth(tree[p].right_sibling,...
[["-", 0, 30, 0, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 30, 0, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 30, 0, 9, 0, 1, 0, 11, 12, 13], ["-", 36, 36, 0, 30, 0, 9, 0, 1, 0, 35]]
0
535
4
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int p, l, r; } Node; Node T[MAX]; int depht(int); void print_degree(int); int main() { int n, i, j, node, degree, child, left; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = NIL; T[i].r = NIL; } for (i ...
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int p, l, r; } Node; Node T[MAX]; int depht(int); void print_degree(int); int main() { int n, i, j, node, degree, child, left; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = NIL; T[i].r = NIL; } for (i ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
402
2
#include <stdio.h> #define MAX 100005 #define NIL -1 /* p: parent l: left-child r: right sibling */ struct Node { int p, l, r; }; struct Node T[MAX]; // Tree int dep = 1, m; /*...*/ int depth(int u) { if (T[u].p == NIL) return 0; // printf("%d ",T[u].p); // printf("%d ",T[T[u].p].p); if (T[T[u].p]...
#include <stdio.h> #define MAX 100005 #define NIL -1 /* p: parent l: left-child r: right sibling */ struct Node { int p, l, r; }; struct Node T[MAX]; // Tree int dep = 1, m; /*...*/ int depth(int u) { if (T[u].p == NIL) return 0; // printf("%d ",T[u].p); // printf("%d ",T[T[u].p].p); if (T[T[u].p]...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
589
4
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r, depth; }; struct Node T[MAX]; int flag, k, left; void maketree(int id, int c) { T[c].p = id; if (flag == 0) { T[id].l = c; left = c; } else { T[left].r = c; left = c; } } void print(int u) { if (T[u].p == -1)...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r, depth; }; struct Node T[MAX]; int flag, k, left; void maketree(int id, int c) { T[c].p = id; if (flag == 0) { T[id].l = c; left = c; } else { T[left].r = c; left = c; } } void print(int u) { if (T[u].p == -1)...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
608
2
#include <stdio.h> #define max 100001 #define nil -1 typedef struct { int right; int left; int parent; } Node; Node Tree[max]; int depth[max], length, child[max]; int main() { int i, own, numberchild, j; scanf("%d", &length); for (i = 0; i < length; i++) { Tree[i].parent = nil; Tree[i].right = ...
#include <stdio.h> #define max 100001 #define nil -1 typedef struct { int right; int left; int parent; } Node; Node Tree[max]; int depth[max], length, child[max]; int main() { int i, own, numberchild, j; scanf("%d", &length); for (i = 0; i < length; i++) { Tree[i].parent = nil; Tree[i].right = ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
460
4
#include <stdio.h> #define MAX 100005 typedef struct { int parent, left, right, depth; } Node; Node tree[MAX]; void print(int); void getDepth(void); int n, i; int main(void) { int k, j, rank, c, d, pre; scanf("%d", &n); for (i = 0; i < n; i++) { tree[i].parent = tree[i].left = tree[i].right = -1; }...
#include <stdio.h> #define MAX 100005 typedef struct { int parent, left, right, depth; } Node; Node tree[MAX]; void print(int); void getDepth(void); int n, i; int main(void) { int k, j, rank, c, d, pre; scanf("%d", &n); for (i = 0; i < n; i++) { tree[i].parent = tree[i].left = tree[i].right = -1; }...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
573
4
#include <stdio.h> #define NIL -1 #define N 100006 struct Node { int p, l, r; }; struct Node A[N]; int deep(int); int child(int); main() { int i, j; int n, id, deg, c, k; scanf("%d", &n); for (i = 0; i < n; i++) { A[i].p = NIL; A[i].l = NIL; A[i].r = NIL; } for (i = 0; i < n; i++) { ...
#include <stdio.h> #define NIL -1 #define N 100006 struct Node { int p, l, r; }; struct Node A[N]; int deep(int); int child(int); main() { int i, j; int n, id, deg, c, k; scanf("%d", &n); for (i = 0; i < n; i++) { A[i].p = NIL; A[i].l = NIL; A[i].r = NIL; } 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
429
2
#include <stdio.h> int depth(int); void P(int); struct node { int p, l, r; }; struct node tree[100005]; int n, D[100005]; main(void) { int i, j, d, e, c, l, r; scanf("%d", &n); for (i = 0; i < n; i++) { tree[i].p = tree[i].l = tree[i].r = -1; } for (i = 0; i < n; i++) { scanf("%d %d", &e, &d...
#include <stdio.h> int depth(int); void P(int); struct node { int p, l, r; }; struct node tree[100005]; int n, D[100005]; main(void) { int i, j, d, e, c, l, r; scanf("%d", &n); for (i = 0; i < n; i++) { tree[i].p = tree[i].l = tree[i].r = -1; } for (i = 0; i < n; i++) { scanf("%d %d", &e, &d...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
565
4
#include <stdio.h> typedef struct { int p, l, r; /* parent,left child,right sibling */ } Node; Node T[100000]; int depth(int); int PrintChild(int); void Print(int); int main() { int n, i, j, c, id, k, pre; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = -1; } for (i = 0; i < n; i++...
#include <stdio.h> typedef struct { int p, l, r; /* parent,left child,right sibling */ } Node; Node T[100000]; int depth(int); int PrintChild(int); void Print(int); int main() { int n, i, j, c, id, k, pre; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = -1; } 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
415
2
#include <stdio.h> #define N 100001 typedef struct { int parent; int left; int right; } Node; Node T[N]; int main() { int n, i, j, buf; int id, degree, depth[N]; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].parent = -1; T[i].left = N; T[i].right = N; depth[i] = 0; } for (i = ...
#include <stdio.h> #define N 100001 typedef struct { int parent; int left; int right; } Node; Node T[N]; int main() { int n, i, j, buf; int id, degree, depth[N]; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].parent = -1; T[i].left = N; T[i].right = N; depth[i] = 0; } for (i = ...
[["-", 15, 23, 0, 16, 31, 118, 28, 69, 28, 22], ["-", 15, 23, 0, 16, 31, 118, 28, 69, 0, 70], ["-", 15, 23, 0, 16, 31, 118, 28, 69, 0, 73], ["-", 0, 57, 15, 23, 0, 16, 31, 118, 17, 131], ["-", 0, 57, 15, 23, 0, 16, 31, 118, 119, 120]]
0
546
5
#include <stdio.h> #define N 100000 typedef struct { int parent; int left; int right; } Node; int depth(int); void judgenode(int); void children(int); Node node[N]; main() { int i, j, id, k, n, left, child; scanf("%d", &n); for (i = 0; i < n; i++) { node[i].parent = -1; node[i].left = -1; ...
#include <stdio.h> #define N 100000 typedef struct { int parent; int left; int right; } Node; int depth(int); void judgenode(int); void children(int); Node node[N]; main() { int i, j, id, k, n, left, child; scanf("%d", &n); for (i = 0; i < n; i++) { node[i].parent = -1; node[i].left = -1; ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
477
6
#include <stdio.h> struct intree { int parent; int left; int right; }; int main(void) { int n, i, j, k, id, left, child, depth, key; struct intree list[100000]; scanf("%d", &n); for (i = 0; i < n; i++) { list[i].parent = -1; list[i].left = -1; list[i].right = -1; } for (i = 0; i < n; i...
#include <stdio.h> struct intree { int parent; int left; int right; }; int main(void) { int n, i, j, k, id, left, child, depth, key; struct intree list[100000]; scanf("%d", &n); for (i = 0; i < n; i++) { list[i].parent = -1; list[i].left = -1; list[i].right = -1; } for (i = 0; i < n; i...
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79]]
0
429
2
#include <stdio.h> #include <stdlib.h> #define N 100001 #define NIL -1 typedef struct { int parent; int leftChild; int rightSilbing; } Node; Node node[N]; int depth = 1, n; void initNode(Node *node) { int i; for (i = 0; i < n; i++) { node[i].parent = NIL; node[i].leftChild = NIL; node[i].right...
#include <stdio.h> #include <stdlib.h> #define N 100001 #define NIL -1 typedef struct { int parent; int leftChild; int rightSilbing; } Node; Node node[N]; int depth, n; void initNode(Node *node) { int i; for (i = 0; i < n; i++) { node[i].parent = NIL; node[i].leftChild = NIL; node[i].rightSilb...
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 0, 32], ["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
0
611
6
#include <stdio.h> #define MAX 100005 typedef struct { int p; int l; int r; int depth; } Node; Node np[MAX]; int n, i; void print(int i) { int l; printf("node %d: p = %d, depth = %d, ", i, np[i].p, np[i].depth); if (np[i].p == -1) { if (np[i].l == -1) { printf("root, []\n"); } else { ...
#include <stdio.h> #define MAX 100005 typedef struct { int p; int l; int r; int depth; } Node; Node np[MAX]; int n, i; void print(int i) { int l; printf("node %d: parent = %d, depth = %d, ", i, np[i].p, np[i].depth); if (np[i].p == -1) { if (np[i].l == -1) { printf("root, []\n"); } else ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
565
2
#include <stdio.h> #define N 100001 #define NIL -1 struct Node { int p, l, r; }; struct Node T[N]; int CalcDepth(int id) { if (T[id].p == NIL) return 0; return CalcDepth(T[id].p) + 1; } int main() { int n, i, j, id, k, c, pr; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = N...
#include <stdio.h> #define N 100001 #define NIL -1 struct Node { int p, l, r; }; struct Node T[N]; int CalcDepth(int id) { if (T[id].p == NIL) return 0; return CalcDepth(T[id].p) + 1; } int main() { int n, i, j, id, k, c, pr; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = N...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
407
2
/* * ALDS1_7_A.cpp * * Created on: Apr 30, 2018 * Author: 13743 */ #include <cstdio> struct Node { int pa; int lc; int rs; }; Node tree[100000]; int depth(int u) { int de = 0; while (tree[u].pa != -1) { de++; u = tree[u].pa; } return de; } int main() { int n; scanf("%d", &n); ...
/* * ALDS1_7_A.cpp * * Created on: Apr 30, 2018 * Author: 13743 */ #include <cstdio> struct Node { int pa; int lc; int rs; }; Node tree[100000]; int depth(int u) { int de = 0; while (tree[u].pa != -1) { de++; u = tree[u].pa; } return de; } int main() { int n; scanf("%d", &n); ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
423
2
#include <bits/stdc++.h> using namespace std; typedef struct node_ { int id; int k; vector<node_ *> children; int depth; int parent; } * node; void printTree(vector<node> tree, int n) { for (int i = 0; i < n; i++) { node nd = tree[i]; char *kind = new char[15]; if (nd->parent == -1) { s...
#include <bits/stdc++.h> using namespace std; typedef struct node_ { int id; int k; vector<node_ *> children; int depth; int parent; } * node; void printTree(vector<node> tree, int n) { for (int i = 0; i < n; i++) { node nd = tree[i]; char *kind = new char[15]; if (nd->parent == -1) { s...
[["-", 0, 43, 49, 50, 51, 69, 341, 342, 0, 22], ["+", 0, 43, 49, 50, 51, 69, 341, 342, 0, 22]]
1
583
2
//左子右兄弟表达法 #include <cstdio> #include <iostream> using namespace std; const int maxn = 1e5 + 5; const int NIL = -1; struct node { int p, l, r; }; node t[maxn]; int n, d[maxn]; void print(int u) { int i, c; cout << "node " << u << ": "; cout << "parent = " << t[u].p << ", "; cout << "depth = " << d[u] <<...
//左子右兄弟表达法 #include <cstdio> #include <iostream> using namespace std; const int maxn = 1e5 + 5; const int NIL = -1; struct node { int p, l, r; }; node t[maxn]; int n, d[maxn]; void print(int u) { int i, c; cout << "node " << u << ": "; cout << "parent = " << t[u].p << ", "; cout << "depth = " << d[u] <<...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6]]
1
503
2
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <cmath> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using namespace std; typedef long ...
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <cmath> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using namespace std; typedef long ...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
470
4
#include <iostream> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int D[MAX]; void print(int i) { cout << "node " << i << ": parents = "; cout << T[i].p << ", depth = " << D[i] << ", "; if (T[i].p == NIL) cout << "root"; else if (T[i].l == NIL) cou...
#include <iostream> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; Node T[MAX]; int D[MAX]; void print(int i) { cout << "node " << i << ": parent = "; cout << T[i].p << ", depth = " << D[i] << ", "; if (T[i].p == NIL) cout << "root"; else if (T[i].l == NIL) cout...
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 44], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
453
5
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> #include <vector> long long int INF = 1e18; using namespace std; typedef pair<long long int, long long int> P; vector<int> E[110000]; int parent[11...
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> #include <vector> long long int INF = 1e18; using namespace std; typedef pair<long long int, long long int> P; vector<int> E[110000]; int parent[11...
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
435
2
#include <iostream> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int parent; int leftChild; int rightSibling; }; Node T[MAX]; int D[MAX]; void print(int u) { cout << "node " << u << ": "; cout << "parent = " << T[u].parent << ", "; cout << "depth = " << D[u] << ", "; if (T[u]...
#include <iostream> using namespace std; #define MAX 100005 #define NIL -1 struct Node { int parent; int leftChild; int rightSibling; }; Node T[MAX]; int D[MAX]; void print(int u) { cout << "node " << u << ": "; cout << "parent = " << T[u].parent << ", "; cout << "depth = " << D[u] << ", "; if (T[u]...
[["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40]]
1
486
4
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define LP(i, n) for (int i = 0; i < n; i++) #define Mset(x, v) memset(x, v, sizeof(x...
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define LP(i, n) for (int i = 0; i < n; i++) #define Mset(x, v) memset(x, v, sizeof(x...
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
510
2
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; map<int, string> t; enum NodeType { ROOT = 0, INTERNALNODE = 1, LEAF = 2 }; struct type_name { map<int, string> type_map; type_name() { type_map[ROOT] = "root"; type_map[INTERNALNODE] = "intern...
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; map<int, string> t; enum NodeType { ROOT = 0, INTERNALNODE = 1, LEAF = 2 }; struct type_name { map<int, string> type_map; type_name() { type_map[ROOT] = "root"; type_map[INTERNALNODE] = "intern...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
1
615
2
#include <iostream> #include <vector> using namespace std; #define MAX 100000 int par[MAX]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = -1; } } int depth(int x) { if (par[x] == -1) { return 0; } else { return depth(par[x]) + 1; } } int main() { int n; vector<int> v[MAX]; ...
#include <iostream> #include <vector> using namespace std; #define MAX 100000 int par[MAX]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = -1; } } int depth(int x) { if (par[x] == -1) { return 0; } else { return depth(par[x]) + 1; } } int main() { int n; vector<int> v[MAX]; ...
[["-", 0, 2, 63, 118, 28, 69, 341, 342, 0, 22], ["+", 0, 2, 63, 118, 28, 69, 341, 342, 0, 22]]
1
343
2
#include <algorithm> #include <stdio.h> using namespace std; int main() { int n; scanf("%d", &n); int A[n], B[n], C[n]; for (int i = 0; i < n; i++) scanf("%d", &A[i]); for (int i = 0; i < n; i++) B[i] = A[i]; sort(B, B + n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if...
#include <algorithm> #include <stdio.h> using namespace std; int main() { int n; scanf("%d", &n); int A[n], B[n], C[n]; for (int i = 0; i < n; i++) scanf("%d", &A[i]); for (int i = 0; i < n; i++) B[i] = A[i]; sort(B, B + n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if...
[["+", 12, 16, 12, 23, 0, 16, 12, 69, 28, 22], ["+", 12, 23, 0, 16, 12, 69, 341, 342, 0, 70], ["+", 12, 23, 0, 16, 12, 69, 341, 342, 0, 73]]
1
363
6
#include <algorithm> #include <bitset> #include <stdio.h> #include <utility> using namespace std; typedef pair<int, int> pi; #define F first #define S second #define MP make_pair const int N = 1e3 + 10; bitset<N> went; int bot, tot, a[N], t; pi b[N]; void dfs(int n) { if (went[n]) return; went[n] = true; t++;...
#include <algorithm> #include <bitset> #include <stdio.h> #include <utility> using namespace std; typedef pair<int, int> pi; #define F first #define S second #define MP make_pair const int N = 1e3 + 10; bitset<N> went; int bot, tot, a[N], t; pi b[N]; void dfs(int n) { if (went[n]) return; went[n] = true; t++;...
[["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22]]
1
337
6
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define INTINF 2147483647 #define LLINF 9223372036854775807 #define MAX 1000 #define VMAX 10000 typedef long long ll; using namespace std; int n, A[MAX], s; in...
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define INTINF 2147483647 #define LLINF 9223372036854775807 #define MAX 1000 #define VMAX 10000 typedef long long ll; using namespace std; int n, A[MAX], s; in...
[["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
1
366
3
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int n, A[MAX], s; int B[MAX], T[VMAX + 1]; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++) { B[i] = A[i]; V[i] = false; } sort(B, B + n); for (int i = 0; i...
[["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 22]]
1
321
2
n = gets.chomp.to_i arr = gets.chomp.split.map(&:to_i) t = [] n.times do |i| t << arr.shift end # swap???????????? def swap(list, idx1, idx2) list[idx1], list[idx2] = list[idx2], list[idx1] return list end def minCostPath(list) sorted = list.sort total = 0 # list????????? list.size.times do |i| #...
n = gets.chomp.to_i arr = gets.chomp.split.map(&:to_i) t = [] n.times do |i| t << arr.shift end # swap???????????? def swap(list, idx1, idx2) list[idx1], list[idx2] = list[idx2], list[idx1] return list end def minCostPath(list) sorted = list.sort total = 0 # list????????? list.size.times do |i| #...
[["-", 12, 652, 486, 516, 0, 738, 31, 738, 31, 22], ["+", 12, 652, 486, 516, 0, 738, 31, 738, 31, 22]]
4
182
2
#最小コストソート n = int(input()) a = list(map(int, input().split())) b = sorted(a) c = 0 for i in range(n-1): t = cnt = 0 #本来i番目にいるべき値はaではどこにいるのか(ループの最小値) x = a.index(b[i]) #もしあるべき場所にあったり、あるべき場所に帰ってきたら終了 while x != i: #ループで最も小さい値を使いまわしながら整えていく #ループの最小値が入っている場所にいるべき値がaでは何処にいるか y = ...
#最小コストソート n = int(input()) a = list(map(int, input().split())) b = sorted(a) c = 0 for i in range(n-1): t = cnt = 0 #本来i番目にいるべき値はaではどこにいるのか(ループの最小値) x = a.index(b[i]) #もしあるべき場所にあったり、あるべき場所に帰ってきたら終了 while x != i: #ループで最も小さい値を使いまわしながら整えていく #ループの最小値が入っている場所にいるべき値がaでは何処にいるか y = ...
[["-", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22], ["+", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22]]
5
163
2
#最小コストソート n = int(input()) a = list(map(int, input().split())) b = sorted(a) c = 0 for i in range(n-1): t = cnt = 0 #本来i番目にいるべき値はaではどこにいるのか(ループの最小値) x = a.index(b[i]) #もしあるべき場所にあったり、あるべき場所に帰ってきたら終了 while x != i: #ループで最も小さい値を使いまわしながら整えていく #ループの最小値が入っている場所にいるべき値がaでは何処にいるか y = ...
#最小コストソート n = int(input()) a = list(map(int, input().split())) b = sorted(a) c = 0 for i in range(n-1): t = cnt = 0 x = a.index(b[i]) while x != i: y = a.index(b[x]) a[x],a[y] = a[y],a[x];cnt += 1 t += a[x] + a[y] x = y if cnt: c += min(t, (b[i]+b[0])*2 + t -(b[i]-b[0])*...
[["-", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22], ["+", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22]]
5
163
2
def perfect_swap(): global n, a, b, cost for i in range(1, n - 1): for j in range(i + 1, n): ai, aj = a[i], a[j] if ai == b[j] and aj == b[i]: a[i], a[j] = aj, ai cost += ai + aj def lowest_swap(): global n, a, b, cost for i in range(n - ...
def perfect_swap(): global n, a, b, cost for i in range(1, n - 1): for j in range(i + 1, n): ai, aj = a[i], a[j] if ai == b[j] and aj == b[i]: a[i], a[j] = aj, ai cost += ai + aj def lowest_swap(): global n, a, b, cost for i in range(n - ...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
262
4
def get_weights(): input() return list(map(int, input().split())) #weights: list def minimam_cost_sort(weights): mw = min(weights) s_w = sorted(weights) lol = [] for i in range(len(weights)): if weights[i] != 0: j = weights[i] idx = s_w.index(j) weigh...
def get_weights(): input() return list(map(int, input().split())) #weights: list def minimam_cost_sort(weights): mw = min(weights) s_w = sorted(weights) lol = [] for i in range(len(weights)): if weights[i] != 0: j = weights[i] idx = s_w.index(j) weigh...
[["-", 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
245
4
# -*- coding: utf-8 -*- import copy class BagsWithWeight(list): def __init__(self, l): super(BagsWithWeight, self).__init__(l) self.sorted_weights = list(sorted(self)) def get_lists_of_loop(self): """???????????????????????????????????????????±?????????? ????????\??????????????...
# -*- coding: utf-8 -*- import copy class BagsWithWeight(list): def __init__(self, l): super(BagsWithWeight, self).__init__(l) self.sorted_weights = list(sorted(self)) def get_lists_of_loop(self): """???????????????????????????????????????????±?????????? ????????\??????????????...
[["-", 0, 7, 8, 196, 0, 52, 15, 666, 0, 612], ["+", 8, 196, 0, 52, 15, 666, 0, 664, 17, 33], ["+", 8, 196, 0, 52, 15, 666, 0, 664, 28, 612], ["-", 0, 52, 8, 196, 0, 1, 0, 662, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 664, 17, 33], ["+", 8, 196, 0, 1, 0, 662, 12, 664, 28, 612]]
5
411
6
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def mincost(A): B = sorted(A) cost = 0 for i, bi in enumerate(B): t = 0 j = A.index(bi) tmp_cost = 0 # swap in a cyclic group while j != i: t += 1 bj = B[j] k = ...
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def mincost(A): B = sorted(A) cost = 0 for i, bi in enumerate(B): t = 0 j = A.index(bi) tmp_cost = 0 # swap in a cyclic group while j != i: t += 1 bj = B[j] k = ...
[["-", 0, 662, 12, 657, 12, 23, 0, 657, 31, 22], ["+", 0, 662, 12, 657, 12, 23, 0, 657, 31, 22]]
5
194
20
input() w=list(map(int,input().split())) x=min(w) m={k:v for k,v in zip(sorted(w),w)if k!=v} l=list(m.keys()) p=[] while l: a=l.pop();b=m[a];l.remove(b) if a==m[b]:p+=[[a,b]] else: t=[a,b] while 1: c=m[b];t+=[c] if c==a:p+=[t];break else:b=c;l.remove(c) n=0 for s in p: n+=sum(s);t=len(s);y=min(s) if t...
input() w=list(map(int,input().split())) x=min(w) m={k:v for k,v in zip(sorted(w),w)if k!=v} l=list(m.keys()) p=[] while l: a=l.pop();b=m[a];l.remove(b) if a==m[b]:p+=[[a,b]] else: t=[b] while 1: c=m[b];t+=[c] if c==a:p+=[t];break else:b=c;l.remove(c) n=0 for s in p: n+=sum(s);t=len(s);y=min(s) if t>2...
[["-", 8, 196, 0, 1, 0, 662, 12, 634, 0, 22], ["-", 8, 196, 0, 1, 0, 662, 12, 634, 0, 21]]
5
213
2
n=int(input()) a=list(map(int, input().split())) b=sorted(a) c=0 for i in range(n): x=a.index(b[i]) j=0 while x > i: j+=1 y=a.index(b[x]) c+=a[b] a[x],a[y]=a[y],a[x] x=y c+=min(b[i]*j,b[i]*2+b[0]*(j+2)) print(c)
n=int(input()) a=list(map(int, input().split())) b=sorted(a) c=0 for i in range(n): x=a.index(b[i]) j=0 while x>i: j+=1 y=a.index(b[x]) c+=a[y] a[x],a[y]=a[y],a[x] x=y c+=min(b[i]*j,b[i]*2+b[0]*(j+2)) print(c)
[["-", 8, 196, 0, 1, 0, 677, 12, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 677, 12, 206, 206, 22]]
5
136
2
import copy n = int(input()) a = list(map(int, input().split())) b = copy.deepcopy(a) b.sort() loop = [] minp = min(a) t = [0 for i in range(n)] while True: i = t.index(0) j = len(loop) loop.append([a[i]]) t[i] = 1 while True: i = b.index(a[i]) if t[i] == 1: break ...
import copy n = int(input()) a = list(map(int, input().split())) b = copy.deepcopy(a) b.sort() loop = [] minp = min(a) t = [0 for i in range(n)] while True: i = t.index(0) j = len(loop) loop.append([a[i]]) t[i] = 1 while True: i = b.index(a[i]) if t[i] == 1: break ...
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
224
4
#coding:utf-8 n = int(input()) A = list(map(int, input().split())) B = A[:] B.sort() C = [True for i in range(n)] minA = min(A) j = 0 a = [] total = 0 for i in range(n): circle = [] j = i while C[j]: C[j] = False j = B.index(A[j]) circle.append(A[j]) n_c = len(circle) if n_c...
#coding:utf-8 n = int(input()) A = list(map(int, input().split())) B = A[:] B.sort() C = [True for i in range(n)] minA = min(A) j = 0 a = [] total = 0 for i in range(n): circle = [] j = i while C[j]: C[j] = False j = B.index(A[j]) circle.append(A[j]) n_c = len(circle) if n_c...
[["-", 0, 657, 12, 657, 31, 23, 0, 657, 31, 22], ["+", 0, 657, 12, 657, 31, 23, 0, 657, 31, 22]]
5
189
4
#include <stdio.h> struct Node { int parent; int left; int right; }; int n; struct Node tree[100000]; int dipth[100000]; void getdip(int, int); void printtree(int); int main() { int i, id, j, num, p, l, root; scanf("%d", &n); for (i = 0; i < n; i++) tree[i].parent = tree[i].left = tree[i].right = -1; ...
#include <stdio.h> struct Node { int parent; int left; int right; }; int n; struct Node tree[100000]; int dipth[100000]; void getdip(int, int); void printtree(int); int main() { int i, id, j, num, p, l, root; scanf("%d", &n); for (i = 0; i < n; i++) tree[i].parent = tree[i].left = tree[i].right = -1; ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
468
6
#include <stdio.h> #define NO -1 #define MAX 1000000 typedef struct Node { int p, l, r; } S; S tree[MAX]; int getdepth(int x) { int d = 0; while (tree[x].p != NO) { x = tree[x].p; d++; } return d; } void out(int y) { int i, j; printf("node = %d: ", y); printf("parent = %d, ", tree[y].p); print...
#include <stdio.h> #define NO -1 #define MAX 1000000 typedef struct Node { int p, l, r; } S; S tree[MAX]; int getdepth(int x) { int d = 0; while (tree[x].p != NO) { x = tree[x].p; d++; } return d; } void out(int y) { int i, j; printf("node %d: ", y); printf("parent = %d, ", tree[y].p); printf(...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
411
2
#include <stdio.h> typedef struct { int parent; int left; int right; } DATA; #define MAX 1000000 #define NIL -1 DATA array[MAX]; int main() { int i; int id; int j; int n; int k; int count[100000]; int hukasa = 0; int num; scanf("%d", &n); for (i = 0; i < n; i++) { array[i].parent = N...
#include <stdio.h> typedef struct { int parent; int left; int right; } DATA; #define MAX 1000000 #define NIL -1 DATA array[MAX]; int main() { int i; int id; int j; int n; int k; int count[100000]; int hukasa = 0; int num; scanf("%d", &n); for (i = 0; i < n; i++) { array[i].parent = N...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
514
2
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int p; int l; int r; } Node; int rec(int, int); Node T[MAX]; int n, D[MAX]; int main() { int n, i, j, d, v, c, l, r; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL; for (i = 0; i < n; i++) { scanf...
#include <stdio.h> #define MAX 100005 #define NIL -1 typedef struct { int p; int l; int r; } Node; int rec(int, int); Node T[MAX]; int n, D[MAX]; int main() { int n, i, j, d, v, c, l, r; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL; for (i = 0; i < n; i++) { scanf...
[["-", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
0
477
1
#include <stdio.h> #include <stdlib.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int); int rec(int, int); int main() { int i, j; int d, v, c, l, r; scanf("%d", &n); if (n < 1 || n > 100000) exit(1); for (i = 0; i < n; i++) T[i].p ...
#include <stdio.h> #include <stdlib.h> #define MAX 100005 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int); int rec(int, int); int main() { int i, j; int d, v, c, l, r; scanf("%d", &n); if (n < 1 || n > 100000) exit(1); for (i = 0; i < n; i++) T[i].p ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
527
2
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p; int l; int r; } Tree; Tree T[MAX]; /*??±????????°??????*/ int getDepth(int x) { int dep; while (T[x].p != NIL) { x = T[x].p; dep++; } return dep; } void Print(x) { int a; if (T[x].p == NIL) printf("node %d...
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p; int l; int r; } Tree; Tree T[MAX]; /*??±????????°??????*/ int getDepth(int x) { int dep = 0; while (T[x].p != NIL) { x = T[x].p; dep++; } return dep; } void Print(x) { int a; if (T[x].p == NIL) printf("nod...
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
0
515
2
#include <stdio.h> #define MAX 1000000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int u); int rec(int u, int p); int main() { int i, j, k, l, d, s, c, r; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = NIL; T[i].r = NIL; } ...
#include <stdio.h> #define MAX 1000000 #define NIL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, D[MAX]; void print(int u); int rec(int u, int p); int main() { int i, j, k, l, d, s, c, r; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = NIL; T[i].l = NIL; T[i].r = NIL; } ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
489
2
#include <stdio.h> #define NIL -1 typedef struct { int left, right, parent; } Tree; void setDepth(int, int); int n, depth[100000]; Tree Node[100000]; int main(void) { int i, j, node, parent, child, prev_child; scanf("%d", &n); for (i = 0; i < n; i++) { Node[i].left = NIL; Node[i].right = NIL; Node...
#include <stdio.h> #define NIL -1 typedef struct { int left, right, parent; } Tree; void setDepth(int, int); int n, depth[100000]; Tree Node[100000]; int main(void) { int i, j, node, parent, child, prev_child; scanf("%d", &n); for (i = 0; i < n; i++) { Node[i].left = NIL; Node[i].right = NIL; Node...
[["+", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95]]
0
466
1
#include <stdio.h> #define MAX 100005 int parent[MAX], left[MAX], right[MAX]; int n, D[MAX]; int getDepth(int u) { int d = 0; while (parent[u] != -1) { u = parent[u]; d++; } return d; } void setDepth(int u, int p) { D[u] = p; if (right[u] != -1) { setDepth(right[u], p); } if (left[u] != -1...
#include <stdio.h> #define MAX 100005 int parent[MAX], left[MAX], right[MAX]; int n, D[MAX]; int getDepth(int u) { int d = 0; while (parent[u] != -1) { u = parent[u]; d++; } return d; } void setDepth(int u, int p) { D[u] = p; if (right[u] != -1) { setDepth(right[u], p); } if (left[u] != -1...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
488
2
#include <stdio.h> #include <stdlib.h> #define N 100000 #define NIL -1 struct Node { int parent; int depth; int root; }; struct Node A[N]; int B[N]; void res(int r, int w) { B[r] = w; if (A[r].root != NIL) res(A[r].root, w); if (A[r].depth != NIL) res(A[r].depth, w + 1); } void output(int n) { ...
#include <stdio.h> #include <stdlib.h> #define N 100000 #define NIL -1 struct Node { int parent; int depth; int root; }; struct Node A[N]; int B[N]; void res(int r, int w) { B[r] = w; if (A[r].root != NIL) res(A[r].root, w); if (A[r].depth != NIL) res(A[r].depth, w + 1); } void output(int n) { ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
0
468
2
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, r, l; }; struct Node T[MAX]; int n, D[MAX]; int search(int, int); void print(int); int main() { int i, j, r; int v, d, c, l; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = T[i].r = T[i].l = NIL; for (i = 0; i < n; i++) { sc...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p, r, l; }; struct Node T[MAX]; int n, D[MAX]; int search(int, int); void print(int); int main() { int i, j, r; int v, d, c, l; scanf("%d", &n); for (i = 0; i < n; i++) T[i].p = T[i].r = T[i].l = NIL; for (i = 0; i < n; i++) { sc...
[["-", 0, 14, 8, 9, 0, 57, 64, 37, 0, 38]]
0
499
2
#include <stdio.h> #define MAX 100000 int Parent[MAX]; int Left[MAX]; int Right[MAX]; int D[MAX]; void Depth(int, int); int main() { int i, j; int n = 0; int depth = 0; int id = 0; int k = 0; int c = 0; int lef = 0; scanf("%d", &n); for (i = 0; i < n; i++) { Left[i] = -1; Right[i] = -1; ...
#include <stdio.h> #define MAX 100000 int Parent[MAX]; int Left[MAX]; int Right[MAX]; int D[MAX]; void Depth(int, int); int main() { int i, j; int n = 0; int depth = 0; int id = 0; int k = 0; int c = 0; int lef = 0; scanf("%d", &n); for (i = 0; i < n; i++) { Left[i] = -1; Right[i] = -1; ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
458
2
#include <stdio.h> #define NTL -1 typedef struct tree { int par; int lch; int rbro; } tree; int depth(int, tree *); int type(int, tree *); void cpri(int, tree *); int main() { int n, i, j, now, chi, bchi, num; /*scan n*/ scanf("%d", &n); tree t[n]; /*NTL*/ for (i = 0; i < n; i++) { t[i].par = NTL;...
#include <stdio.h> #define NTL -1 typedef struct tree { int par; int lch; int rbro; } tree; int depth(int, tree *); int type(int, tree *); void cpri(int, tree *); int main() { int n, i, j, now, chi, bchi, num; /*scan n*/ scanf("%d", &n); tree t[n]; /*NTL*/ for (i = 0; i < n; i++) { t[i].par = NTL;...
[["-", 0, 52, 15, 23, 0, 16, 31, 118, 119, 120], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 60], ["+", 0, 52, 15, 23, 0, 16, 31, 118, 119, 120], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["-", 8, 9, 0, 1, 0, 11, 12, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 11, 12, 118, 119, 120]]
0
531
6
#include <stdio.h> #define MAX 100000 typedef struct node { int p; int left; int right; } Node; int D[MAX]; Node node[MAX]; void depth(int, int); int main() { int n, i, num, j, cnum, tmp, l; scanf("%d", &n); for (i = 0; i < n; i++) { node[i].p = -1; node[i].left = -1; node[i].right = -1; } ...
#include <stdio.h> #define MAX 100000 typedef struct node { int p; int left; int right; } Node; int D[MAX]; Node node[MAX]; void depth(int, int); int main() { int n, i, num, j, cnum, tmp, l; scanf("%d", &n); for (i = 0; i < n; i++) { node[i].p = -1; node[i].left = -1; node[i].right = -1; } ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
566
2
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int parent; int left, right; }; struct Node T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d, ", T[u].parent); printf("depth = %d, ", D[u]); if (T[u].parent == NIL) printf("root, "); ...
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int parent; int left, right; }; struct Node T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d, ", T[u].parent); printf("depth = %d, ", D[u]); if (T[u].parent == NIL) printf("root, "); ...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
482
2
#include <stdio.h> #define MAX 1000000 typedef struct { int x, y, z; } Tree; Tree A[MAX]; int Dep(int); main() { int i, j, n, num, deg, c, k = 0; scanf("%d", &n); for (i = 0; i < n; i++) { A[i].x = -1; A[i].y = -1; A[i].z = -1; } for (i = 0; i < n; i++) { scanf("%d%d", &num, &deg...
#include <stdio.h> #define MAX 1000000 typedef struct { int x, y, z; } Tree; Tree A[MAX]; int Dep(int); main() { int i, j, n, num, deg, c, k = 0; scanf("%d", &n); for (i = 0; i < n; i++) { A[i].x = -1; A[i].y = -1; A[i].z = -1; } for (i = 0; i < n; i++) { scanf("%d%d", &num, &deg...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
377
2
#include <stdio.h> #define MAX 10000 typedef struct node { int pare; int left; int right; } Node; Node a[MAX]; int depth[MAX]; void searchdep(int, int); int main() { int n, i, num, sum, j, tmp, k; scanf("%d", &n); for (i = 0; i < n; i++) { a[i].left = -1; a[i].right = -1; a[i].pare = -1; } ...
#include <stdio.h> #define MAX 100000 typedef struct node { int pare; int left; int right; } Node; Node a[MAX]; int depth[MAX]; void searchdep(int, int); int main() { int n, i, num, sum, j, tmp, k; scanf("%d", &n); for (i = 0; i < n; i++) { a[i].left = -1; a[i].right = -1; a[i].pare = -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]]
0
594
4
#include <stdio.h> #include <stdlib.h> struct Tree { int parent; int left; int right; }; struct Tree T[100000]; int D[100000]; int a = 0; void rec(int u, int p) { D[u] = p; if (T[u].right != -1) rec(T[u].right, p); if (T[u].left != -1) rec(T[u].left, p + 1); } int main() { int n, i, j, d, v, c...
#include <stdio.h> #include <stdlib.h> struct Tree { int parent; int left; int right; }; struct Tree T[100000]; int D[100000]; int a = 0; void rec(int u, int p) { D[u] = p; if (T[u].right != -1) rec(T[u].right, p); if (T[u].left != -1) rec(T[u].left, p + 1); } int main() { int n, i, j, d, v, c...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
488
2
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p; int l; int r; } Node; Node T[MAX]; int n, D[MAX]; //深さを代入 void print(int node_num) { int i, c, flag = 1; printf("node %d: ", node_num); //引数の番号 printf("parent = %d, ", T[node_num].p); //引数ノードの親 printf("depth = %d, ", D...
#include <stdio.h> #define MAX 100000 #define NIL -1 typedef struct { int p; int l; int r; } Node; Node T[MAX]; int n, D[MAX]; //深さを代入 void print(int node_num) { int i, c, flag = 1; printf("node %d: ", node_num); //引数の番号 printf("parent = %d, ", T[node_num].p); //引数ノードの親 printf("depth = %d, ", D...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
522
2
#include <stdio.h> #define max 100000 #define NIL -1 typedef struct { int parent; int left; int right; } node; node T[max]; int n, D[max]; void print(int); void rec(int, int); int main() { int i, j, k, d, v, c, l, r, id; 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 typedef struct { int parent; int left; int right; } node; node T[max]; int n, D[max]; void print(int); void rec(int, int); int main() { int i, j, k, d, v, c, l, r, id; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].parent = NIL; T[i].left = ...
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 69, 71, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
505
4
#include <stdio.h> #define MAX 100000 int confirm_depth(int); struct Node // This variable is used only confirm the node is root,internal,or // leaf. { int parent, left, right; }; /* struct insert //This variable is used to remember how many children the node has. { int id,number_of_children; }; */ ...
#include <stdio.h> #define MAX 100000 int confirm_depth(int); struct Node // This variable is used only confirm the node is root,internal,or // leaf. { int parent, left, right; }; /* struct insert //This variable is used to remember how many children the node has. { int id,number_of_children; }; */ ...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
500
6
#include <stdio.h> #define MAX 100005 #define NTL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, H, D[MAX]; int main() { int i, j, d, v, c, l; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = NTL; } for (i = 0; i < n; i++) { scanf("%d %d", &v, &d); for (j ...
#include <stdio.h> #define MAX 100005 #define NTL -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, H, D[MAX]; int main() { int i, j, d, v, c, l; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = NTL; } for (i = 0; i < n; i++) { scanf("%d %d", &v, &d); for (j ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
0
462
2
#include <stdio.h> #define MAX 100005 #define NOT -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, H, A[MAX]; int getDepth(int); void Print(int); int main() { int i, j, k, l, v, c; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = NOT; } for (i = 0; i < n; i++) { s...
#include <stdio.h> #define MAX 100005 #define NOT -1 struct Node { int p, l, r; }; struct Node T[MAX]; int n, H, A[MAX]; int getDepth(int); void Print(int); int main() { int i, j, k, l, v, c; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].p = T[i].l = T[i].r = NOT; } for (i = 0; i < n; i++) { s...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
478
4
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int p, q, r; }; struct Node T[MAX]; int n, m, D[MAX]; int getdepth(int u) { int d = 0; while (T[u].p != NIL) { u = T[u].p; d++; } return d; } void print(int u) { int i, A; printf("node %d: parent = %d, depth = %d, ", u, T[u]....
#include <stdio.h> #define MAX 100000 #define NIL -1 struct Node { int p, q, r; }; struct Node T[MAX]; int n, m, D[MAX]; int getdepth(int u) { int d = 0; while (T[u].p != NIL) { u = T[u].p; d++; } return d; } void print(int u) { int i, A; printf("node %d: parent = %d, depth = %d, ", u, T[u]....
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
0
467
2
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int l; int r; int d; } Node; Node Tree[100001]; int dep; int getDep(int ppp) { if (Tree[ppp].parent == -1) return 0; dep = getDep(Tree[ppp].parent) + 1; return dep; } void scan(int n) { int id, number; int p1, p2; for (int i...
#include <stdio.h> #include <stdlib.h> typedef struct { int parent; int l; int r; int d; } Node; Node Tree[100001]; int dep; int getDep(int ppp) { if (Tree[ppp].parent == -1) return 0; dep = getDep(Tree[ppp].parent) + 1; return dep; } void scan(int n) { int id, number; int p1, p2; for (int i...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 75, 76, 0, 57, 75, 76, 0, 9, 0, 46], ["-", 75, 76, 0, 57, 75, 76, 0, 9, 0, 46]]
0
496
8
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p; int l; int r; } Node, T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d, ", T[u].p); printf("depth = %d,", D[u]); if (T[u].p == NIL) printf(" root, "); else if (T[...
#include <stdio.h> #define MAX 100005 #define NIL -1 struct Node { int p; int l; int r; } Node, T[MAX]; int n, D[MAX]; void print(int u) { int i, c; printf("node %d: ", u); printf("parent = %d, ", T[u].p); printf("depth = %d,", D[u]); if (T[u].p == NIL) printf(" root, "); else if (T[...
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 14, 39, 40]]
0
485
6