s_id
string
p_id
string
u_id
string
date
string
language
string
original_language
string
filename_ext
string
status
string
cpu_time
string
memory
string
code_size
string
code
string
error
string
stdout
string
s755097651
p02277
u313994256
1442583732
Python
Python
py
Runtime Error
0
0
1519
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 1000000000000000000000000000000000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] return i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("NOt stable") print " \n".join(num_list)
File "/tmp/tmps5lgk1ln/tmp4w7lqj7q.py", line 77 print " \n".join(num_list) ^ IndentationError: unindent does not match any outer indentation level
s960104671
p02277
u313994256
1442584006
Python
Python
py
Runtime Error
0
0
1491
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 100000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] return i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("NOt stable") print " \n".join(num_list)
File "/tmp/tmpp9b5hnpb/tmpqds_tg7f.py", line 77 print " \n".join(num_list) ^ IndentationError: unindent does not match any outer indentation level
s076138227
p02277
u313994256
1442584101
Python
Python
py
Runtime Error
0
0
1490
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 100000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] return i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("Not stable") print "\n".join(num_list)
File "/tmp/tmps8e9rk1r/tmp0hq1wo1a.py", line 77 print "\n".join(num_list) ^ IndentationError: unindent does not match any outer indentation level
s761710190
p02277
u313994256
1442755215
Python
Python
py
Runtime Error
0
0
1531
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 100000000000000000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] retu rn i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) print " \n".join(num_list) mergesort(num_list1, 0, len(num_list1)) print "\n".join(num_list1) if num_list == num_list1: print ("Stable") else:c print ("NOt stable")
File "/tmp/tmpsbalz7wk/tmp7sl8cm7l.py", line 49 rn i+1 ^ SyntaxError: invalid syntax
s239685672
p02277
u313994256
1442755272
Python
Python
py
Runtime Error
0
0
1531
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 100000000000000000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] retu rn i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) print " \n".join(num_list) mergesort(num_list1, 0, len(num_list1)) print "\n".join(num_list1) if num_list == num_list1: print ("Stable") else:c print ("Not stable")
File "/tmp/tmpxwd9_seb/tmp09lbu_kq.py", line 49 rn i+1 ^ SyntaxError: invalid syntax
s389442742
p02277
u313994256
1442755317
Python
Python
py
Runtime Error
0
0
1532
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 100000000000000000000000000000000] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if int(L[i][-1]) <= int(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 # kannsei def partition(A, p, r): x = int(A[r-1][2]) i = p - 1 for j in range(p, r-1): if int(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] retu rn i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) print " \n".join(num_list) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else:c print ("Not stable") print "\n".join(num_list1)
File "/tmp/tmpcatp8i0o/tmpz61c3zyp.py", line 49 rn i+1 ^ SyntaxError: invalid syntax
s508357251
p02277
u313994256
1442761751
Python
Python
py
Runtime Error
0
0
1499
def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", float("inf")] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if float(L[i][-1]) <= float(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 def partition(A, p, r): x = float(A[r-1][2]) i = p - 1 for j in range(p, r): if float(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r-1]=A[r-1], A[i+1] return i+1 def quicksort(A, p, r): if p < r-1: q = partition(A, p, r) quicksort(A, p, q) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("Not stable") print "\n".join(num_list)
File "/tmp/tmpzpcwis1c/tmpel397xxi.py", line 71 print "\n".join(num_list) ^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s505383031
p02277
u313994256
1442762617
Python
Python
py
Runtime Error
0
0
1506
#????????? def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", float("inf")] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if float(L[i][-1]) <= float(R[j][-1]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 def partition(A, p, r): x = float(A[r][2]) i = p - 1 for j in range(p, r): if float(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r]=A[r], A[i+1] return i+1 def quicksort(A, p, r): if p < r: q = partition(A, p, r) quicksort(A, p, q-1) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)-1) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("Not stable") print "\n".join(num_list)
File "/tmp/tmp04x_9rq4/tmpztj2j5ob.py", line 72 print "\n".join(num_list) ^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s452327356
p02277
u313994256
1442795581
Python
Python
py
Runtime Error
0
0
1498
#????????? def mergesort(A, left, right): if left + 1 < right: mid = (left + right)/2 mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid -left n2 = right - mid L = [] R = [] x = [" "," ", 10**10] for i in range(0, n1): L.append(A[left + i]) for i in range(0, n2): R.append(A[mid + i]) L.append(x) R.append(x) i = 0 j = 0 for k in range(left, right): if float(L[i]) <= float(R[j]): A[k] = L[i] i = i + 1 else: A[k] = R[j] j = j + 1 def partition(A, p, r): x = float(A[r][2]) i = p - 1 for j in range(p, r): if float(A[j][2]) <= x: i = i + 1 A[i],A[j]=A[j], A[i] A[i+1], A[r]=A[r], A[i+1] return i+1 def quicksort(A, p, r): if p < r: q = partition(A, p, r) quicksort(A, p, q-1) quicksort(A, q+1, r) if __name__ == "__main__": num = int(raw_input()) num_list = [] num_list1 = [] for i in range(num): num_list.append(raw_input()) num_list1 = list(num_list) quicksort(num_list, 0, len(num_list)-1) mergesort(num_list1, 0, len(num_list1)) if num_list == num_list1: print ("Stable") else: print ("Not stable") print "\n".join(num_list)
File "/tmp/tmpnr5_airb/tmpeg1iq4v0.py", line 73 print "\n".join(num_list) ^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s809966355
p02277
u731710433
1455975495
Python
Python3
py
Runtime Error
20
7812
918
def partition(A, p, r): x = A[r][1] i = p-1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quicksort(A, p, r): if p < r: q = partition(A, p, r) quicksort(A, p, q-1) quicksort(A, q+1, r) def suitlist(cards): suits = [[]]*len(cards) for card in cards: suits[int(card[1])].append(card[0]) return suits def is_stable(before, after): suits_b = suitlist(before) suits_a = suitlist(after) for a, b in zip(suits_b, suits_a): if a != b: return False return True n = int(input()) cards = [] origin = cards.copy() for _ in range(n): cards.append(input().split()) origin = cards.copy() quicksort(cards, 0, n - 1) print("Stable" if is_stable(origin, cards) else "Not stable") for card in cards: print(*card)
Traceback (most recent call last): File "/tmp/tmpdnwk06c4/tmpj47qza73.py", line 35, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s717670848
p02277
u742013327
1478604971
Python
Python3
py
Runtime Error
0
0
1421
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=jp def partition(target_list, l, r): x = int(target_list[r][1:]) i = l - 1 for j in range(l, r): if int(target_list[j][1:]) <= x: i = i + 1 tmp = target_list[i] target_list[i] = target_list[j] target_list[j] = tmp tmp = target_list[r] target_list[r] = target_list[i + 1] target_list[i + 1] = tmp return i + 1 def check_stable(origin_list, target_list): for i, origin_v in enumerate(origin_list.split()): for origin_v2 in origin_list[i+1:]: if origin_v[1] == origin_v2[1]: for j, target_v in enumerate(target_list.split()): for target_v2 in target_list[j+1:]: if origin_v == target_v2 and origin_v2 == target_v: return "Not stable" return "Stable" def quick_sort(target_list, l, r): if l < r: c = partition(target_list, l, r) quick_sort(target_list, l, c - 1) quick_sort(target_list, c + 1, r) if __name__ == "__main__": n_list = int(input()) target_list = [] for i in range(n_list): target_list.append(input()) origin_list = [a for a in target_list] quick_sort(target_list, 0, n_list - 1) print(check_stable(origin_list, target_list)) print("\n".join(target_list))
Traceback (most recent call last): File "/tmp/tmpli99vuyf/tmpgbu1jjbd.py", line 36, in <module> n_list = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s433995968
p02277
u742013327
1478605012
Python
Python3
py
Runtime Error
0
0
1437
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=jp def partition(target_list, l, r): x = int(target_list[r][1:]) i = l - 1 for j in range(l, r): if int(target_list[j][1:]) <= x: i = i + 1 tmp = target_list[i] target_list[i] = target_list[j] target_list[j] = tmp tmp = target_list[r] target_list[r] = target_list[i + 1] target_list[i + 1] = tmp return i + 1 def check_stable(origin_list, target_list): for i, origin_v in enumerate(origin_list.split()): for origin_v2 in origin_list[i+1:].split(): if origin_v[1] == origin_v2[1]: for j, target_v in enumerate(target_list.split()): for target_v2 in target_list[j+1:].split(): if origin_v == target_v2 and origin_v2 == target_v: return "Not stable" return "Stable" def quick_sort(target_list, l, r): if l < r: c = partition(target_list, l, r) quick_sort(target_list, l, c - 1) quick_sort(target_list, c + 1, r) if __name__ == "__main__": n_list = int(input()) target_list = [] for i in range(n_list): target_list.append(input()) origin_list = [a for a in target_list] quick_sort(target_list, 0, n_list - 1) print(check_stable(origin_list, target_list)) print("\n".join(target_list))
Traceback (most recent call last): File "/tmp/tmp6kntjrl1/tmpfehftj7i.py", line 36, in <module> n_list = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s894782368
p02277
u022407960
1478848723
Python
Python3
py
Runtime Error
0
0
1855
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Input: 6 D 3 H 2 D 1 S 3 D 2 C 1 Output: Not stable / Stable D 1 C 1 D 2 H 2 D 3 S 3 """ import sys import copy def partition(array, start, end): x = int(array[end][2:]) i = start - 1 assert start <= end for j in range(start, end): if int(array[j][2:]) <= x: i += 1 array[i], array[j] = array[j], array[i] array[i + 1], array[end] = array[end], array[i + 1] return i + 1 def quick_sort(array, start, end): if start + 1 < end: cursor = partition(array, start, end) quick_sort(array, start, cursor - 1) quick_sort(array, cursor + 1, end) return array def merge(A, left, mid, right): L = A[left:mid] + ['N ' + str(int(1e9 + 1))] R = A[mid:right] + ['N ' + str(int(1e9 + 1))] i, j = 0, 0 for k in range(left, right): if int(L[i][2:]) <= int(R[j][2:]): A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return None def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) return A if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(lambda x: x.strip('\n'), _input[1:])) assert len(array) == array_length merge_array = copy.deepcopy(array) # print('merge',merge_array) merge_result = merge_sort(A=merge_array, left=0, right=array_length) # print(*merge_result, sep='\n') # print('quick',array) quick_result = quick_sort(array=array, start=0, end=array_length) if quick_result != merge_result: print('Not stable') else: print('Stable') print(*quick_result, sep='\n')
Traceback (most recent call last): File "/tmp/tmpd4w8s0d5/tmpeabtomwz.py", line 75, in <module> array_length = int(_input[0]) ~~~~~~^^^ IndexError: list index out of range
s690557776
p02277
u811733736
1480892093
Python
Python3
py
Runtime Error
20
7876
2044
def merge_sort(A, left, right): if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = A[left:mid] R = A[mid:right] L.append(('J', 99)) R.append(('J', 99)) i = 0 # L[]??¨????????????????????? j = 0 # R[]??¨????????????????????? for k in range(left, right): if L[i][1] <= R[j][1]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def partition(A, p, r): """ ???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨??? """ x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: 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 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) quick_sort(A, p, q-1) quick_sort(A, q+1, r) if __name__ == '__main__': # ??????????????\??? #cards = [('D', 3), ('H', 2), ('D', 1), ('S', 3), ('D', 2), ('C', 1)] #comp_cards = cards[:] num_of_cards = int(input()) cards = [] for i in range(num_of_cards): suit, rank = input().split(' ') cards.append((suit, int(rank))) comp_cards = cards[:] # ?????????????????? data_length = len(cards) quick_sort(cards, 0, data_length-1) merge_sort(comp_cards, 0, data_length) # ?????????????????????????????????????????¨ # ??????????????? stable = True # ????????????????????????????????????????????? for x, y in zip(cards, comp_cards): if x != y: stable = False print('Not stable') break if stable is True: print('Stable') for c in cards: # ??????????????¨??? print('{0} {1}'.format(c[0], c[1]))
Traceback (most recent call last): File "/tmp/tmpdf5d9_ob/tmpvrguvm2u.py", line 56, in <module> num_of_cards = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s537923096
p02277
u512342660
1484106313
Python
Python
py
Runtime Error
0
0
1747
def partition(A,B,p,r): x = A[r] i = p-1 for j in xrange(p,r): if A[j] <= x: i += 1 tmp = A[i] A[i] = A[j] A[j] = tmp tmp = B[i] B[i] = B[j] B[j] = tmp tmp = A[i+1] A[i+1] = A[r] A[r] = tmp tmp = B[i+1] B[i+1] = B[r] B[r] = tmp return i+1 def quick_sort(A,B, p, r): # q??????????????????p??¨r????????????????????°??????????????§??? # ?????????p?????????q-1???????????§???????????????????????????q+1???r????¶??????? # ?????§??????????????§????????????????????¨????????? if p < r: # ???????????£?????§?????????????°??????°????????? q = partition(A,B,p,r) quick_sort(A,B,p,q-1) quick_sort(A,B,q+1,r) def stable_check(sorted_values,sorted_suits,default_values,default_suits,n): for i in xrange(1,10): check_ss = [] check_ds = [] if i in sorted_values: for x in xrange(n): if i == sorted_values[x]: check_ss.append(sorted_suits[x]) if i == default_values[x]: check_ds.append(default_suits[x]) for x in xrange(len(check_ss)): if check_ss[x]!=check_ds[x]: return "Not stable" return "Stable" def main(): n = input() A = [] B = [] for i in xrange(n): b,a = raw_input().split() A.append(int(a)) B.append(b) cpA=list(A) setA = set(A) cpB=list(B) quick_sort(A,B,0,n-1) # Stable Check print stable_check(A,B,cpA,cpB,n) for i in xrange(n): line = "%s %s"%(B[i],A[i]) print line if __name__ == '__main__': main()
File "/tmp/tmppzvwgn12/tmpd_tm6w26.py", line 60 print stable_check(A,B,cpA,cpB,n) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s604361014
p02277
u564398841
1486271349
Python
Python3
py
Runtime Error
0
0
1269
def mergesort(A, s, e): if s + 1 < e: m = (e + s) // 2 mergesort(A, s, m) mergesort(A, m, e) merge(A, s, m, e) def merge(A, s, m, e): L = A[s:m] + [('*', 1E10)] R = A[m:e] + [('*', 1E10)] ix_l = ix_r = 0 for ix in range(s, e): if L[ix_l][1] < R[ix_r][1]: A[ix] = L[ix_l] ix_l += 1 else: A[ix] = R[ix_r] ix_r += 1 def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quicksort(A, p, r): if p < r: i = partition(A, p, r) quicksort(A, p, i - 1) quicksort(A, i + 1, r) fin = open('sample.txt') input = fin.readline if __name__ == '__main__': N = int(input().strip()) AA = [0] * N for i in range(N): key, val = input().strip().split() val = int(val) AA[i] = (key, val) AA2 = AA quicksort(AA, 0, len(AA) - 1) mergesort(AA2, 0, len(AA2)) if all([a == 2 for a, a2 in zip(AA, AA2)]): print('Stable') else: print('Not stable') for key, val in AA: print('{} {}'.format(key, val))
Traceback (most recent call last): File "/tmp/tmpbh7cfdga/tmpz7yehqax.py", line 40, in <module> fin = open('sample.txt') ^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'sample.txt'
s360806683
p02277
u564398841
1486271489
Python
Python3
py
Runtime Error
0
0
1273
def mergesort(A, s, e): if s + 1 < e: m = (e + s) // 2 mergesort(A, s, m) mergesort(A, m, e) merge(A, s, m, e) def merge(A, s, m, e): L = A[s:m] + [('*', 1E10)] R = A[m:e] + [('*', 1E10)] ix_l = ix_r = 0 for ix in range(s, e): if L[ix_l][1] < R[ix_r][1]: A[ix] = L[ix_l] ix_l += 1 else: A[ix] = R[ix_r] ix_r += 1 def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quicksort(A, p, r): if p < r: i = partition(A, p, r) quicksort(A, p, i - 1) quicksort(A, i + 1, r) fin = open('sample.txt') input = fin.readline if __name__ == '__main__': N = int(input().strip()) AA = [0] * N for i in range(N): key, val = input().strip().split() val = int(val) AA[i] = (key, val) AA2 = AA[:] quicksort(AA, 0, len(AA) - 1) mergesort(AA2, 0, len(AA2)) if all([a == a2 for a, a2 in zip(AA, AA2)]): print('Stable') else: print('Not stable') for key, val in AA: print('{} {}'.format(key, val))
Traceback (most recent call last): File "/tmp/tmp3668g2sa/tmp2nhdi8ki.py", line 40, in <module> fin = open('sample.txt') ^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'sample.txt'
s369710370
p02277
u918276501
1507982244
Python
Python3
py
Runtime Error
0
0
937
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def isStable(A): for i in range(1, len(A)): if A[i][1] == A[i-1][1]: if A[i][2] < A[i-1][2]: return False return True 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 def quick(A,p=0,r=None): if r is None: r = len(A)-1 if p < r: q = partition(A,p,r) quick(A,p,q-1) quick(A,q+1,r) import sys if __name__ == "__main__": n = int(sys.stdin.readline()) A = [] for i in range(n): card = sys.stdin.readline().split() A.append(int(card[1]), [card[0], i]) quick(A,0,n-1) if isStable(A): print("Stable") else: print("Not stable") for card in A: print(card[1], card[0])
File "/tmp/tmpd3wmy1xs/tmpfsmj4y8a.py", line 38 A.append(int(card[1]), [card[0], i]) ^ IndentationError: unindent does not match any outer indentation level
s906880370
p02277
u918276501
1507982262
Python
Python3
py
Runtime Error
0
0
937
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def isStable(A): for i in range(1, len(A)): if A[i][1] == A[i-1][1]: if A[i][2] < A[i-1][2]: return False return True 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 def quick(A,p=0,r=None): if r is None: r = len(A)-1 if p < r: q = partition(A,p,r) quick(A,p,q-1) quick(A,q+1,r) import sys if __name__ == "__main__": n = int(sys.stdin.readline()) A = [] for i in range(n): card = sys.stdin.readline().split() A.append([int(card[1]), card[0], i]) quick(A,0,n-1) if isStable(A): print("Stable") else: print("Not stable") for card in A: print(card[1], card[0])
File "/tmp/tmpmxz96wn4/tmpk_2rg1n1.py", line 38 A.append([int(card[1]), card[0], i]) ^ IndentationError: unindent does not match any outer indentation level
s184233842
p02277
u918276501
1507982383
Python
Python3
py
Runtime Error
0
0
943
def swap(A,i,j): A[i],A[j] = A[j],A[i] return A def isStable(A): for i in range(1, len(A)): if A[i][1] == A[i-1][1]: if A[i][2] < A[i-1][2]: return False return True 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][1] <= x[1]: i += 1 swap(A,i,j) swap(A,i+1,r) return i+1 def quick(A,p=0,r=None): if r is None: r = len(A)-1 if p < r: q = partition(A,p,r) quick(A,p,q-1) quick(A,q+1,r) import sys if __name__ == "__main__": n = int(sys.stdin.readline()) A = [] for i in range(n): card = sys.stdin.readline().split() A.append([card[0], int(card[1]), i]) quick(A,0,n-1) if isStable(A): print("Stable") else: print("Not stable") for card in A: print(card[0], card[1])
File "/tmp/tmp_xgt5d03/tmpw0xke3nw.py", line 38 A.append([card[0], int(card[1]), i]) ^ IndentationError: unindent does not match any outer indentation level
s431487359
p02277
u426534722
1517237990
Python
Python3
py
Runtime Error
0
0
775
import sys readline = sys.stdin.readline def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quicksort(A, p, r): if p < r: q = partition(A, p, r) quicksort(A, p, q - 1) quicksort(A, q + 1, r) def isStable(A): for i in range(0, len(A) - 1): if A[i][1] == A[i + 1][1]: if A[i][2] > A[i + 1][2]: return False return True n = int(input()) f = lambda a: (a[0], int(a[1])) A = [f(readline().split()) + (i) for i in range(n)] quicksort(A, 0, n - 1) print("Stable" if isStable(A) else "Not stable") print("\n".join(f"{a} {b}" for a, b, c in A))
Traceback (most recent call last): File "/tmp/tmp1wdzbf58/tmpprno7ak5.py", line 23, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s957918720
p02277
u177808190
1518527491
Python
Python3
py
Runtime Error
20
5620
1092
def partition(hoge, p, r): x = int(hoge[r-1][1]) i = p-1 for j in range(p, len(hoge)): if int(hoge[j][1]) <= x: i += 1 tmp = hoge[i] hoge[i] = hoge[j] hoge[j] = tmp return i def qSort(hoge, p, r): if p < r: q = partition(hoge, p, r) qSort(hoge, p, q-1) qSort(hoge, q+1, r) def isStable(input_array, output_array): N = len(input_array) for i in range(1, N-1): for j in range(i+1, N): for a in range(1, N-1): for b in range(a+1, N): if input_array[i][1] == output_array[j][1] and input_array[i] == output_array[b] and input_array[j] == output_array[a]: return 'Not stable' return 'Stable' if __name__ == '__main__': num = int(input()) hoge = list() for _ in range(num): c, s = input().split() hoge.append(c+s) origin = hoge[:] qSort(hoge, 0, len(hoge)) print(isStable(origin, hoge)) print('\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))
Traceback (most recent call last): File "/tmp/tmpjaefib2z/tmpe2xzjf69.py", line 29, in <module> num = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s598690782
p02277
u150984829
1518841310
Python
Python3
py
Runtime Error
0
0
471
import sys def t(A,p,r): x=A[r][1];i=p-1 for j in range(p,r): if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i] A[i+1],A[r]=A[r],A[i+1] return i+1 def k(A,p,r): if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r) def s(A): for i in range(n-1): if A[i][1]==A[i+1][1]: if A[i][2]>A[i+1][2]:return 0 return 1 n=int(input()) f=lambda x,i:(x[0],int(x[1]),i) A=[f(sys.stdin.readline().split(),i))for i in range(n)] k(A,0,n-1) print(['Not s','S'][s(A)]+'table') for e in A:print(*e[:2])
File "/tmp/tmpidp08rar/tmp3zee9ps1.py", line 17 A=[f(sys.stdin.readline().split(),i))for i in range(n)] ^ SyntaxError: closing parenthesis ')' does not match opening parenthesis '['
s130648760
p02277
u150984829
1518843458
Python
Python3
py
Runtime Error
0
0
445
import sys def t(A,p,r): x=A[r][1];i=p-1 for j in range(p,r): if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i] A[i+1],A[r]=A[r],A[i+1] return i+1 def k(A,p,r): if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r) def s(A): for i in range(n-1): if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s' return'S' n=int(input()) A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)] k(A,0,n-1) print(s(A)+'table') print("\n".join(f"{a} {b}"for a,b in A[:2]))
Traceback (most recent call last): File "/tmp/tmpe0l7fcxo/tmpecevla8c.py", line 14, in <module> n=int(input()) ^^^^^^^ EOFError: EOF when reading a line
s354904776
p02277
u150984829
1520051083
Python
Python3
py
Runtime Error
0
0
484
import sys def t(A,p,r): x=A[r][1];i=p-1 for j in range(p,r): if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i] A[i+1],A[r]=A[r],A[i+1] return i+1 def k(A,p,r): if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r) def s(A): for i in range(n-1): if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s' return'S' def m(): n=int(input()) A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)] k(A,0,n-1) print(s(A)+'table') print('\n'.join(f'{a} {b}'for a,b,_ in A)) if'__main__'==__name__:m()
Traceback (most recent call last): File "/tmp/tmp4y5ffter/tmpr4n8oz0_.py", line 20, in <module> if'__main__'==__name__:m() ^^^ File "/tmp/tmp4y5ffter/tmpr4n8oz0_.py", line 15, in m n=int(input()) ^^^^^^^ EOFError: EOF when reading a line
s668807896
p02277
u328199937
1524621695
Python
Python3
py
Runtime Error
20
5612
1246
def partition(A, left, right): p = left r = right x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 key = A[i] A[i] = A[j] A[j] = key key = A[i + 1] A[i + 1] = A[r] A[r] = key if i + 1 - left <= 1: if right - (i + 1) == 1: return i + 1, A[left:right + 1] else: return i + 1, A[left:i + 2] else: return i + 1, A[i + 1:i + 2] def quickSort(A, left, right): list = [] if left < right: Q = partition(A, left, right) q = Q[0] list.extend(quickSort(A, left, q - 1)) list.extend(Q[1]) list.extend(quickSort(A, q + 1, right)) return list def bubleSort(a): for i in range(len(a)): for j in range(len(a)-1, i, -1): if a[j][1] < a[j-1][1]: a[j], a[j-1] = a[j-1], a[j] return a n = int(input()) T = [('0', 0)] for i in range(n): a, b = map(str, input().split()) x = int(b) T.append((a, x)) T1 = T[1:] T2 = quickSort(T, 1, n) if T2 == bubleSort(T1): print('Stable') else: print('Not stable') for i in range(n): a = str(T2[1]) print(T2[i][0] + ' ' + str((T2[i][1])))
Traceback (most recent call last): File "/tmp/tmp66n4ad9_/tmp9x9kz5mg.py", line 41, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s489620411
p02277
u328199937
1524623224
Python
Python3
py
Runtime Error
20
5616
1245
def partition(A, left, right): p = left r = right x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 key = A[i] A[i] = A[j] A[j] = key key = A[i + 1] A[i + 1] = A[r] A[r] = key if i + 1 - left <= 1: if right - (i + 1) == 1: return i + 1, A[left:right + 1] else: return i + 1, A[left:i + 2] else: return i + 1, A[i + 1:i + 2] def quickSort(A, left, right): list = [] if left < right: Q = partition(A, left, right) q = Q[0] list.extend(quickSort(A, left, q - 1)) list.extend(Q[1]) list.extend(quickSort(A, q + 1, right)) return list def bubleSort(a): for i in range(len(a)): for j in range(len(a)-1, i, -1): if a[j][1] < a[j-1][1]: a[j], a[j-1] = a[j-1], a[j] return a n = int(input()) T = [('0', 0)] for i in range(n): a, b = map(str, input().split()) x = int(b) T.append((a, x)) T1 = T[1:] T2 = quickSort(T, 1, n) if T2 == bubleSort(T1): print('Stable') else: print('Not stable') for i in range(n): a = str(T2[1]) print(T2[i][0] + ' ' + str((T2[i][1])))
Traceback (most recent call last): File "/tmp/tmpn8e4ui2x/tmpess4noir.py", line 41, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s793887808
p02277
u255317651
1525354073
Python
Python3
py
Runtime Error
20
5620
1038
# -*- coding: utf-8 -*- """ Created on Thu May 3 21:24:25 2018 ALDS1_6_C @author: maezawa """ a = [] n = int(input()) for i in range(n): s = input().split() a.append([s[0], int(s[1])]) a_in = a.copy() def is_stable(a, b): s = True for i, card in enumerate(b): if b[i+1][1] == b[i][1]: j = a.index(card) k = a.index(b[i+1]) if j > k: s = False return s return s def partition(a, p, r): x = a[r][1] i = p - 1 for j in range(p, r): if a[j][1] <= x: 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 def quick_sort(a, p, r): if p < r: q = partition(a, p, r) quick_sort(a, p, q-1) quick_sort(a, q+1, r) quick_sort(a, 0, len(a)-1) if is_stable(a_in, a): print('Stable') else: print('Not stable') for i in range(len(a)): print('{} {}'.format(a[i][0],a[i][1]))
Traceback (most recent call last): File "/tmp/tmpp1rxci7d/tmp458t2tcw.py", line 8, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s634911755
p02277
u684241248
1527768019
Python
Python3
py
Runtime Error
0
0
1426
INF = 10**10 def partition(ary, p, r): x = ary[r][1] i = p - 1 for j in range(p, r): if ary[j][1] <= x: i += 1 ary[i], ary[j] = ary[j], ary[i] ary[i + 1], ary[r] = ary[r], ary[i + 1] return i + 1 def quick_sort(ary, p, r): if p < r: q = partition(ary, p, r) quick_sort(ary, p, q - 1) quick_sort(ary, q + 1, r) def merge(ary, left, mid, right): lry = ary[left:mid] rry = ary[mid:right] lry.append(INF) rry.append(INF) i = 0 j = 0 for k in range(left, right): if lry[i][1] <= rry[j][1]: ary[k] = lry[i] i += 1 else: ary[k] = rry[j] j += 1 return right - left def merge_sort(ary, left, right): cnt = 0 if left + 1 < right: mid = (left + right) // 2 cnt += merge_sort(ary, left, mid) cnt += merge_sort(ary, mid, right) cnt += merge(ary, left, mid, right) return cnt if __name__ == '__main__': import sys from copy import deepcopy n = int(input()) ary = [] for line in sys.stdin: _ = line.strip().split() ary.append((_[0], int(_[1]))) qary = deepcopy(ary) mary = deepcopy(ary) quick_sort(qary, 0, n - 1) merge_sort(mary, 0, n) if qary == mary: print('Stable') else: print('Not stable') [print(*_) for _ in qary]
Traceback (most recent call last): File "/tmp/tmp88a7n47t/tmp2hud4g0j.py", line 58, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s348669463
p02277
u007270338
1528091966
Python
Python3
py
Runtime Error
30
6348
1142
#coding:utf-8 from copy import deepcopy n = int(input()) A = [] for i in range(n): ch, num = input().split() A.append([ch, int(num)]) B = deepcopy(A) def Merge(A, left, mid, right): L = A[left:mid] R = A[mid:right] L.append(["S",20000000]) R.append(["S",20000000]) i,j = 0,0 for k in range(left,right): if L[i][1] <= R[j][1]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def MergeSort(A, left, right): if left+1 < right: mid = (left + right)//2 MergeSort(A, left, mid) MergeSort(A, mid, right) Merge(A, left, mid, right) def partition(A, p, r): x = A[r-1][1] i = p-1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] return i def quickSort(A, p, r): if p < r: q = partition(A, p, r) quickSort(A, p, q) quickSort(A, q+1, r) quickSort(A, 0, n) MergeSort(B, 0, n) if A == B: print("Stable") else: print("Not stable") for a in A: a = " ".join([a[0],str(a[1])]) print(a)
Traceback (most recent call last): File "/tmp/tmp1pif2l3q/tmpx_ghdqdk.py", line 3, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s575819031
p02277
u424720817
1530591818
Python
Python3
py
Runtime Error
0
0
399
n = int(input()) numbers = list(map(int, input().split())) def main() : x = numbers[n - 1] i = 0 for j in range(n) : if numbers[j] <= x : numbers[i], numbers[j] = numbers[j], numbers[i] i += 1 [print(numbers[j] if j != i - 1 else '['+str(numbers[j])+']', end = ' ' if j != n - 1 else '\n') for j in range(n)] if __name__ == '__main__': main()
Traceback (most recent call last): File "/tmp/tmptakv_r1s/tmp573cknhn.py", line 1, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s325639292
p02277
u912237403
1371352726
Python
Python
py
Runtime Error
20
4272
831
def partition(A, p, r): x = A[r]/10 i = p-1 for j in range(p, r): if A[j]/10 <= x: i += 1 A[i], A[j] = A[j], A[i] i += 1 A[i], A[r] = A[r], A[i] return i def quicksort(A, p, r): if p<r: q = partition(A, p, r) quicksort(A, p, q-1) quicksort(A, q+1, r) return def order(A): x = [0 for i in range(len(A))] xp = 0 for i in range(max(A)): for e in A: if e/10 == i: x[xp] = e xp += 1 return x n = int(input()) x = [[] for i in range(n)] for i in range(n): a, b = raw_input().split() x[i] = int(b)*10 + 'SHDC'.index(a) x1 = x + [] quicksort(x1, 0, n-1) if order(x) == order(x1): print 'Stable' else: print 'Not stable' for e in x1: print 'SHDC'[e % 10], e/10
File "/tmp/tmpjbtvg5wg/tmpkxpjjwkp.py", line 38 print 'Stable' ^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s624856791
p02277
u912237403
1371365342
Python
Python
py
Runtime Error
0
0
846
def partition(A, p, r): x = A[r]/10 i = p-1 for j in range(p, r): if A[j]/10 <= x: i += 1 A[i], A[j] = A[j], A[i] i += 1 A[i], A[r] = A[r], A[i] print A,i,r return i def quicksort(A, p, r): if p<r: q = partition(A, p, r) quicksort(A, p, q-1) quicksort(A, q+1, r) return def bubblesort(A): for i in range(len(A)): for j in range(i+1,len(A))[::-1]: if A[j] < A[j-1]: A[j],A[j-1] = A[j-1], A[j] return n = int(input()) x = [[] for i in range(n)] for i in range(n): a, b = raw_input().split() x[i] = int(b)*10 + 'SHDC'.index(a) x1 = x + [] quicksort(x1, 0, n-1) x2 = x + [] bubblesort(x2, 0, n-1) if x1 == x2: print 'Stable' else: print 'Not stable' for e in x1: print 'SHDC'[e % 10], e/10
File "/tmp/tmp4ni4oupr/tmpbndwhy3s.py", line 10 print A,i,r ^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s862778680
p02278
u440050957
1454083178
Python
Python
py
Runtime Error
0
0
673
def get_weights(): input() return raw_input().split() #weights: list def minimam_cost_sort(weights): lol = [] for i in weights: if i !=0: j = i l = [j] while weights[j - 1] != 0: l.append(weights[j - 1]) j = weights[j - 1] weights[j - 1] = 0 l.sort() lol.append(l) lol.sort() s = 0 for l in lol: s += get_wol(l) print s def get_wol(l): sub = (l[0] - 1) * (len(l) - 1) - (l[0] + 1) * 2 s = sum(l) + (l[0] * (len(l) - 2)) if sub > 0: return s - sub return s minimam_cost_sort(get_weights())
File "/tmp/tmplpg9puxv/tmp36sj_342.py", line 24 print s ^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s550878983
p02278
u440050957
1454083967
Python
Python
py
Runtime Error
10
6408
766
def get_weights(): raw_input() return map(int, raw_input().split()) #weights: list def minimam_cost_sort(weights): lol = [] for i in range(len(weights)): if weights[i] !=0: j = weights[i] weights[i] = 0 l = [j] while weights[j - 1] != 0: l.append(weights[j - 1]) k = j j = weights[k - 1] weights[k - 1] = 0 l.sort() lol.append(l) lol.sort() s = 0 for l in lol: s += get_wol(l) print s def get_wol(l): sub = (l[0] - 1) * (len(l) - 1) - (l[0] + 1) * 2 s = sum(l) + (l[0] * (len(l) - 2)) if sub > 0: return s - sub return s minimam_cost_sort(get_weights())
File "/tmp/tmpgx3te0hi/tmpnb8z9dbe.py", line 26 print s ^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s327720666
p02278
u567281053
1459614983
Python
Python
py
Runtime Error
20
6548
686
import sys def minimumCostSort(A): B = sorted(A) V = [False] * len(A) T = [0] * 10000 ans = 0 s = min(A) for i in range(len(A)): T[B[i]] = i for i in range(len(A)): if V[i]: continue S = an = 0 j = i m = 10000 while True: V[j] = True an += 1 v = A[j] m = min(m, v) S += v j = T[v] if V[j]: break ans += min(S + (an - 2) * m, m + S + (an + 1) * s) return ans if __name__ == "__main__": lines = sys.stdin.readlines() A = map(int, lines[1].split()) print minimumCostSort(A)
File "/tmp/tmp99p9cdkb/tmpnjrmrxxq.py", line 34 print minimumCostSort(A) ^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s374806663
p02278
u742013327
1478840293
Python
Python3
py
Runtime Error
20
7912
2401
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_D #????°??????????????????? def partition(target_list, l, r): x = target_list[r] i = l - 1 for j in range(l, r): if target_list[j] <= x: i = i + 1 tmp = target_list[i] target_list[i] = target_list[j] target_list[j] = tmp tmp = target_list[r] target_list[r] = target_list[i + 1] target_list[i + 1] = tmp return i + 1 def quick_sort(target_list, l, r): if l < r: c = partition(target_list, l, r) quick_sort(target_list, l, c - 1) quick_sort(target_list, c + 1, r) def processA(target_list, correct_list, i): cost = 0 while not correct_list[i] == target_list[i]: min_i = target_list.index(correct_list[i]) change_i = target_list.index(correct_list[min_i]) cost += (target_list[min_i] + target_list[change_i]) target_list[min_i], target_list[change_i] = target_list[change_i], target_list[min_i] #print("A", target_list) return cost def processB(target_list, correct_list, i): minv = correct_list[0] target = correct_list[i] if minv == target: return 10 ** 9 cost = (minv + target) #print(minv, target) mmi = target_list.index(minv) smi = target_list.index(target) target_list[mmi], target_list[smi] = target_list[smi], target_list[mmi] while not correct_list[i] == target_list[i]: min_i = target_list.index(minv) change_i = target_list.index(correct_list[min_i]) cost += (target_list[min_i] + target_list[change_i]) target_list[min_i], target_list[change_i] = target_list[change_i], target_list[min_i] #print("B",target_list) return cost def minimum_cost_sort(target_list): correct_list = [a for a in target_list] quick_sort(correct_list, 0, len(correct_list) - 1) cost = 0 i = 0 while not correct_list == target_list: cost_b = processB([a for a in target_list], correct_list, i) cost_a = processA(target_list, correct_list, i) cost += min(cost_a, cost_b) #print(cost_a, cost_b) #print(target_list) i += 1 return cost def main(): n_list = input() target_list = [int(s) for s in input().split()] print(minimum_cost_sort(target_list)) if __name__ == "__main__": main()
Traceback (most recent call last): File "/tmp/tmpl948nwfs/tmpljxwmc04.py", line 75, in <module> main() File "/tmp/tmpl948nwfs/tmpljxwmc04.py", line 70, in main n_list = input() ^^^^^^^ EOFError: EOF when reading a line
s618661055
p02278
u022407960
1479897472
Python
Python3
py
Runtime Error
20
7744
1141
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys MAX_VALUE = 1e4 def min_cost_sort(): ans = 0 for i in range(array_length): if check_order[i]: continue current_index = i _sum, min_value, circle_size = 0, MAX_VALUE, 0 while True: check_order[current_index] = True circle_size += 1 current_value = array[current_index] min_value = min(min_value, current_value) _sum += current_value current_index = kv_reverse[current_value] if check_order[current_index]: break ans += min(_sum + (circle_size - 2) * min_value, _sum + min_value + (circle_size + 1) * _sum) return ans if __name__ == '__main__': _input = sys.stdin.readlines() array_length = int(_input[0]) array = list(map(int, _input[1].split())) # assert len(array) == array_length check_order = [False] * array_length kv_reverse = [-1] * (array_length + 1) compare_ans = sorted(array) for j in range(array_length): kv_reverse[compare_ans[j]] = j print(min_cost_sort())
Traceback (most recent call last): File "/tmp/tmpmy4t1qfc/tmppct4wg5o.py", line 31, in <module> array_length = int(_input[0]) ~~~~~~^^^ IndexError: list index out of range
s813406616
p02278
u918276501
1508063320
Python
Python3
py
Runtime Error
0
0
767
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 = A.index(bj) tmp_cost += bi + bj swap(A,j,k) j = k # diff. to swap with min(B) dec = t * (bj - B[0]) inc = 2 * (bj + B[0]) if dec < inc: cost += tmp_cost else: cost += tmp_cost - dec + inc return cost if __name__ == "__main__": input() A = list(map(int, input().strip().split())) cost = mincost(A) print(cost)
Traceback (most recent call last): File "/tmp/tmpc1r0xh3l/tmpa6__zst8.py", line 34, in <module> input() EOFError: EOF when reading a line
s019119332
p02278
u957470671
1511917819
Python
Python3
py
Runtime Error
20
5600
550
# line = "4 3 2 1" # L = [int(x) for x in line.split()] # n = len(L) n = int(input()) line = input() L = [int(x) for x in line.split()] flags = [False] * n loops = [] for i, x in enumerate(L): k = x - 1 if flags[k]: continue if i == k: flags[i] = True continue loop = [] while x not in loop: flags[k] = True loop.append(x) x = L[k] k = x - 1 loops.append(loop) cost = 0 for loop in loops: m = min(loop) cost += m * (len(loop)-1) + sum(loop) - m print(cost)
Traceback (most recent call last): File "/tmp/tmpbaywjafn/tmp5_svd4_1.py", line 5, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s416905491
p02278
u957470671
1511917903
Python
Python3
py
Runtime Error
20
5604
480
n = int(input()) line = input() L = [int(x) for x in line.split()] flags = [False] * n loops = [] for i, x in enumerate(L): k = x - 1 if flags[k]: continue if i == k: flags[i] = True continue loop = [] while x not in loop: flags[k] = True loop.append(x) x = L[k] k = x - 1 loops.append(loop) cost = 0 for loop in loops: m = min(loop) cost += m * (len(loop)-1) + sum(loop) - m print(cost)
Traceback (most recent call last): File "/tmp/tmpcg2sdwtx/tmp2k8zwhlw.py", line 1, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s466438584
p02278
u426534722
1517324830
Python
Python3
py
Runtime Error
0
0
579
n = int(input()) A = list(map(int, input().split())) s = min(A) def solve(): ans = 0 V = [False] * n # B = sorted(A) # T = {B[i]: i for i in range(n)} T = {B: i for i, B in enumerate(sorted(A))} for i in range(n): if V[i]: continue cur = i S = an = 0 m = 10000 while not V[cur]: V[cur] = True an += 1 v = A[cur] m = min(m, v) S += v cur = T[v] ans += min(S + (an - 2) * m, m + S + (an + 1) * s) return ans print(solve())
File "/tmp/tmp_jgkfz55/tmpx49romjb.py", line 9 T = {B: i for i, B in enumerate(sorted(A))} TabError: inconsistent use of tabs and spaces in indentation
s404025644
p02278
u150984829
1518977988
Python
Python3
py
Runtime Error
0
0
226
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)
Traceback (most recent call last): File "/tmp/tmp3bh3mqea/tmpg62s_kvj.py", line 1, in <module> n=int(input()) ^^^^^^^ EOFError: EOF when reading a line
s676599596
p02278
u500386459
1519402405
Python
Python3
py
Runtime Error
0
0
1208
let quick_sort a n cmp = let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in let partition p r = let i = ref p in for j = p to r - 1 do if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i) done; swap !i r; !i in let rec doit p r = if p >= r then () else let q = partition p r in doit p (q - 1); doit (q + 1) r in doit 0 (n - 1) let calc_cost a n = let b = Array.copy a in quick_sort b n compare; let t = Array.make (b.(n-1) + 1) 0 in Array.iteri (fun i e -> t.(e) <- i) b; let p = Array.make n false in let rec cycle i acc = p.(i) <- true; let j = t.(a.(i)) in if p.(j) then a.(i) :: acc else cycle j (a.(i) :: acc) in let cycle i = cycle i [] in let rec doit i acc = if i = n then acc else if p.(i) then doit (i + 1) acc else let ws = cycle i in let m = List.length ws in let s = List.fold_left (+) 0 ws in let z = List.fold_left min max_int ws in doit (i + 1) (acc + (min (s + (m - 2)*z) (s + z + (m + 1)*b.(0)))) in doit 0 0 let () = let n = read_int () in let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in calc_cost a n |> Printf.printf "%d\n"
File "/tmp/tmpt3elr98w/tmp6y4q6jjg.py", line 1 let quick_sort a n cmp = ^^^^^^^^^^ SyntaxError: invalid syntax
s092462832
p02278
u500386459
1519402412
Python
Python
py
Runtime Error
0
0
1208
let quick_sort a n cmp = let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in let partition p r = let i = ref p in for j = p to r - 1 do if cmp a.(j) a.(r) <= 0 then (swap !i j; incr i) done; swap !i r; !i in let rec doit p r = if p >= r then () else let q = partition p r in doit p (q - 1); doit (q + 1) r in doit 0 (n - 1) let calc_cost a n = let b = Array.copy a in quick_sort b n compare; let t = Array.make (b.(n-1) + 1) 0 in Array.iteri (fun i e -> t.(e) <- i) b; let p = Array.make n false in let rec cycle i acc = p.(i) <- true; let j = t.(a.(i)) in if p.(j) then a.(i) :: acc else cycle j (a.(i) :: acc) in let cycle i = cycle i [] in let rec doit i acc = if i = n then acc else if p.(i) then doit (i + 1) acc else let ws = cycle i in let m = List.length ws in let s = List.fold_left (+) 0 ws in let z = List.fold_left min max_int ws in doit (i + 1) (acc + (min (s + (m - 2)*z) (s + z + (m + 1)*b.(0)))) in doit 0 0 let () = let n = read_int () in let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in calc_cost a n |> Printf.printf "%d\n"
File "/tmp/tmp2zozzpgn/tmp99cwgoep.py", line 1 let quick_sort a n cmp = ^^^^^^^^^^ SyntaxError: invalid syntax
s561586851
p02278
u138546245
1524566688
Python
Python3
py
Runtime Error
20
5648
2243
def partition(li, p, r): """Separate li with a value of li[r]. Returns index of the partition value. >>> ax = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11] >>> partition(ax, 0, 11) 7 >>> ax [9, 5, 8, 7, 4, 2, 6, 11, 21, 13, 19, 12] """ x = li[r] i = p - 1 for j in range(p, r): if li[j] <= x: i += 1 li[i], li[j] = li[j], li[i] i += 1 li[i], li[r] = li[r], li[i] return i def quicksort(li, p, r): """sort li by quick sort algorithm. >>> li = [3, 2, 1, 3, 2, 1] >>> quicksort(li, 0, 5) >>> li [1, 1, 2, 2, 3, 3] """ if p < r: q = partition(li, p, r) quicksort(li, p, q-1) quicksort(li, q+1, r) def min_cost(li1, li2): """calculate minimum cost to transform li1 into li2. >>> min_cost([1, 5, 3, 4, 2], [1, 2, 3, 4, 5]) 7 >>> min_cost([4, 3, 2, 1], [1, 2, 3, 4]) 10 """ def find_moves(i, j): start = i elems = [i] mincost = li1[i] minidx = 0 while j != start: if mincost > li1[j]: mincost = li1[j] minidx = len(elems) elems.append(j) j = li2.index(li1[j]) elems = elems[minidx+1:] + elems[:minidx+1] if 2 * (mincost + li1[mini]) < (len(elems) - 1) * (mincost - li1[mini]): elems.append(mini) elems.insert(0, mini) q = elems.pop() p = elems.pop() yield (p, q) while len(elems) > 0: q = p p = elems.pop() yield (p, q) def move(i, j): cost = 0 for p, q in find_moves(i, j): li1[p], li1[q] = li1[q], li1[p] cost += li1[p] + li1[q] return cost assert len(li1) == len(li2) size = len(li1) totalcost = 0 for i in reversed(range(size)): if li1[i] != li2[i]: mini = li1.index(li2[0]) totalcost += move(li1.index(li2[i]), i) return totalcost def run(): _ = int(input()) # flake8: noqa li = [int(i) for i in input().split()] sli = li[:] quicksort(sli, 0, len(li)-1) print(min_cost(li, sli)) if __name__ == '__main__': run()
Traceback (most recent call last): File "/tmp/tmpatxtipu8/tmpfxzek6ob.py", line 103, in <module> run() File "/tmp/tmpatxtipu8/tmpfxzek6ob.py", line 94, in run _ = int(input()) # flake8: noqa ^^^^^^^ EOFError: EOF when reading a line
s538963761
p02278
u318430977
1528817706
Python
Python3
py
Runtime Error
20
5612
1290
def partition(a, p, r): x = a[r] i = p - 1 for j in range(p, r): if a[j] <= x: i += 1 tmp = a[i] a[i] = a[j] a[j] = tmp tmp = a[i+1] a[i+1] = a[r] a[r] = tmp return i + 1 def quick_sort(a, p, r): if p < r: q = partition(a, p, r) quick_sort(a, p, q-1) quick_sort(a, q+1, r) def make_cyclic(w, v): flags = [True] * len(w) cyclics = [] for i in range(len(w)): if flags[i]: flags[i] = False cycle = [w[i]] now = w[i] while True: j = v.index(now) if j == i: break cycle.append(w[j]) now = w[j] flags[j] = False cyclics.append(cycle) return cyclics def min_cost_sort(w): v = w.copy() quick_sort(v, 0, len(v) - 1) cyclics = make_cyclic(w, v) ans = 0 for cycle in cyclics: inner_cycle = min(cycle) * (len(cycle) - 2) + sum(cycle) outer_cycle = min(cycle) + min(set(w) - set(cycle)) * (len(cycle) + 1) + sum(cycle) ans += min(inner_cycle, outer_cycle) return ans n = int(input()) w = [int(x) for x in input().split()] print(min_cost_sort(w))
Traceback (most recent call last): File "/tmp/tmpzxgmf52m/tmpq0o6fg2c.py", line 58, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s616023301
p02278
u318430977
1528817986
Python
Python3
py
Runtime Error
30
5624
1392
def partition(a, p, r): x = a[r] i = p - 1 for j in range(p, r): if a[j] <= x: i += 1 tmp = a[i] a[i] = a[j] a[j] = tmp tmp = a[i+1] a[i+1] = a[r] a[r] = tmp return i + 1 def quick_sort(a, p, r): if p < r: q = partition(a, p, r) quick_sort(a, p, q-1) quick_sort(a, q+1, r) def make_cyclic(w, v): flags = [True] * len(w) cyclics = [] for i in range(len(w)): if flags[i]: flags[i] = False cycle = [w[i]] now = w[i] while True: j = v.index(now) if j == i: break cycle.append(w[j]) now = w[j] flags[j] = False cyclics.append(cycle) return cyclics def min_cost_sort(w): v = w.copy() quick_sort(v, 0, len(v) - 1) cyclics = make_cyclic(w, v) ans = 0 for cycle in cyclics: inner_cycle = min(cycle) * (len(cycle) - 2) + sum(cycle) if len(set(w) - set(cycle)) >= 1: outer_cycle = min(cycle) + min(set(w) - set(cycle)) * (len(cycle) + 1) + sum(cycle) else: outer_cycle = inner_cycle + 1 ans += min(inner_cycle, outer_cycle) return ans n = int(input()) w = [int(x) for x in input().split()] print(min_cost_sort(w))
Traceback (most recent call last): File "/tmp/tmpub06j0za/tmp_q2rz2lo.py", line 61, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s875012938
p02279
u153665391
1531230222
Python
Python3
py
Runtime Error
0
0
1525
N = int(input()) def get_parent(node): parent = -1 if "parent" in node: parent = node["parent"] return parent def get_depth(node): depth = 0 while "parent" not in node: depth += 1 parent = node["parent"] node = rooted_tree[parent] return depth def get_node_type(node): if "parent" in node: return "root" if "left" in node: return "leaf" return "internal node" def get_children(node): if "left" not in node: return "[]" left = node["left"] siblings = [] siblings.append(str(left)) while rooted_tree[left]["right"] > -1: right = rooted_tree[left]["right"] siblings.append(str(right)) left = right return "[{}]".format(", ".join(siblings)) rooted_tree = [{} for i in range(N)] for id in range(N): row = input() _, degree, *children = list(map(int, row.split())) if degree > 0: rooted_tree[id]["left"] = children[0] for i in range(len(children)): child_id = children[i] right = -1 if i < len(children)-1: right = children[i+1] rooted_tree[child_id]["right"] = right rooted_tree[child_id]["parent"] = id for id in range(N): node = rooted_tree[id] parent = get_parent(node) depth = get_depth(node) node_type = get_node_type(node) children = get_children(node) print("node {}: parent = {}, depth = {}, {}, {}".format(id, parent, depth, node_type, children))
Traceback (most recent call last): File "/tmp/tmp3lk_3a_d/tmphws_13b9.py", line 1, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s118951374
p02279
u153665391
1531436040
Python
Python3
py
Runtime Error
20
5612
1701
N = int(input()) def get_parent(node): parent = -1 if "parent" in node: parent = node["parent"] return parent def get_node_type(node): if "parent" not in node: return "root" if "left" not in node: return "leaf" return "internal node" def get_children(node): if "left" not in node: return "[]" left = node["left"] siblings = [] siblings.append(str(left)) while rooted_tree[left]["right"] > -1: right = rooted_tree[left]["right"] siblings.append(str(right)) left = right return "[{}]".format(", ".join(siblings)) def rec(node_id, depth): Depth[node_id] = str(depth) if "right" in rooted_tree[node_id]: rec(rooted_tree[node_id]["right"], depth) if "left" in rooted_tree[node_id]: rec(rooted_tree[node_id]["left"], depth+1) rooted_tree = [{} for i in range(N)] for _ in range(N): row = input() id, degree, *children = list(map(int, row.split())) if degree > 0: rooted_tree[id]["left"] = children[0] for i in range(len(children)): child_id = children[i] right = -1 if i < len(children)-1: right = children[i+1] rooted_tree[child_id]["right"] = right rooted_tree[child_id]["parent"] = id root = 0 for i in range(N): if "parent" not in rooted_tree[i]: root == i break Depth = {} rec(root, 0) for id in range(N): node = rooted_tree[id] parent = get_parent(node) node_type = get_node_type(node) children = get_children(node) print("node {}: parent = {}, depth = {}, {}, {}".format(id, parent, Depth[id], node_type, children))
Traceback (most recent call last): File "/tmp/tmp7vk5aa7g/tmp5q06fclw.py", line 1, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s411722048
p02279
u657361950
1531707092
Python
Python3
py
Runtime Error
0
0
2011
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static class Node { int id; int parentId; int depth; int[] children; public Node(int id, int parentId) { this.id = id; this.parentId = parentId; this.children = null; this.depth = 0; } public void setChildlen(int[] childlen) { this.children = childlen; } public void setParentId(int parentId) { this.parentId = parentId; } public void setDepth(int depth) { this.depth = depth; } private String getType() { if (depth == 0) { return "root"; } if (children == null || children.length == 0) { return "leaf"; } return "internal node"; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("node " + id + ": "); sb.append("parent = " + parentId + ", "); sb.append("depth = " + depth + ", "); sb.append(getType() + ", "); sb.append(Arrays.toString(children)); return sb.toString(); } } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(reader.readLine()); Node[] nodes = new Node[n]; for (int i = 0; i < n; i++) { StringTokenizer st = new StringTokenizer(reader.readLine()); int id = Integer.parseInt(st.nextToken()); if (nodes[id] == null) { nodes[id] = new Node(id, -1); } int m = Integer.parseInt(st.nextToken()); int[] children = new int[m]; for (int j = 0; j < m; j++) { int childId = Integer.parseInt(st.nextToken()); children[j] = childId; if (nodes[childId] == null) { nodes[childId] = new Node(childId, id); } else { nodes[childId].setParentId(id); } nodes[childId].setDepth(nodes[id].depth + 1); } nodes[id].setChildlen(children); } for (Node node : nodes) { System.out.println(node); } } }
File "/tmp/tmpxss4eyhv/tmp4jzr9pue.py", line 7 public class Main { ^^^^^ SyntaxError: invalid syntax
s603592848
p02279
u657361950
1531790943
Python
Python3
py
Runtime Error
0
0
1349
class Node: def __init__(self, id): self.id = id self.parent_id = -1 self.depth = -1 self.children = None def get_type(self): if self.parent_id == -1: return 'root' elif self.children == None or len(self.children) == 0: return 'leaf' return 'internal node' def __str__(self): strNode = 'node ' + str(self.id) + ': ' strNode += 'parent = ' + str(self.parent_id) + ', ' strNode += 'depth = ' + str(self.depth) + ', ' strNode += self.get_type() + ', [' if len(self.children) > 0: strNode += str(self.children[0]) for i in range(1, len(self.children)): strNode += ', ' + str(self.children[i]) strNode += ']' return strNode def calc_depth(nodes): stack = [] for i in range(len(nodes)): if nodes[i].parent_id == -1: nodes[i].depth = 0 stack.append(nodes[i].id) break while len(stack) != 0: node = nodes[stack.pop()] for i in range(len(node.children)): child_id = node.children[i] nodes[child_id].depth = node.depth + 1 stack.append(child_id) n = int(input()) nodes = [Node(i) for i in range(n)] for i in range(n): a = list(map(int, input().split())) id = a[0] m = a[1] children = [0] * m for j in range(m): child_id = a[2 + j] child = nodes[child_id] child.parent_id = id children[j] = child_id nodes[id].children = children calc_depth(nodes) for i in range(n):
File "/tmp/tmp087_mst0/tmp5g4n_n1h.py", line 55 for i in range(n): IndentationError: expected an indented block after 'for' statement on line 55
s474523829
p02279
u637322311
1535099929
Python
Python3
py
Runtime Error
20
5612
1125
from sys import stdin class Node(object): def __init__(self, parent=None, children=None, name=None, depth=None): self.parent = parent self.children = children self.name = name self.depth = depth def set_depth(nodes, u): p = nodes[u].parent d = nodes[p].depth if d != None and p != -1: nodes[u].depth = d + 1 def read_rooted_tree(n, nodes): for _ in range(n): i = [int(i) for i in stdin.readline().strip().split()] c = i[2:len(i)] nodes[i[0]].children = c if nodes[i[0]].name != "root": if c: nodes[i[0]].name = "internal node" else: nodes[i[0]].name = "leaf" for j in nodes[i[0]].children: nodes[j].parent = i[0] set_depth(nodes, i[0]) n = int(input()) nodes = [Node() for _ in range(n)] nodes[0].parent = -1 nodes[0].depth = 0 nodes[0].name = "root" read_rooted_tree(n, nodes) for i in range(n): print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format( i, nodes[i].parent, nodes[i].depth, nodes[i].name, nodes[i].children))
Traceback (most recent call last): File "/tmp/tmp9_mbkewo/tmprmgn5hdh.py", line 30, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s016238642
p02279
u487861672
1535698209
Python
Python3
py
Runtime Error
20
5608
898
#! /usr/local/bin/python3 # coding: utf-8 class Node(): def __init__(self, parent=-1, child=[]): self.parent = parent self.child = child def node_depth(u, id): if u[id].parent == -1: return 0 else: return node_depth(u, u[id].parent) + 1 def node_type(u, id): if u[id].parent == -1: return "root" elif u[id].child == []: return "leaf" else: return "internal node" def main(): n = int(input()) u = [Node() for _ in range(n)] for i in range(n): _, _, *child = (int(x) for x in input().split()) u[i].child = child for c in child: u[c].parent = i for i in range(n): print("node {}: parent = {}, depth = {}, {}, {}". format(i, u[i].parent, node_depth(u, i), node_type(u, i), u[i].child)) main()
Traceback (most recent call last): File "/tmp/tmp0fmwabf5/tmpbnhdirqt.py", line 44, in <module> main() File "/tmp/tmp0fmwabf5/tmpbnhdirqt.py", line 28, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s077990586
p02279
u487861672
1535698304
Python
Python3
py
Runtime Error
20
5616
987
#! /usr/local/bin/python3 # coding: utf-8 from sys import setrecursionlimit setrecursionlimit(21) class Node(): def __init__(self, parent=-1, child=[]): self.parent = parent self.child = child def node_depth(u, id): if u[id].parent == -1: return 0 else: return node_depth(u, u[id].parent) + 1 def node_type(u, id): if u[id].parent == -1: return "root" elif u[id].child == []: return "leaf" else: return "internal node" def main(): n = int(input()) u = [Node() for _ in range(n)] for i in range(n): _, _, *child = (int(x) for x in input().split()) u[i].child = child for c in child: u[c].parent = i for i in range(n): print("node {}: parent = {}, depth = {}, {}, {}". format(i, u[i].parent, node_depth(u, i), node_type(u, i), u[i].child)) if __name__ == '__main__': main()
Traceback (most recent call last): File "/tmp/tmpdj7nuxk5/tmpnuasvmqe.py", line 49, in <module> main() File "/tmp/tmpdj7nuxk5/tmpnuasvmqe.py", line 32, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s356769780
p02279
u487861672
1535698327
Python
Python3
py
Runtime Error
20
5620
987
#! /usr/local/bin/python3 # coding: utf-8 from sys import setrecursionlimit setrecursionlimit(22) class Node(): def __init__(self, parent=-1, child=[]): self.parent = parent self.child = child def node_depth(u, id): if u[id].parent == -1: return 0 else: return node_depth(u, u[id].parent) + 1 def node_type(u, id): if u[id].parent == -1: return "root" elif u[id].child == []: return "leaf" else: return "internal node" def main(): n = int(input()) u = [Node() for _ in range(n)] for i in range(n): _, _, *child = (int(x) for x in input().split()) u[i].child = child for c in child: u[c].parent = i for i in range(n): print("node {}: parent = {}, depth = {}, {}, {}". format(i, u[i].parent, node_depth(u, i), node_type(u, i), u[i].child)) if __name__ == '__main__': main()
Traceback (most recent call last): File "/tmp/tmpuoirx8ja/tmp9lo0lhdl.py", line 49, in <module> main() File "/tmp/tmpuoirx8ja/tmp9lo0lhdl.py", line 32, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s510482477
p02279
u487861672
1535975339
Python
Python3
py
Runtime Error
20
5616
1410
class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmp26yeawv9/tmpwnwen_qp.py", line 64, in <module> main() File "/tmp/tmp26yeawv9/tmpwnwen_qp.py", line 57, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s766638627
p02279
u487861672
1535975667
Python
Python3
py
Runtime Error
0
0
1481
from sys import setrecursionlimit setrecursionlimit(1000) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
File "/tmp/tmpj4cktvai/tmpk78n825d.py", line 1 from sys import setrecursionlimit IndentationError: unexpected indent
s195783752
p02279
u487861672
1535975690
Python
Python3
py
Runtime Error
20
5620
1472
from sys import setrecursionlimit setrecursionlimit(1000) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmp9178y9yo/tmpi44c2qg6.py", line 67, in <module> main() File "/tmp/tmp9178y9yo/tmpi44c2qg6.py", line 60, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s780475739
p02279
u487861672
1535975734
Python
Python3
py
Runtime Error
20
5620
1474
from sys import setrecursionlimit setrecursionlimit(200000) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmpgzwxqw0u/tmpmu0k9esa.py", line 67, in <module> main() File "/tmp/tmpgzwxqw0u/tmpmu0k9esa.py", line 60, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s153622781
p02279
u487861672
1535976010
Python
Python3
py
Runtime Error
20
5616
1474
from sys import setrecursionlimit setrecursionlimit(100000) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmpcyr_5tsj/tmp2vcekub3.py", line 67, in <module> main() File "/tmp/tmpcyr_5tsj/tmp2vcekub3.py", line 60, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s256653212
p02279
u487861672
1535976026
Python
Python3
py
Runtime Error
20
5616
1473
from sys import setrecursionlimit setrecursionlimit(50000) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmpqb25t0hi/tmplenav03a.py", line 67, in <module> main() File "/tmp/tmpqb25t0hi/tmplenav03a.py", line 60, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s891273863
p02279
u487861672
1535976049
Python
Python3
py
Runtime Error
30
5620
1473
from sys import setrecursionlimit setrecursionlimit(99999) class Node(): NIL = -1 def __init__(self, parent=NIL, left=NIL, right=NIL, depth=-1): self.parent = parent self.left = left self.right = right self.depth = depth def read_nodes(T): for _ in range(len(T)): id, _, *child = [int(x) for x in input().split()] for i, c in enumerate(child): if i == 0: T[id].left = c else: T[l].right = c l = c T[c].parent = id def calc_depth(T): def rec(r, p): nonlocal T T[r].depth = p if T[r].right != Node.NIL: rec(T[r].right, p) if T[r].left != Node.NIL: rec(T[r].left, p + 1) rec([u.parent for u in T].index(-1), 0) def node_type(T, id): if T[id].parent == Node.NIL: return "root" elif T[id].left == Node.NIL: return "leaf" else: return "internal node" def child(T, id): c = [] i = T[id].left while i != Node.NIL: c.append(i) i = T[i].right return c def print_nodes(T): for id in range(len(T)): print("node {}: parent = {}, depth = {}, {}, {}". format(id, T[id].parent, T[id].depth, node_type(T, id), child(T, id))) def main(): n = int(input()) T = [Node() for _ in range(n)] read_nodes(T) calc_depth(T) print_nodes(T) main()
Traceback (most recent call last): File "/tmp/tmpa2gtdbiz/tmp0pjf7eqv.py", line 67, in <module> main() File "/tmp/tmpa2gtdbiz/tmp0pjf7eqv.py", line 60, in main n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s084869984
p02279
u609159835
1546151307
Python
Python3
py
Runtime Error
0
0
1427
#include<stdio.h> #include<stdlib.h> #define MAX 100000 #define NIL -1 typedef struct node { int p; int l; int r; } Node; Node no[MAX]; int D[MAX]; void setDepth(int u, int p){ D[u] = p; if(no[u].l != NIL){ setDepth(no[u].l, p + 1); } if (no[u].r != NIL){ setDepth(no[u].r, p); } } void print(int u){ int i, c; printf("node "); printf("%d: ", u); printf("parent = %d, ", no[u].p); printf("depth = %d, ", D[u]); if(no[u].p == NIL) printf("root, "); else if (no[u].l == NIL ) printf("leaf, "); else printf("internal node, "); printf("["); for(i = 0, c = no[u].l; c != NIL; i++, c = no[c].r){ if(i) printf(", "); printf("%d", c); } printf("]"); printf("\n"); } int main(){ int n, i, j, v, l = 0; int tmp; int a[10]; scanf("%d", &n); /* initialize */ for(i = 0; i < n; i++){ no[i].p = no[i].l = no[i].r = NIL; } for(i = 0; i < n; i++){ int id, k; scanf("%d%d", &id, &k); for(j = 0; j < k; j++){ int c; tmp = scanf("%d", &c); if(j == 0) no[id].l = c; else no[l].r = c; l = c; no[t].p = id; } } int r; for(i = 0; i < n; i++){ if(no[i].p == NIL) r = i; } setDepth(r, 0); for(i = 0; i < n; i++) print(i); return 0; }
File "/tmp/tmp65ullto_/tmpec2k0i38.py", line 6 typedef struct node { ^^^^^^ SyntaxError: invalid syntax
s467622726
p02279
u631142478
1559360041
Python
Python3
py
Runtime Error
20
5620
1038
class Node(): def __init__(self, p, l, r): self.p = p self.l = l self.r = r def rec(u, p): D[u] = p if T[u].r != -1: rec(T[u].r, p) if T[u].l != -1: rec(T[u].l, p + 1) N = int(input()) T = [Node(-1, -1, -1) for _ in range(N)] D = [-1] * N for i in range(N): i, k, *cs = map(int, input().split()) for j, c in enumerate(cs): if j == 0: T[i].l = c else: T[l].r = c l = c T[c].p = i for i, t in enumerate(T): if t.p == -1: r = i rec(r, 0) for i, t in enumerate(T): cs = [] c = t.l while c != -1: cs.append(c) c = T[c].r if t.p == -1: print('node {}: parent = {}, depth = {}, root, {}' .format(i, t.p, D[i], cs)) elif t.l == -1: print('node {}: parent = {}, depth = {}, leaf, {}' .format(i, t.p, D[i], cs)) else: print('node {}: parent = {}, depth = {}, internal node, {}' .format(i, t.p, D[i], cs))
Traceback (most recent call last): File "/tmp/tmpqn7bvlww/tmpsvbnep4h.py", line 16, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s235773555
p02279
u631142478
1559360112
Python
Python3
py
Runtime Error
20
5624
1080
import sys sys.setrecursionlimit(10000) class Node(): def __init__(self, p, l, r): self.p = p self.l = l self.r = r def rec(u, p): D[u] = p if T[u].r != -1: rec(T[u].r, p) if T[u].l != -1: rec(T[u].l, p + 1) N = int(input()) T = [Node(-1, -1, -1) for _ in range(N)] D = [-1] * N for i in range(N): i, k, *cs = map(int, input().split()) for j, c in enumerate(cs): if j == 0: T[i].l = c else: T[l].r = c l = c T[c].p = i for i, t in enumerate(T): if t.p == -1: r = i rec(r, 0) for i, t in enumerate(T): cs = [] c = t.l while c != -1: cs.append(c) c = T[c].r if t.p == -1: print('node {}: parent = {}, depth = {}, root, {}' .format(i, t.p, D[i], cs)) elif t.l == -1: print('node {}: parent = {}, depth = {}, leaf, {}' .format(i, t.p, D[i], cs)) else: print('node {}: parent = {}, depth = {}, internal node, {}' .format(i, t.p, D[i], cs))
Traceback (most recent call last): File "/tmp/tmph4v8pfyx/tmpzkeeq7qd.py", line 20, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s086467730
p02279
u631142478
1559360131
Python
Python3
py
Runtime Error
20
5624
1081
import sys sys.setrecursionlimit(100000) class Node(): def __init__(self, p, l, r): self.p = p self.l = l self.r = r def rec(u, p): D[u] = p if T[u].r != -1: rec(T[u].r, p) if T[u].l != -1: rec(T[u].l, p + 1) N = int(input()) T = [Node(-1, -1, -1) for _ in range(N)] D = [-1] * N for i in range(N): i, k, *cs = map(int, input().split()) for j, c in enumerate(cs): if j == 0: T[i].l = c else: T[l].r = c l = c T[c].p = i for i, t in enumerate(T): if t.p == -1: r = i rec(r, 0) for i, t in enumerate(T): cs = [] c = t.l while c != -1: cs.append(c) c = T[c].r if t.p == -1: print('node {}: parent = {}, depth = {}, root, {}' .format(i, t.p, D[i], cs)) elif t.l == -1: print('node {}: parent = {}, depth = {}, leaf, {}' .format(i, t.p, D[i], cs)) else: print('node {}: parent = {}, depth = {}, internal node, {}' .format(i, t.p, D[i], cs))
Traceback (most recent call last): File "/tmp/tmp9dpo9s1q/tmp565shrc2.py", line 20, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s592896594
p02279
u567380442
1421820075
Python
Python3
py
Runtime Error
0
0
1370
class Tree(): def __init__(self, root_id): self.nodes = {root_id:Node(root_id)} def add_node(self, parent_id, child_id): child = Node(child_id, self.nodes[parent_id]) self.nodes[child.id] = child class Node(): def __init__(self, id, parent = None): self.id = id self.parent = parent self.children = [] if self.parent: self.parent.children.append(self) self.depth = self.parent.depth + 1 self.nodetype = 'leaf' if self.parent.nodetype == 'leaf': self.parent.nodetype = 'internal node' else: self.depth = 0 self.nodetype = 'root' def walk(self): yield self for child in self.children: for node in child.walk(): yield node def __str__(self): parent = self.parent.id if self.parent else -1 children = ' ,'.join([str(node.id) for node in self.children]) return 'node {}: parent = {}, depth = {}, {}, [{}]'.format(self.id, parent, self.depth, self.nodetype, children) tree n = int(input()) for i in range(n): line = input().split() id = int(line[0]) if i == 0: tree = Tree(id) for ci in map(int, line[2:]): tree.add_node(id, ci) for id in tree.nodes: print( tree.nodes[id])
Traceback (most recent call last): File "/tmp/tmp3tra9f5p/tmp1i58zkt4.py", line 35, in <module> tree NameError: name 'tree' is not defined. Did you mean: 'Tree'?
s645412441
p02279
u567380442
1421820259
Python
Python3
py
Runtime Error
30
6752
1377
class Tree(): def __init__(self, root_id): self.nodes = {root_id:Node(root_id)} def add_node(self, parent_id, child_id): child = Node(child_id, self.nodes[parent_id]) self.nodes[child.id] = child class Node(): def __init__(self, id, parent = None): self.id = id self.parent = parent self.children = [] if self.parent: self.parent.children.append(self) self.depth = self.parent.depth + 1 self.nodetype = 'leaf' if self.parent.nodetype == 'leaf': self.parent.nodetype = 'internal node' else: self.depth = 0 self.nodetype = 'root' def walk(self): yield self for child in self.children: for node in child.walk(): yield node def __str__(self): parent = self.parent.id if self.parent else -1 children = ' ,'.join([str(node.id) for node in self.children]) return 'node {}: parent = {}, depth = {}, {}, [{}]'.format(self.id, parent, self.depth, self.nodetype, children) tree = None n = int(input()) for i in range(n): line = input().split() id = int(line[0]) if i == 0: tree = Tree(id) for ci in map(int, line[2:]): tree.add_node(id, ci) for id in tree.nodes: print( tree.nodes[id])
Traceback (most recent call last): File "/tmp/tmppj8qpk06/tmpz2oblhwm.py", line 37, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s457390630
p02279
u253463900
1445866965
Python
Python3
py
Runtime Error
40
7784
1638
def Get_leafs_list(T, p): l = p.l ans = [] while(T[l].r != -1): ans.append(T[l].r) l = T[l].r return ans def rec(T,node, p): T[node].d = p if(T[node].r != -1): rec(T,T[node].r, p) if(T[node].l != -1): rec(T,T[node].l, p+1) class Node(): def __init__(self,i): self.p = -1 self.l = -1 self.r = -1 self.d = 0 self.n = i def Get_leafs_list(self,T): l = self.l if l != -1: ans = [l] else: ans = [] while(T[l].r != -1): ans.append(T[l].r) l = T[l].r return ans def print_ans(self): print("node",self.n, end=": ") print("parent =",self.p, end=", ") print('depth =',self.d, end=", ") if self.l == -1 and self.p != -1: print('leaf, []') return else: if self.p == -1: print("root",end=", ") else : print("internal node",end=", ") ans = self.Get_leafs_list(T) print(ans) T = [] n = int(input()) for i in range(0,n): T.append(Node(i)) for i in range(0,n): data = [int(x) for x in input().split()] k = data[0] if(data[1] != 0): # node has leafs for j in range(0,data[1]): #leafs if j == 0: T[k].l = data[2] else: T[l].r = data[2+j] l = data[2+j] T[l].p = data[0] #get root for x in range(0,n): if(T[x].p == -1): root = x break rec(T,root,0) for x in T: x.print_ans()
Traceback (most recent call last): File "/tmp/tmpp59ca7dd/tmp_f2r3c5x.py", line 52, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s126259604
p02279
u881590806
1448767798
Python
Python
py
Runtime Error
20
6416
1328
class Node: def __init__(self, parent, left, right): self.parent = parent self.left = left self.right = right def get_type(self): if self.parent == -1: return "root" elif self.left == -1: return "leaf" else: return "internal node" def set_depth(u,d): global D global tree D[u] = d if not tree[u].right == -1: set_depth(tree[u].right, d) if not tree[u].left == -1: set_depth(tree[u].left, d+1) def print_tree(t,D): for i in range(len(t)): children = [] c = t[i].left if not c == -1: while True: children.append(c) c = t[c].right if c == -1: break print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) n = int(raw_input()) tree = {} for i in range(n): tree[i] = Node(-1, -1, -1) for _ in range(n): entry = map(int, raw_input().strip().split(' ')) nid = entry[0] n_child = entry[1] for i in range(n_child): if i == 0: tree[nid].left = entry[i+2] else: tree[entry[i+1]].right = entry[i+2] tree[entry[i+2]].parent = nid r = -1 for i in range(n): if tree[i].parent == -1: r = i D = {} set_depth(r, 0) print_tree(tree, D)
File "/tmp/tmpko_ed4vd/tmpp9cokgow.py", line 30 print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s122212381
p02279
u881590806
1448874506
Python
Python
py
Runtime Error
10
6500
1336
class Node: def __init__(self, parent, left, right): self.parent = parent self.left = left self.right = right def get_type(self): if self.parent == -1: return "root" elif self.left == -1: return "leaf" else: return "internal node" def set_depth(u,d): global D global tree D[u] = d if not tree[u].right == -1: set_depth(tree[u].right, d) if not tree[u].left == -1: set_depth(tree[u].left, d+1) def print_tree(t,D): for i in range(len(t)): children = [] c = t[i].left if not c == -1: while True: children.append(c) c = t[c].right if c == -1: break print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) n = int(raw_input().strip()) tree = {} for i in range(n): tree[i] = Node(-1, -1, -1) for _ in range(n): entry = map(int, raw_input().strip().split(' ')) nid = entry[0] n_child = entry[1] for i in range(n_child): if i == 0: tree[nid].left = entry[i+2] else: tree[entry[i+1]].right = entry[i+2] tree[entry[i+2]].parent = nid r = -1 for i in range(n): if tree[i].parent == -1: r = i D = {} set_depth(r, 0) print_tree(tree, D)
File "/tmp/tmpsjtjmaow/tmp0ahmnapv.py", line 30 print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s809884429
p02279
u881590806
1448874959
Python
Python
py
Runtime Error
10
6332
1346
class Node: def __init__(self, parent, left, right): self.parent = parent self.left = left self.right = right def get_type(self): if self.parent == -1: return "root" elif self.left == -1: return "leaf" else: return "internal node" def set_depth(u,d): global D global tree D[u] = d while not tree[u].right == -1: u = tree[u].right D[u] = d if not tree[u].left == -1: set_depth(tree[u].left, d+1) def print_tree(t,D): for i in range(len(t)): children = [] c = t[i].left if not c == -1: while True: children.append(c) c = t[c].right if c == -1: break print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) n = int(raw_input().strip()) tree = {} for i in range(n): tree[i] = Node(-1, -1, -1) for _ in range(n): entry = map(int, raw_input().strip().split(' ')) nid = entry[0] n_child = entry[1] for i in range(n_child): if i == 0: tree[nid].left = entry[i+2] else: tree[entry[i+1]].right = entry[i+2] tree[entry[i+2]].parent = nid r = -1 for i in range(n): if tree[i].parent == -1: r = i D = {} set_depth(r, 0) print_tree(tree, D)
File "/tmp/tmpc6xcms3o/tmpwq7qcchd.py", line 31 print "node %s: parent = %s, depth = %s, %s, [%s]" % (i, t[i].parent, D[i], t[i].get_type(), ", ".join(map(str, children))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s602830499
p02279
u797673668
1454172466
Python
Python3
py
Runtime Error
20
7744
1134
n = int(input()) tree = [None] * n formatted_tree = [None] * n def register_node(i, node, searching): if not searching: return False for si, st in enumerate(searching[1]): if st[0] == i: searching[1][si] = node return True elif st[1]: if register_node(i, node, st): return True return False def format(node, parent, depth): (i, cs) = node cis = [format(c, i, depth + 1) for c in cs] formatted_tree[i] = 'node {0}: parent = {1}, depth = {2}, {3}, [{4}]'.format( i, parent, depth, 'root' if not depth else 'internal node' if cis else 'leaf', ', '.join(cis) ) return str(i) while n: l = list(map(int, input().split())) i, cs = l[0], l[2:] node = (i, [(c, None) for c in cs]) for p in tree: if register_node(i, node, p): break else: tree[i] = node for i, ci in enumerate(cs): if tree[ci]: cs[i] = tree[ci] tree[ci] = None n -= 1 format(next(filter(None, tree)), -1, 0) for fn in formatted_tree: print(fn)
Traceback (most recent call last): File "/tmp/tmptagrg74j/tmpo7y1ctyv.py", line 1, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s582912421
p02279
u072053884
1454781859
Python
Python3
py
Runtime Error
30
7804
1798
"""Rooted Trees.""" class Node: def __init__(self, num, parent, rightSibling, *children): self.id = num self.parent = parent self.rightSibling = rightSibling self.children = list(children) self.depth = 0 def showInfo(self): print('node {0}: '.format(self.id), end = '') print('parent = {0}, '.format(self.parent), end = '') print('depth = {0}, '.format(self.depth), end = '') if self.children and self.parent != -1: print('internal node, ', end = '') elif self.parent != -1: print('leaf, ', end = '') else: print('root, ', end = '') print('{0}'.format(self.children)) def setNode(num, k, *children): if T[num]: T[num].children = list(children) else: node = Node(num, -1, None, *children) T[num] = node if children: for i, x in enumerate(children[:-1]): if T[x]: T[x].parent = num T[x].rightSibling = children[i + 1] else: node = Node(x, num, children[i + 1]) T[x] = node lastChild = children[-1] if T[lastChild]: T[lastChild].parent = num else: node = Node(lastChild, num, None) T[lastChild] = node def setDepth(u, p): T[u].depth = p if T[u].children: setDepth(T[u].children[0], p + 1) if T[u].rightSibling: setDepth(T[u].rightSibling, p) def findRoot(r): if T[r].parent == -1: return r findRoot(T[r].parent) import sys n = int(sys.stdin.readline()) T = [None for i in range(n)] for x in sys.stdin.readlines(): setNode(*list(map(int, x.split()))) r = findRoot(0) setDepth(r, 0) for x in T: x.showInfo()
Traceback (most recent call last): File "/tmp/tmp8jcmmv2l/tmp21dc5mor.py", line 58, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s504083169
p02279
u072053884
1454783019
Python
Python3
py
Runtime Error
20
7868
1813
"""Rooted Trees.""" class Node: def __init__(self, num, parent, rightSibling, *children): self.id = num self.parent = parent self.rightSibling = rightSibling self.children = list(children) self.depth = 0 def showInfo(self): print('node {0}: '.format(self.id), end = '') print('parent = {0}, '.format(self.parent), end = '') print('depth = {0}, '.format(self.depth), end = '') if self.children and self.parent != -1: print('internal node, ', end = '') elif self.parent != -1: print('leaf, ', end = '') else: print('root, ', end = '') print('{0}'.format(self.children)) def setNode(num, k, *children): if T[num]: T[num].children = list(children) else: node = Node(num, -1, None, *children) T[num] = node if children: for i, x in enumerate(children[:-1]): if T[x]: T[x].parent = num T[x].rightSibling = children[i + 1] else: node = Node(x, num, children[i + 1]) T[x] = node lastChild = children[-1] if T[lastChild]: T[lastChild].parent = num else: node = Node(lastChild, num, None) T[lastChild] = node def setDepth(u, p): T[u].depth = p if T[u].children: setDepth(T[u].children[0], p + 1) if T[u].rightSibling != None: setDepth(T[u].rightSibling, p) def findRoot(r): if T[r].parent == -1: return r return findRoot(T[r].parent) import sys n = int(sys.stdin.readline()) T = [None for i in range(n)] for x in sys.stdin.readlines(): setNode(*list(map(int, x.split()))) r = findRoot(0) setDepth(r, 0) for x in T: x.showInfo()
Traceback (most recent call last): File "/tmp/tmpk3lf91tg/tmpcowyiqff.py", line 58, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s584455858
p02279
u072053884
1454783492
Python
Python3
py
Runtime Error
660
90272
1844
"""Rooted Trees.""" class Node: def __init__(self, num, parent, rightSibling, *children): self.id = num self.parent = parent self.rightSibling = rightSibling self.children = list(children) self.depth = 0 def showInfo(self): print('node {0}: '.format(self.id), end = '') print('parent = {0}, '.format(self.parent), end = '') print('depth = {0}, '.format(self.depth), end = '') if self.children and self.parent != -1: print('internal node, ', end = '') elif self.parent != -1: print('leaf, ', end = '') else: print('root, ', end = '') print('{0}'.format(self.children)) def setNode(num, k, *children): if T[num]: T[num].children = list(children) else: node = Node(num, -1, None, *children) T[num] = node if children: for i, x in enumerate(children[:-1]): if T[x]: T[x].parent = num T[x].rightSibling = children[i + 1] else: node = Node(x, num, children[i + 1]) T[x] = node lastChild = children[-1] if T[lastChild]: T[lastChild].parent = num else: node = Node(lastChild, num, None) T[lastChild] = node def setDepth(u, p): T[u].depth = p if T[u].children: setDepth(T[u].children[0], p + 1) if T[u].rightSibling != None: setDepth(T[u].rightSibling, p) def findRoot(r): if T[r].parent == -1: return r return findRoot(T[r].parent) import sys sys.setrecursionlimit(100000) n = int(sys.stdin.readline()) T = [None for i in range(n)] for x in sys.stdin.readlines(): setNode(*list(map(int, x.split()))) r = findRoot(0) setDepth(r, 0) for x in T: x.showInfo()
Traceback (most recent call last): File "/tmp/tmp8jy8ww40/tmpkyl6x4kf.py", line 60, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s098971326
p02279
u072053884
1454783544
Python
Python3
py
Runtime Error
570
90472
1845
"""Rooted Trees.""" class Node: def __init__(self, num, parent, rightSibling, *children): self.id = num self.parent = parent self.rightSibling = rightSibling self.children = list(children) self.depth = 0 def showInfo(self): print('node {0}: '.format(self.id), end = '') print('parent = {0}, '.format(self.parent), end = '') print('depth = {0}, '.format(self.depth), end = '') if self.children and self.parent != -1: print('internal node, ', end = '') elif self.parent != -1: print('leaf, ', end = '') else: print('root, ', end = '') print('{0}'.format(self.children)) def setNode(num, k, *children): if T[num]: T[num].children = list(children) else: node = Node(num, -1, None, *children) T[num] = node if children: for i, x in enumerate(children[:-1]): if T[x]: T[x].parent = num T[x].rightSibling = children[i + 1] else: node = Node(x, num, children[i + 1]) T[x] = node lastChild = children[-1] if T[lastChild]: T[lastChild].parent = num else: node = Node(lastChild, num, None) T[lastChild] = node def setDepth(u, p): T[u].depth = p if T[u].children: setDepth(T[u].children[0], p + 1) if T[u].rightSibling != None: setDepth(T[u].rightSibling, p) def findRoot(r): if T[r].parent == -1: return r return findRoot(T[r].parent) import sys sys.setrecursionlimit(1000000) n = int(sys.stdin.readline()) T = [None for i in range(n)] for x in sys.stdin.readlines(): setNode(*list(map(int, x.split()))) r = findRoot(0) setDepth(r, 0) for x in T: x.showInfo()
Traceback (most recent call last): File "/tmp/tmpf_pgoop3/tmpd8o2cy9o.py", line 60, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s695448265
p02279
u341533698
1454852279
Python
Python
py
Runtime Error
10
6488
1401
import sys n = int(raw_input()) #class of node class Node: def __init__(self): self.p = -1 self.l = -1 self.r = -1 T = [ Node() for _ in xrange(n)] #info of u D = [0] * n #depth of u def printInfo(u): #print 'node', u, ':', #print 'parent = ', T[u].p, ',', #print 'depth = ', D[u], ',', print "node {}: parent = {}, depth = {},".format(u, T[u].p, D[u]) , if T[u].p == -1: print 'root, ', elif T[u].l == -1: print 'leaf, ', else: print 'internal node, ', #print '[', sys.stdout.write("[") c = T[u].l i = 0 while c != -1: if i > 0: print ', ', sys.stdout.write(str(c)) #print "{}".format(c), c = T[c].r i += 1 #print ']' sys.stdout.write("]\n") return 0 def rec(u, p): D[u] = p if T[u].r != -1: rec(T[u].r, p) if T[u].l != -1: rec(T[u].l, p+1) return def main(): for i in xrange(n): a = map(int, raw_input().split()) v = a[0] d = a[1] for j in xrange(d): if j == 0: T[v].l = a[j+2] else: T[l].r = a[j+2] l = a[j+2] T[a[j+2]].p = v for i in xrange(n): if T[i].p == -1: r = i rec(r, 0) for i in xrange(n): printInfo(i) return 0 main()
File "/tmp/tmpd_z6lsw7/tmp_lx46uzx.py", line 20 print "node {}: parent = {}, depth = {},".format(u, T[u].p, D[u]) , ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
s312818756
p02279
u247976584
1454910478
Python
Python3
py
Runtime Error
30
8184
1579
from collections import deque, namedtuple class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmp25nyll57/tmp1l9t3yim.py", line 35, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s536717301
p02279
u247976584
1454910836
Python
Python3
py
Runtime Error
30
8204
1619
from collections import deque, namedtuple import sys sys.setrecursionlimit(10000) class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmpm6tapa8g/tmptq23dgwt.py", line 37, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s470088129
p02279
u247976584
1454910942
Python
Python3
py
Runtime Error
1060
63832
1620
from collections import deque, namedtuple import sys sys.setrecursionlimit(100000) class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmp5mib4_40/tmpvnrwrbq9.py", line 37, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s282886033
p02279
u247976584
1454911142
Python
Python3
py
Runtime Error
1080
63852
1621
from collections import deque, namedtuple import sys sys.setrecursionlimit(1000000) class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmpuiuvyhkw/tmpnwq3g_in.py", line 37, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s229368194
p02279
u247976584
1454911342
Python
Python3
py
Runtime Error
1080
63404
1623
from collections import deque, namedtuple import sys sys.setrecursionlimit(100000000) class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmp4pdtfpqx/tmp6_3jknuk.py", line 37, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s658952893
p02279
u247976584
1454911545
Python
Python3
py
Runtime Error
1070
63844
1619
from collections import deque, namedtuple import sys sys.setrecursionlimit(1000000000) class RootedTree: def __init__(self, t, n): self.t = t self.n = n self.d = [-1] * n def setDepth(self, u, p): self.d[u] = p if self.t[u].r != -1: self.setDepth(self.t[u].r, p) if self.t[u].l != -1: self.setDepth(self.t[u].l, p + 1) return(self.d) def getChildren(self, u): ret = [] c = self.t[u].l while c != -1: ret.append(c) c = self.t[c].r return(ret) def printNode(self, i): p_ = self.t[i].p d_ = self.d[i] c_ = self.getChildren(i) if p_ == -1: t_ = "root" elif len(c_) == 0: t_ = "leaf" else: t_ = "internal node" print("node {}: parent = {}, depth = {}, {}, {}".format(i, p_, d_, t_, c_)) if __name__ == '__main__': n = int(input().rstrip()) Node = namedtuple('Node', ['p', 'l', 'r']) t = [Node(-1, -1, -1)] * n r = -1 for i in range(n): tmp = deque([int(i) for i in input().rstrip().split(" ")]) v = tmp.popleft() d = tmp.popleft() for j in range(d): c = tmp.popleft() if j == 0: t[v] = t[v]._replace(l = c) else: t[l] = t[l]._replace(r = c) l = c t[c] = t[c]._replace(p = v) for i in range(n): if (t[i].p == -1): r = i x = RootedTree(t, n) x.setDepth(r, 0) for i in range(n): x.printNode(i)
Traceback (most recent call last): File "/tmp/tmppkxshuoq/tmpkwj184lr.py", line 37, in <module> n = int(input().rstrip()) ^^^^^^^ EOFError: EOF when reading a line
s699996899
p02279
u963402991
1459994124
Python
Python3
py
Runtime Error
0
0
999
class Node: def __init__(self, num, parent, children): self.id = num self.parent = -1 self.depth = 0 self.type = None self.children = children def show_info(self): print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(self.id, self.parent, self.depth,self.type, self.children)) def set_node(i_s): num, children = i_s[0], i_s[2:] node = Node(num, -1, children) T[num] = node for n in children: T[-1] -= n def set_pdt(n_i, parent, depth): node = T[n_i] node.parent = parent node.depth = depth if node.children: node.type = 'internal node' for n in node.children: set_pdt(n, n_i, depth + 1) else: node.type = 'leaf' n = int(input()) tree = [list(map(int, input().split())) for i in range(n)] T = [None] * n T += [int(n * (n - 1) / 2)] for i in range(n): set_node(tree[i]) set_pdt(1, -1, 0) T[0].type ='root' for n in T[:-1]: n.show_info()
Traceback (most recent call last): File "/tmp/tmp1l342ksy/tmprdrcm729.py", line 35, in <module> n = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s476940978
p02279
u317901693
1477022668
Python
Python3
py
Runtime Error
0
0
1603
# -*- coding: utf-8 -*- class Node(object): # left????????¨??????????????????(leaf), right???s?????¨?????????????????????????????? # ???????????????????????????????????¨???????????´??????parent???-1????????? def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [-1 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children #f = open("input.txt") #N = int(f.readline()) N = input() T = Node(N) for j in range(N): #A = [int(i) for i in f.readline().split()] A = [int(i) for i in input().readline().split()] # left????±???? if len(A) > 2: T.l[j] = A[2] else: T.l[j] = -1 # parent???right????±???? for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(0, 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmp8xs1miyu/tmpsid3fikk.py:14: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmp8xs1miyu/tmpsid3fikk.py:16: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmp8xs1miyu/tmpsid3fikk.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp8xs1miyu/tmpsid3fikk.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp8xs1miyu/tmpsid3fikk.py:55: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmp8xs1miyu/tmpsid3fikk.py:57: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmp8xs1miyu/tmpsid3fikk.py", line 31, in <module> N = input() ^^^^^^^ EOFError: EOF when reading a line
s074616888
p02279
u317901693
1477022784
Python
Python3
py
Runtime Error
0
0
1303
class Node(object): def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [-1 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().readline().split()] # left????±???? if len(A) > 2: T.l[j] = A[2] else: T.l[j] = -1 # parent???right????±???? for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(0, 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmp0u9puc9w/tmpvddknya5.py:10: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmp0u9puc9w/tmpvddknya5.py:12: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmp0u9puc9w/tmpvddknya5.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp0u9puc9w/tmpvddknya5.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp0u9puc9w/tmpvddknya5.py:46: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmp0u9puc9w/tmpvddknya5.py:48: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmp0u9puc9w/tmpvddknya5.py", line 24, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s562523852
p02279
u317901693
1477022822
Python
Python3
py
Runtime Error
0
0
1251
class Node(object): def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [-1 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().readline().split()] if len(A) > 2: T.l[j] = A[2] else: T.l[j] = -1 for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(0, 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmpxl9h4ouh/tmpvajhrjcx.py:10: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmpxl9h4ouh/tmpvajhrjcx.py:12: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmpxl9h4ouh/tmpvajhrjcx.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpxl9h4ouh/tmpvajhrjcx.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpxl9h4ouh/tmpvajhrjcx.py:44: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmpxl9h4ouh/tmpvajhrjcx.py:46: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmpxl9h4ouh/tmpvajhrjcx.py", line 24, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s155269556
p02279
u317901693
1477023278
Python
Python3
py
Runtime Error
0
0
1264
class Node(object): def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [-1 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().split()] if len(A) > 2: T.l[j] = A[2] else: T.l[j] = -1 for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(T.p.index(None), 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmpzii264k9/tmpktberl1o.py:10: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmpzii264k9/tmpktberl1o.py:12: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmpzii264k9/tmpktberl1o.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpzii264k9/tmpktberl1o.py:18: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpzii264k9/tmpktberl1o.py:44: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmpzii264k9/tmpktberl1o.py:46: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmpzii264k9/tmpktberl1o.py", line 24, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s206480495
p02279
u317901693
1477024099
Python
Python3
py
Runtime Error
20
7792
1522
# -*- coding: utf-8 -*- class Node(object): # left????????¨??????????????????(leaf), right???s?????¨?????????????????????????????? # ???????????????????????????????????¨???????????´??????parent???-1????????? def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [0 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().split()] # left????±???? if len(A) > 2: T.l[A[0]] = A[2] else: T.l[A[0]] = -1 # parent???right????±???? for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(T.p.index(-1), 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmp05hpvmqi/tmpy5xk4ztx.py:14: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmp05hpvmqi/tmpy5xk4ztx.py:16: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmp05hpvmqi/tmpy5xk4ztx.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp05hpvmqi/tmpy5xk4ztx.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp05hpvmqi/tmpy5xk4ztx.py:50: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmp05hpvmqi/tmpy5xk4ztx.py:52: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmp05hpvmqi/tmpy5xk4ztx.py", line 28, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s721720362
p02279
u317901693
1477032244
Python
Python3
py
Runtime Error
0
0
1562
# -*- coding: utf-8 -*- import sys sys.getrecursionlimit(10000) class Node(object): # left????????¨??????????????????(leaf), right???s?????¨?????????????????????????????? # ???????????????????????????????????¨???????????´??????parent???-1????????? def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [0 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().split()] # left????±???? if len(A) > 2: T.l[A[0]] = A[2] else: T.l[A[0]] = -1 # parent???right????±???? for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(T.p.index(-1), 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmpqah3ryt6/tmp77esn4zy.py:15: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmpqah3ryt6/tmp77esn4zy.py:17: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmpqah3ryt6/tmp77esn4zy.py:23: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpqah3ryt6/tmp77esn4zy.py:23: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmpqah3ryt6/tmp77esn4zy.py:52: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmpqah3ryt6/tmp77esn4zy.py:54: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmpqah3ryt6/tmp77esn4zy.py", line 3, in <module> sys.getrecursionlimit(10000) TypeError: sys.getrecursionlimit() takes no arguments (1 given)
s601939799
p02279
u317901693
1477032355
Python
Python3
py
Runtime Error
30
7844
1563
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10000) class Node(object): # left????????¨??????????????????(leaf), right???s?????¨?????????????????????????????? # ???????????????????????????????????¨???????????´??????parent???-1????????? def __init__(self, N): self.p = [-1 for i in range(N)] self.l = [-1 for i in range(N)] self.r = [-1 for i in range(N)] self.D = [0 for i in range(N)] def set_depth(self, u, p): self.D[u] = p if self.r[u] is not -1: self.set_depth(self.r[u], p) if self.l[u] is not -1: self.set_depth(self.l[u], p+1) def print_children(self, u): children = [] flag = self.l[u] while flag is not -1: children.append(flag) flag = self.r[flag] return children N = int(input()) T = Node(N) for j in range(N): A = [int(i) for i in input().split()] # left????±???? if len(A) > 2: T.l[A[0]] = A[2] else: T.l[A[0]] = -1 # parent???right????±???? for index, i in enumerate(A[2:]): if(A[-1] == i): T.p[i], T.r[i] = A[0], -1 else: T.p[i], T.r[i] = A[0], A[index+3] T.set_depth(T.p.index(-1), 0) for i in range(N): if T.p[i] is -1: node = "root" elif T.l[i] is -1: node = "leaf" else: node = "internal node" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(i, T.p[i], T.D[i], node, T.print_children(i)))
/tmp/tmp4l0va1q0/tmpgbkhs0s1.py:17: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.r[u] is not -1: /tmp/tmp4l0va1q0/tmpgbkhs0s1.py:19: SyntaxWarning: "is not" with a literal. Did you mean "!="? if self.l[u] is not -1: /tmp/tmp4l0va1q0/tmpgbkhs0s1.py:25: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp4l0va1q0/tmpgbkhs0s1.py:25: SyntaxWarning: "is not" with a literal. Did you mean "!="? while flag is not -1: /tmp/tmp4l0va1q0/tmpgbkhs0s1.py:53: SyntaxWarning: "is" with a literal. Did you mean "=="? if T.p[i] is -1: /tmp/tmp4l0va1q0/tmpgbkhs0s1.py:55: SyntaxWarning: "is" with a literal. Did you mean "=="? elif T.l[i] is -1: Traceback (most recent call last): File "/tmp/tmp4l0va1q0/tmpgbkhs0s1.py", line 31, in <module> N = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s276554044
p02279
u811733736
1480917355
Python
Python3
py
Runtime Error
0
0
2133
class Node(object): def __init__(self, parent, left, right): self.parent = parent # ???????????? self.left = left # ?????????????????????????????????????????? self.right = right # ??????????????????????????????????????´????????? def get_depth(self): if self.parent == None: return 0 else: depth = 1 t = Nodes[self.parent] while t.parent != -1: t = Nodes[t.parent] depth += 1 return depth def get_type(self): if self.parent == -1: return 'root' elif self.left == None: return 'leaf' else: return 'internal node' def decode_node_data(n): global Nodes num_of_elem = len(n) if num_of_elem < 2: raise ValueError elif num_of_elem == 2: # leaf pass else: id, num_of_children = int(n[0]), int(n[1]) children = n[2:] Nodes[id].left = int(children[0]) prev_child = None for c in children: Nodes[int(c)].parent = id if prev_child != None: Nodes[prev_child].right = int(c) prev_child = int(c) MAX_NODES = 20 Nodes = [Node(-1, None, None) for _ in range(MAX_NODES)] if __name__ == '__main__': # ??????????????\??? num_of_nodes = int(input()) node_data = [] for _ in range(num_of_nodes): node_data.append(input().split(' ')) # ??¨????§£??? for n in node_data: decode_node_data(n) # ???????????¨??? for node_id in range(num_of_nodes): type = Nodes[node_id].get_type() children = [] if type != 'leaf': c = Nodes[node_id].left children.append(c) while Nodes[c].right != None: c = Nodes[c].right children.append(c) print('node {0}: parent = {1}, depth = {2}, {3}, [{4}]'.format(node_id, Nodes[node_id].parent, Nodes[node_id].get_depth(), type, ', '.join(map(str, children))))
Traceback (most recent call last): File "/tmp/tmp0mx7nque/tmpqorglx5c.py", line 50, in <module> num_of_nodes = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s493841072
p02279
u811733736
1480917631
Python
Python3
py
Runtime Error
30
7820
2195
class Node(object): def __init__(self, parent, left, right): self.parent = parent # ???????????? self.left = left # ?????????????????????????????????????????? self.right = right # ??????????????????????????????????????´????????? def get_depth(self): if self.parent == -1: return 0 else: depth = 1 t = Nodes[self.parent] while t.parent != -1: t = Nodes[t.parent] depth += 1 return depth def get_type(self): if self.parent == -1: return 'root' elif self.left == None: return 'leaf' else: return 'internal node' def decode_node_data(n): global Nodes num_of_elem = len(n) if num_of_elem < 2: raise ValueError elif num_of_elem == 2: # leaf pass else: id, num_of_children = int(n[0]), int(n[1]) children = n[2:] Nodes[id].left = int(children[0]) prev_child = None for c in children: Nodes[int(c)].parent = id if prev_child != None: Nodes[prev_child].right = int(c) prev_child = int(c) MAX_NODES = 20 Nodes = [Node(-1, None, None) for _ in range(MAX_NODES)] if __name__ == '__main__': # ??????????????\??? num_of_nodes = int(input()) node_data = [] for _ in range(num_of_nodes): node_data.append(input().split(' ')) # ??¨????§£??? for n in node_data: decode_node_data(n) # ???????????¨??? for node_id in range(num_of_nodes): type = Nodes[node_id].get_type() children = [] if type != 'leaf': if Nodes[node_id].left != None: c = Nodes[node_id].left children.append(c) while Nodes[c].right != None: c = Nodes[c].right children.append(c) print('node {0}: parent = {1}, depth = {2}, {3}, [{4}]'.format(node_id, Nodes[node_id].parent, Nodes[node_id].get_depth(), type, ', '.join(map(str, children))))
Traceback (most recent call last): File "/tmp/tmp6u0naf4x/tmpb31gwo6d.py", line 51, in <module> num_of_nodes = int(input()) ^^^^^^^ EOFError: EOF when reading a line
s035135719
p02279
u923668099
1484735458
Python
Python3
py
Runtime Error
20
7872
1296
import sys nil = -1 class Node: def __init__(self, p, l, r): self.p = p self.l = l self.r = r def depth_rec(u, p, depth): depth[u] = p if tree[u].r != nil: depth_rec(tree[u].r, p, depth) if tree[u].l != nil: depth_rec(tree[u].l, p + 1, depth) pass n = int(sys.stdin.readline()) tree = [Node(nil, nil, nil) for i in range(n)] depth = [0] * n for i in range(n): line = [int(i) for i in sys.stdin.readline().split()] vertex = line[0] for (j, c) in enumerate(line[2:]): if j == 0: tree[vertex].l = c else: tree[l].r = c l = c tree[c].p = vertex ''' for i in range(n): print(tree[i].p, tree[i].l, tree[i].r) ''' for i in range(n): if tree[i].p == nil: root = i depth_rec(root, 0, depth) # print(depth) for vtx in range(n): print("node {}: parent = {}, depth = {}, ".format(vtx, tree[vtx].p, depth[vtx]), end = "") if tree[vtx].p == nil: print("root, ", end = "") elif tree[vtx].l == nil: print("leaf, ", end = "") else: print("internal node, ", end = "") children = [] child = tree[vtx].l while child != nil: children.append(child) child = tree[child].r print(children)
Traceback (most recent call last): File "/tmp/tmps1gxv3l1/tmp_2t52ing.py", line 19, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s160063647
p02279
u923668099
1484735617
Python
Python3
py
Runtime Error
550
72936
1327
import sys sys.setrecursionlimit(10 ** 6) nil = -1 class Node: def __init__(self, p, l, r): self.p = p self.l = l self.r = r def depth_rec(u, p, depth): depth[u] = p if tree[u].r != nil: depth_rec(tree[u].r, p, depth) if tree[u].l != nil: depth_rec(tree[u].l, p + 1, depth) pass n = int(sys.stdin.readline()) tree = [Node(nil, nil, nil) for i in range(n)] depth = [0] * n for i in range(n): line = [int(i) for i in sys.stdin.readline().split()] vertex = line[0] for (j, c) in enumerate(line[2:]): if j == 0: tree[vertex].l = c else: tree[l].r = c l = c tree[c].p = vertex ''' for i in range(n): print(tree[i].p, tree[i].l, tree[i].r) ''' for i in range(n): if tree[i].p == nil: root = i depth_rec(root, 0, depth) # print(depth) for vtx in range(n): print("node {}: parent = {}, depth = {}, ".format(vtx, tree[vtx].p, depth[vtx]), end = "") if tree[vtx].p == nil: print("root, ", end = "") elif tree[vtx].l == nil: print("leaf, ", end = "") else: print("internal node, ", end = "") children = [] child = tree[vtx].l while child != nil: children.append(child) child = tree[child].r print(children)
Traceback (most recent call last): File "/tmp/tmp1846k06f/tmp3skq4zqu.py", line 20, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s045446283
p02279
u923668099
1484735679
Python
Python3
py
Runtime Error
520
72808
1327
import sys sys.setrecursionlimit(10 ** 8) nil = -1 class Node: def __init__(self, p, l, r): self.p = p self.l = l self.r = r def depth_rec(u, p, depth): depth[u] = p if tree[u].r != nil: depth_rec(tree[u].r, p, depth) if tree[u].l != nil: depth_rec(tree[u].l, p + 1, depth) pass n = int(sys.stdin.readline()) tree = [Node(nil, nil, nil) for i in range(n)] depth = [0] * n for i in range(n): line = [int(i) for i in sys.stdin.readline().split()] vertex = line[0] for (j, c) in enumerate(line[2:]): if j == 0: tree[vertex].l = c else: tree[l].r = c l = c tree[c].p = vertex ''' for i in range(n): print(tree[i].p, tree[i].l, tree[i].r) ''' for i in range(n): if tree[i].p == nil: root = i depth_rec(root, 0, depth) # print(depth) for vtx in range(n): print("node {}: parent = {}, depth = {}, ".format(vtx, tree[vtx].p, depth[vtx]), end = "") if tree[vtx].p == nil: print("root, ", end = "") elif tree[vtx].l == nil: print("leaf, ", end = "") else: print("internal node, ", end = "") children = [] child = tree[vtx].l while child != nil: children.append(child) child = tree[child].r print(children)
Traceback (most recent call last): File "/tmp/tmppv35dd2u/tmpa44qe9dm.py", line 20, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s084862864
p02279
u923668099
1484735830
Python
Python3
py
Runtime Error
510
72812
1327
import sys sys.setrecursionlimit(10 ** 9) nil = -1 class Node: def __init__(self, p, l, r): self.p = p self.l = l self.r = r def depth_rec(u, p, depth): depth[u] = p if tree[u].r != nil: depth_rec(tree[u].r, p, depth) if tree[u].l != nil: depth_rec(tree[u].l, p + 1, depth) pass n = int(sys.stdin.readline()) tree = [Node(nil, nil, nil) for i in range(n)] depth = [0] * n for i in range(n): line = [int(i) for i in sys.stdin.readline().split()] vertex = line[0] for (j, c) in enumerate(line[2:]): if j == 0: tree[vertex].l = c else: tree[l].r = c l = c tree[c].p = vertex ''' for i in range(n): print(tree[i].p, tree[i].l, tree[i].r) ''' for i in range(n): if tree[i].p == nil: root = i depth_rec(root, 0, depth) # print(depth) for vtx in range(n): print("node {}: parent = {}, depth = {}, ".format(vtx, tree[vtx].p, depth[vtx]), end = "") if tree[vtx].p == nil: print("root, ", end = "") elif tree[vtx].l == nil: print("leaf, ", end = "") else: print("internal node, ", end = "") children = [] child = tree[vtx].l while child != nil: children.append(child) child = tree[child].r print(children)
Traceback (most recent call last): File "/tmp/tmp8z1aah3d/tmplp1u76dv.py", line 20, in <module> n = int(sys.stdin.readline()) ^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: ''
s462681322
p02279
u564398841
1486285587
Python
Python3
py
Runtime Error
0
0
1187
fin = open('sample.txt') input = fin.readline def main(): N = int(input()) A = [0] * N node_info = [[-1, 0, 'internal node', None] for _ in range(int(1E5 + 1))] for i in range(N): A[i] = [int(i) for i in input().strip().split()] for line in A: if line[1] != 0: node_info[line[0]][3] = line[2:] for c in line[2:]: node_info[c][0] = line[0] for line in A: pid = node_info[line[0]][0] if pid == -1: node_info[line[0]][2] = 'root' else: if node_info[line[0]][3] is None: node_info[line[0]][2] = 'leaf' if node_info[line[0]][3] is None: node_info[line[0]][3] = [''] depth = 0 while pid != -1: depth += 1 pid = node_info[pid][0] node_info[line[0]][1] = depth for line in sorted(A, key=lambda a: a[0]): print('node {}: parent = {}, depth = {}, {}, [{}]'.format( line[0], node_info[line[0]][0], node_info[line[0]][1], node_info[line[0]][2], ', '.join([str(i) for i in node_info[line[0]][3]])) ) if __name__ == '__main__': main()
Traceback (most recent call last): File "/tmp/tmpmjo0qsru/tmpsvyymtfg.py", line 1, in <module> fin = open('sample.txt') ^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'sample.txt'