s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1 value | original_language stringclasses 11 values | filename_ext stringclasses 1 value | status stringclasses 1 value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s696173132 | p04048 | u346194435 | 1555974281 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 2940 | 166 | N,X = map(int, input().split())
if N/2 == X:
print(X*3)
else:
# 上側
l = X + N - X
while X > 0:
l += X*2
X -= 1
l += 1
print(l) |
s934838862 | p04048 | u885899351 | 1555959779 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 62 | n,m=map(int,input().split())
print(n//2*3if n//2=m else n*3-3) |
s717233358 | p04048 | u693716675 | 1555103471 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 296 | n, x = [int(i) for i in input().split()]
cnt=0
short = n%x
long = x
cnt += x*(2*(n//x)-1) + (n-x)
while(1):
c = long % short
a = long //short
if c==0:
break
else:
cnt += short * 2 * a
long = short
short = c
cnt += short * 2 * a -1
print(cnt)
|
s319909280 | p04048 | u684695949 | 1553825473 | Python | Python (3.4.3) | py | Runtime Error | 73 | 3980 | 165 | def f(a,b):
if a==b:
ret = a
elif a < b:
ret = 2*a + f(a,b-a)
else:
ret = 2*b + f(a-b,b)
return ret
N,X = map(int,input().split(" "))
print(N+f(N-X,X))
|
s744545686 | p04048 | u684695949 | 1553741162 | Python | Python (3.4.3) | py | Runtime Error | 72 | 3976 | 157 | def f(a,b):
if a==b:
return 2*a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
N,X = map(int,input().split(" "))
print(N+f(N-X,X)) |
s527203596 | p04048 | u684695949 | 1553741022 | Python | Python (3.4.3) | py | Runtime Error | 78 | 3940 | 267 | def f(a,b):
return 2*a + f_fast(a,b-a)
def f_fast(a,b):
if a==b:
return a+b
elif a < b:
if b%a == 0:
return f(a,b)
else:
d = b//a
return 2*a*d + f_fast(a,b%a)
else:
return f_fast(b,a)
N,X = map(int,input().split(" "))
print(N+f_fast(N-X,X)) |
s861657137 | p04048 | u684695949 | 1553740526 | Python | Python (3.4.3) | py | Runtime Error | 74 | 4212 | 169 | def f(a,b):
print(a,b)
if a==b:
return 2*a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
N,X = map(int,input().split(" "))
print(N+f(N-X,X)) |
s158402728 | p04048 | u697713131 | 1552764602 | Python | PyPy3 (2.4.0) | py | Runtime Error | 304 | 48368 | 189 | n,x = map(int,input().split())
def f(a,b):
if a == b:
return a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(b,a-b)
print(n+f(x,n-x)) |
s368961987 | p04048 | u697713131 | 1552764539 | Python | Python (3.4.3) | py | Runtime Error | 73 | 3980 | 189 | n,x = map(int,input().split())
def f(a,b):
if a == b:
return a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(b,a-b)
print(n+f(x,n-x)) |
s384630814 | p04048 | u697713131 | 1552763546 | Python | Python (3.4.3) | py | Runtime Error | 72 | 3980 | 189 | n,x = map(int,input().split())
def f(a,b):
if a == b:
return a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
print(n+f(x,n-x)) |
s175677841 | p04048 | u761989513 | 1551135753 | Python | Python (3.4.3) | py | Runtime Error | 73 | 3984 | 347 | def solve(s, a, b):
if a % b == 0:
return s + ((a // b) * 2 - 1) * b
if b % a == 0:
return s + ((b // a) * 2 - 1) * a
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(n, n - x, x)) |
s288708942 | p04048 | u761989513 | 1551135053 | Python | Python (3.4.3) | py | Runtime Error | 74 | 3984 | 313 | def solve(s, a, b):
if a == 1:
return s + b * 2 - 1
if b == 1:
return s + a * 2 - 1
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(n, n - x, x)) |
s798109564 | p04048 | u761989513 | 1551134507 | Python | Python (3.4.3) | py | Runtime Error | 1347 | 721644 | 275 | import sys
sys.setrecursionlimit(100000000)
def solve(s, a, b):
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(0, n - x, x) + n) |
s144935227 | p04048 | u761989513 | 1551134354 | Python | Python (3.4.3) | py | Runtime Error | 73 | 3980 | 230 | def solve(s, a, b):
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(0, n - x, x) + n) |
s834018018 | p04048 | u016567570 | 1550032052 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 87 | N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*((X//q) + 1)) |
s294232485 | p04048 | u016567570 | 1550030954 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 85 | N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*(X//q + 1)) |
s345405098 | p04048 | u016567570 | 1550030856 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 106 | #-*-coding: utf-8-*-
N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*(X//q + 1)) |
s737283365 | p04048 | u016567570 | 1550030293 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 109 | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//(N%X)) + 1)) |
s099015926 | p04048 | u016567570 | 1550030228 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 110 | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//(N%X)) + 1)) |
s432698194 | p04048 | u016567570 | 1550029907 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 106 | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//q) + 1)) |
s936674618 | p04048 | u902468164 | 1549753953 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 149 | import fraction
li = [int(i) for i in input().split(" ")]
res = (li[0] // fraction.gcd(li[0], li[1]) -1) * 3 * fraction.gcd(li[0], li[1])
print(res) |
s782042100 | p04048 | u902468164 | 1549753851 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 138 | import math
li = [int(i) for i in input().split(" ")]
res = (li[0] // math.gcd(li[0], li[1]) -1) * 3 * math.gcd(li[0], li[1])
print(res) |
s091075627 | p04048 | u740284863 | 1549594499 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 76 | from fractions
n,x=map(int,input().split())
print(3*(n-fractions.gcd(n,x)))
|
s263588101 | p04048 | u740284863 | 1549594471 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 68 | import math
n,x=map(int,input().split())
print(3*(n-math.gcd(n,x)))
|
s025454084 | p04048 | u740284863 | 1549594337 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 67 | import math
n,x=map(int,input().split())
print(4*(n-math.gcd(n,x))) |
s060716523 | p04048 | u740284863 | 1549594259 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 63 | import math
n,x=map(int,input().split())
print(4*(n-gcd(n,x)))
|
s571418060 | p04048 | u879870653 | 1549582575 | Python | Python (3.4.3) | py | Runtime Error | 1315 | 715252 | 238 | import sys
sys.setrecursionlimit(10**9)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
return 2*b + f(b,a-b)
else :
return a
ans = N + f(X,N-X)
print(ans)
|
s883872348 | p04048 | u879870653 | 1549581937 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 259 | import sys
sys.setrecursionlimit(10**12+1)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
|
s493323134 | p04048 | u879870653 | 1549581713 | Python | Python (3.4.3) | py | Runtime Error | 1297 | 715380 | 256 | import sys
sys.setrecursionlimit(10**9)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
|
s422223228 | p04048 | u879870653 | 1549581646 | Python | Python (3.4.3) | py | Runtime Error | 77 | 3972 | 215 | N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
|
s588470967 | p04048 | u879870653 | 1549581072 | Python | Python (3.4.3) | py | Runtime Error | 75 | 3976 | 198 | N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif b == 0 :
return 0
else :
return ((a//b)*2-1)*b
ans = N + f(X,N-X)
print(ans)
|
s797127141 | p04048 | u631277801 | 1549540394 | Python | Python (3.4.3) | py | Runtime Error | 1944 | 715380 | 634 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**8)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def rec(a: int, b: int) -> int:
if a == b:
return a
else:
mx = max(a,b)
mn = min(a,b)
return 2*mn + rec(mn, mx-mn)
n,x = li()
print(n + rec(x, n-x))
|
s844708469 | p04048 | u631277801 | 1549540351 | Python | Python (3.4.3) | py | Runtime Error | 334 | 98548 | 634 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def rec(a: int, b: int) -> int:
if a == b:
return a
else:
mx = max(a,b)
mn = min(a,b)
return 2*mn + rec(mn, mx-mn)
n,x = li()
print(n + rec(x, n-x))
|
s265781339 | p04048 | u904804404 | 1549251109 | Python | Python (3.4.3) | py | Runtime Error | 224 | 89812 | 231 | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(100000)
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) |
s352575624 | p04048 | u904804404 | 1549251035 | Python | Python (3.4.3) | py | Runtime Error | 99 | 11704 | 230 | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(10000)
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) |
s589582202 | p04048 | u904804404 | 1549250939 | Python | Python (3.4.3) | py | Runtime Error | 73 | 3896 | 191 | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) |
s882265313 | p04048 | u588633699 | 1549250938 | Python | Python (3.4.3) | py | Runtime Error | 19 | 2940 | 139 | N = int(input())
L = list(map(int, input().split()))
L.sort()
x = 0
for i in range(0, 2*N, 2):
print(L[i])
x += L[i]
print(x) |
s623476061 | p04048 | u416522077 | 1548645359 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 459 | import sys
N = int(sys.argv[1])
X = int(sys.argv[2])
rect = [ X, N-X ]
rect_temp = rect
length = 0
while True :
if rect_temp[0] < rect_temp[1]:
length += rect_temp[0]*3
rect_temp = [ rect_temp[0], rect_temp[1]-rect_temp[0] ]
elif rect_temp[0] > rect_temp[1]:
length += rect_temp[1]*3
rect_temp = [ rect_temp[0] - rect_temp[1], rect_temp[0] ]
elif rect_temp[0] == rect_temp[1]:
break
print(length) |
s428704902 | p04048 | u416522077 | 1548644410 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 459 | import sys
N = int(sys.argv[1])
X = int(sys.argv[2])
rect = [ X, N-X ]
rect_temp = rect
length = 0
while True :
if rect_temp[0] < rect_temp[1]:
length += rect_temp[0]*3
rect_temp = [ rect_temp[0], rect_temp[1]-rect_temp[0] ]
elif rect_temp[0] > rect_temp[1]:
length += rect_temp[1]*3
rect_temp = [ rect_temp[0] - rect_temp[1], rect_temp[0] ]
elif rect_temp[0] == rect_temp[1]:
break
print(length) |
s891845339 | p04048 | u690536347 | 1547679722 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 170 | import sys
sys.setrecursionlimit(10**15)
def f(a,b):
if a==b:return a
if not a<b:a,b=b,a
return f(a,b-a)+2*a
N,X=map(int,input().split())
print(f(X,N-X)+N)
|
s286661045 | p04048 | u690536347 | 1547679677 | Python | Python (3.4.3) | py | Runtime Error | 1281 | 689908 | 168 | import sys
sys.setrecursionlimit(10**7)
def f(a,b):
if a==b:return a
if not a<b:a,b=b,a
return f(a,b-a)+2*a
N,X=map(int,input().split())
print(f(X,N-X)+N) |
s393774304 | p04048 | u603234915 | 1547181037 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 162 | N, X = map(int, input())
if X == N//2:
print(N//2 * 3)
elif N % X == 0:
a = max(N-X, X)
b = min(N-X, X)
print(a + a // b * 2)
else:
print(0)
|
s743460939 | p04048 | u631277801 | 1542292389 | Python | Python (3.4.3) | py | Runtime Error | 291 | 98532 | 636 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def light_length(a:int, b:int) -> int:
if a == b:
return a
if a > b:
a,b = b,a
return 2*a + light_length(min(a,b-a), max(a,b-a))
n,x = li()
print(n + light_length(x,n-x)) |
s231663088 | p04048 | u631277801 | 1542292293 | Python | Python (3.4.3) | py | Runtime Error | 327 | 100116 | 599 | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def light_length(a:int, b:int) -> int:
if a == b:
return a
return 2*a + light_length(min(a,b-a), max(a,b-a))
n,x = li()
print(n + light_length(x,n-x)) |
s681918282 | p04048 | u368780724 | 1542138871 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 98 | N, X = [int(i) for i in input().split()]
import math
gcd = math.gcd(N, X)
print(gcd*(N//gcd-1)*3) |
s811676658 | p04048 | u328207927 | 1541776657 | Python | Python (3.4.3) | py | Runtime Error | 20 | 2940 | 75 | import math
n,x=map(int,input().strip().split())
print(3*(n-math.gcd(n,x))) |
s241157045 | p04048 | u328207927 | 1541776278 | Python | Python (3.4.3) | py | Runtime Error | 2103 | 3060 | 189 | n,x=map(int,input().strip().split())
z=n-2*x
y=n-x
an=0
an+=3*x+y
an+=z*(x//z+1)
#x=x//z
#z-=2*x
while not z<x:
an+=z*(x//z+1)
if not x%z==0:
an+=1
z-=2*x
print(an) |
s772768992 | p04048 | u393558821 | 1541479806 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 61 | #Include <bits/stdc++.h>
using namespace std;
int main(){
} |
s873049898 | p04048 | u533885955 | 1540082829 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 54 | a,b = map(int,input().split())
s = a/b
print(3b*(s-1)) |
s764156874 | p04048 | u619819312 | 1538927545 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 75 | from fractions import gcd
n,m=map(int,input().split())
print(3*(n-gcd(n,m)) |
s373246359 | p04048 | u667024514 | 1538852398 | Python | Python (3.4.3) | py | Runtime Error | 40 | 5304 | 82 | n,x = map(int,input().split())
import fractions
print+(3 * (n-fractions.gcd(n,x))) |
s255311561 | p04048 | u393481615 | 1535875608 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 85 | import math
[N, X] = list(map(int, input().split()))
print(int(3*(N-math.gcd(N,X))))
|
s048338925 | p04048 | u334712262 | 1534700985 | Python | Python (3.4.3) | py | Runtime Error | 42 | 5688 | 1458 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, X):
if X == N//2:
return 3*X
ans = 0
if X > N//2:
X = N-X
ans = X
def f(n, x):
ans = 0
ans += n
n_x = n // x
ans += 2*n_x*x - x
if n_x % x != 0:
ans += f(x, n - n_x*x)
# print(n, x, n_x, 2*n_x*x - x, ans)
return ans
return ans + f(N-X, X)
def main():
N, X = read_int_n()
print(slv(N, X))
if __name__ == '__main__':
main()
|
s154799118 | p04048 | u334712262 | 1534700839 | Python | PyPy3 (2.4.0) | py | Runtime Error | 295 | 62700 | 1421 | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, X):
ans = 0
if X > N//2:
X = N-X
ans = X
def f(n, x):
ans = 0
ans += n
n_x = n // x
ans += 2*n_x*x - x
if n_x % x != 0:
ans += f(x, n - n_x*x)
# print(n, x, n_x, 2*n_x*x - x, ans)
return ans
return ans + f(N-X, X)
def main():
N, X = read_int_n()
print(slv(N, X))
if __name__ == '__main__':
main()
|
s887363089 | p04048 | u745087332 | 1531529575 | Python | Python (3.4.3) | py | Runtime Error | 76 | 3948 | 386 | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return (b//a*2 - 1)*a
else:
return 2*a + func(a, b-a)
elif a > b:
if a%b == 0:
return (a//b*2 - 1)*b
else:
return 2*b + func(a-b, b)
else:
return a
if x == n/2:
print(3*x)
else:
print(x+(n-x)+func(x,n-x)) |
s430977308 | p04048 | u745087332 | 1531529110 | Python | Python (3.4.3) | py | Runtime Error | 75 | 3948 | 307 | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return b//a*2 - 1
else:
return 2*a + func(a, b-a)
else:
if a%b == 0:
return a//b*2 - 1
else:
return 2*b + func(a-b, b)
print(x+(n-x)+func(x,n-x)) |
s836690284 | p04048 | u745087332 | 1531528879 | Python | Python (3.4.3) | py | Runtime Error | 74 | 3952 | 355 | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return b/a*2 - 1
else:
return 2*a + func(a, b-a)
else:
if a%b == 0:
return a/b*2 - 1
else:
return 2*b + func(a-b, b)
if x == n/2:
print(3*x)
else:
print(x+(n-x)+func(x,n-x)) |
s111435103 | p04048 | u278479217 | 1528601400 | Python | PyPy3 (2.4.0) | py | Runtime Error | 369 | 49260 | 399 | #!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)
N, X = map(int, input().split())
def f(x, n):
debug(x,n)
# if 2*x == n:
# return 3*x
if x % (n-x) == 0:
return 3*x
if 2*x < n:
return f(x, n-x) + 3*x# n + x
a = x//(n-x) + 1
t = a*(n-x) - x
return f(n-x-t, n-x) + 3*x # + t
print(f(X, N))
|
s256155392 | p04048 | u315078622 | 1528248306 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 81 | from math import gcd
N, X = map(int, input().split())
print(3 * (N - gcd(N, X)))
|
s005205942 | p04048 | u304608668 | 1526079859 | Python | Python (3.4.3) | py | Runtime Error | 80 | 3980 | 483 | """
a
+ -------
| b-a / / f(a, b) = 2*a + f(a, b-a)
| / / answer = N + f(X, N-X)
b ------- COMD(a < b)
| / \ /
| / \ /
| / \/
+ -------
"""
#--- define function ---#
def calc(a, b):
if a > b:
a, b = b, a
if a == b:
return a
else:
return 2 * a + calc(a, b - a)
#--- main ---#
N, X = input().split()
N, X = int(N), int(X)
ans = N + calc(X, N - X)
print(ans)
|
s002545282 | p04048 | u562016607 | 1523486598 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 120 | def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X))
|
s352506225 | p04048 | u562016607 | 1523486579 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 120 | def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b):
N,X=map(int,input().split())
print(3*(N-gcd(N,X)) |
s580800768 | p04048 | u050024609 | 1519882185 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 79 | from math import gcd
N, X=map(int, input().split())
print(3*(N - gcd(N, X)))
|
s144543736 | p04048 | u830390742 | 1516806509 | Python | Python (2.7.6) | py | Runtime Error | 24 | 3508 | 216 | def calc(a, b):
if a <= 0 or b <= 0:
return 0
if a == b:
return a
a, b = min(a, b), max(a, b)
return calc(b-a, a) + 2 * a
N, X = map(int, raw_input().split())
print calc(X, N-X) + N
|
s510904734 | p04048 | u325562015 | 1505098205 | Python | Python (3.4.3) | py | Runtime Error | 75 | 3960 | 425 | '''def f(a, b):
if a * b == 0:
return 0
res = f(min(a, b), max(a, b) % min(a, b)) + 2 * min(a, b) * (max(a,b)//min(a, b))
if(max(a, b) % min(a, b) == 0):
res -= 1
return res'''
def f(a, b):
if(a - b == 0):
return a
if(a * b == 0):
return 0
return 2 * min(a, b) + f(min(a, b), max(a,b) - min(a, b))
n, x = map(int, input().split())
res = n + f(n - x, x)
print(res)
|
s002373403 | p04048 | u325562015 | 1505098113 | Python | Python (3.4.3) | py | Runtime Error | 75 | 3964 | 448 | '''def f(a, b):
if a * b == 0:
return 0
res = f(min(a, b), max(a, b) % min(a, b)) + 2 * min(a, b) * (max(a,b)//min(a, b))
if(max(a, b) % min(a, b) == 0):
res -= 1
return res'''
def f(a, b):
minn = min(a, b)
maxx = max(a, b)
if(a - b == 0):
return a
if(a * b == 0):
return 0
return 2 * minn + f(minn, maxx - minn)
n, x = map(int, input().split())
res = n + f(n - x, x)
print(res)
|
s949167797 | p04048 | u998273299 | 1503676015 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 171 | #! /bin/python
# coding:utf-8
import sys
def gcd(N, X):
while X:
N, X = X, N % X
return N
N = int(sys.argv[1])
X = int(sys.argv[2])
print 3 * (N - (gcd(N, X)))
|
s131059688 | p04048 | u998273299 | 1503675661 | Python | Python (2.7.6) | py | Runtime Error | 14 | 2820 | 152 | #! /bin/python
# coding:utf-8
def gcd(N, X):
while X:
N, X = X, N % X
return N
N, X = map(int, raw_input().split())
print = 3 * (N - (gcd(N, X)))
|
s373823028 | p04048 | u884847580 | 1500467252 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 302 | L = map(int, raw_input().split())
n = L[0]
x = L[1]
res = n
a = x
b = n-x
flag = True
while flag :
if a > b:
q = a // b
a -= q*b
res += 2*q*b
elif b > a:
q = b // a
b -= q*a
res += 2*a*q
else:
res += a
flag = False
print(res) |
s532964684 | p04048 | u375536288 | 1499652887 | Python | Python (2.7.6) | py | Runtime Error | 10 | 2568 | 180 | def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
N = int(raw_input())
k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans) |
s544302779 | p04048 | u986399983 | 1490150866 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 46 | N, X = int(input()), int(input())
print(X * 6) |
s183172898 | p04048 | u579875569 | 1469306268 | Python | Python (3.4.3) | py | Runtime Error | 40 | 3064 | 260 | #!/usr/bin/python3
import sys
sys.setrecursionlimit(1000000)
N, X = list(map(int, input().split()))
def f(a,b):
if a > b:
a,b = b,a
if b%a is 0:
return int(a*(2*(b/a)-1))
return int(2*a*int(b/a) + f(a,b%a))
print(N+f(N-X, X))
|
s825196794 | p04048 | u579875569 | 1469306185 | Python | Python (3.4.3) | py | Runtime Error | 40 | 3064 | 259 | #!/usr/bin/python3
import sys
sys.setrecursionlimit(100000)
N, X = list(map(int, input().split()))
def f(a,b):
if a > b:
a,b = b,a
if b%a is 0:
return int(a*(2*(b/a)-1))
return int(2*a*int(b/a) + f(a,b%a))
print(N+f(N-X, X))
|
s754744111 | p04048 | u477320129 | 1468728474 | Python | Python (3.4.3) | py | Runtime Error | 183 | 4468 | 241 | import sys
sys.setrecursionlimit(1500)
def f(x, y):
if x == 0:
return 0
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * x + f(x, y - x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
|
s191680008 | p04048 | u477320129 | 1468728321 | Python | Python (3.4.3) | py | Runtime Error | 46 | 3116 | 220 | import sys
sys.setrecursionlimit(1500)
def f(x, y):
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * (y // x) * x + f(x, y % x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
|
s472515885 | p04048 | u477320129 | 1468728096 | Python | Python (3.4.3) | py | Runtime Error | 185 | 4004 | 169 | def f(x, y):
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * x + f(x, y - x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
|
s034131434 | p04048 | u941268675 | 1468723030 | Python | Python (2.7.6) | py | Runtime Error | 80 | 3552 | 177 | def f(a, b):
if a == 1 and b == 1:
return 1
r = min(a, b)
q = max(a, b)
return 2*r + f(r, q-r)
N, X = map(int, raw_input().split())
print N + f(X, N-X) |
s046359757 | p04048 | u810735437 | 1468719159 | Python | Python (3.4.3) | py | Runtime Error | 223 | 4644 | 490 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import functools
def gcd(a, b):
while b:
a, b = b, a % b
return a
@functools.lru_cache(maxsize = None)
def func(N, X):
g = gcd(N, X)
if g == 1:
if X > N // 2:
return func(N, N - X)
if N == 2:
return 3
if N == 3:
return 6
return X * 3 + func(N-X, X)
else:
return g * func(N//g, X//g)
N,X = map(int,input().split())
print(func(N,X))
|
s124680257 | p04048 | u810735437 | 1468719056 | Python | Python (3.4.3) | py | Runtime Error | 302 | 4556 | 492 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import functools
def gcd(a, b):
while b:
a, b = b, a % b
return a
@functools.lru_cache(maxsize = None)
def func(N, X):
g = gcd(N, X)
if g == 1:
if X > N // 2:
return func(N, N - X)
if N == 2:
return 3
if N == 3:
return 6
return X * 3 + func(N-X, X)
else:
return g * func(N//g, X//g)
N,X = map(int,input().split())
print(func(N,X))
|
s412168424 | p04048 | u945080461 | 1468718591 | Python | Python (2.7.6) | py | Runtime Error | 29 | 2568 | 87 | n, x = map(int, raw_input().split())
g = gcd(n, x)
n /= g
x /= g
print 3 * (n - 1) * g
|
s315910061 | p04049 | u535803878 | 1593985757 | Python | PyPy3 (7.3.0) | py | Runtime Error | 108 | 78304 | 1209 | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
from collections import defaultdict
n,k = map(int, input().split())
ns = defaultdict(set)
for _ in range(n-1):
u,v = map(int, input().split())
u -= 1
v -= 1
ns[u].add(v)
ns[v].add(u)
def bfs(start):
from queue import deque
q = deque([start])
seen = [None] * n
seen[start] = 0
dist = defaultdict(list)
dist[0].append(start)
while q:
u = q.pop()
d = seen[u]
for v in ns[u]:
if seen[v] is None and v not in done:
seen[v] = d + 1
dist[d+1].append(v)
q.appendleft(v)
return seen, dist
ans = 0
done = set()
while True:
start = 0
while start in done:
start += 1
seen, dist1 = bfs(start)
m = max(item for item in seen if item is not None)
u = dist1[m][0]
seen, dist1 = bfs(u)
mm = max(item for item in seen if item is not None)
if mm<=k:
break
ans += 1
v = dist[mm][0]
seen, dist2 = bfs(v)
if dist1[mm]<dist2[mm]:
done.add(v)
else:
done.add(u)
print(ans) |
s994436547 | p04049 | u340781749 | 1588711344 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4956 | 1024 | import sys
from collections import deque
def bfs(links, s, limit):
not_reachable = (1 << len(links)) - 1
q = deque([(0, s, -1)])
pop = q.popleft
extend = q.extend
while q:
cost, v, p = pop()
if cost > limit:
break
not_reachable ^= 1 << v
cost += 1
extend((cost, u, v) for u in links[v] if u != p)
return not_reachable
def solve(n, k, ab):
if k == 1:
return n - 2
links = [set() for _ in range(n)]
link_list = []
for a, b in ab:
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
limit = k // 2
if k % 2 == 0:
ans = min(bin(bfs(links, v, limit)).count('1') for v in range(n))
else:
dists = [bfs(links, v, limit) for v in range(n)]
ans = min(bin(dists[a] & dists[b]).count('1') for a, b in ab)
return ans
n, k = map(int, sys.stdin.buffer.readline().split())
ab = map(int, sys.stdin.buffer.read().split())
ab = list(zip(ab, ab))
print(solve(n, k, ab))
|
s748681090 | p04049 | u340781749 | 1588711257 | Python | Python (3.4.3) | py | Runtime Error | 23 | 4084 | 1085 | import sys
from collections import deque
def bfs(links, s, limit):
not_reachable = (1 << len(links)) - 1
q = deque([(0, s, -1)])
pop = q.popleft
extend = q.extend
while q:
cost, v, p = pop()
if cost > limit:
break
not_reachable ^= 1 << v
cost += 1
extend((cost, u, v) for u in links[v] if u != p)
return not_reachable
def solve(n, k, ab):
if k == 1:
return n - 2
links = [set() for _ in range(n)]
link_list = []
for a, b in zip(ab[0::2], ab[1::2]):
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
link_list.append((a, b))
limit = k // 2
if k % 2 == 0:
ans = min(bin(bfs(links, v, limit)).count('1') for v in range(n))
else:
dists = [bfs(links, v, limit) for v in range(n)]
ans = min(bin(dists[a] & dists[b]).count('1') for a, b in link_list)
return ans
n, k = map(int, sys.stdin.buffer.readline().split())
ab = map(int, sys.stdin.buffer.read().split())
ab = list(zip(ab, ab))
print(solve(n, k, ab))
|
s938174787 | p04049 | u340781749 | 1588710413 | Python | Python (3.4.3) | py | Runtime Error | 2106 | 35700 | 1024 | import sys
from collections import deque, defaultdict
def bfs(links, s, limit):
not_reachable = [True] * len(links)
q = deque([(0, s, -1)])
while q:
cost, v, p = q.popleft()
if cost > limit:
break
not_reachable[v] = False
cost += 1
q.extend((cost, u, v) for u in links[v] if u != p)
return not_reachable
def solve(n, k, ab):
if k == 1:
return n - 2
links = [set() for _ in range(n)]
for a, b in zip(ab[0::2], ab[1::2]):
a -= 1
b -= 1
links[a].add(b)
links[b].add(a)
ans = n
thr = k // 2
if k % 2 == 0:
ans = min(sum(bfs(links, v, thr) for v in range(n)))
else:
dists = [bfs(links, v, thr) for v in range(n)]
for a, b in zip(ab[0::2], ab[1::2]):
a -= 1
b -= 1
ans = min(ans, sum(d1 and d2 for d1, d2 in zip(dists[a], dists[b])))
return ans
n, k, *ab = map(int, sys.stdin.buffer.read().split())
print(solve(n, k, ab))
|
s369512498 | p04049 | u693716675 | 1583471525 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4316 | 1311 | #C
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for i in range(n-1):
a,b = [int(j) for j in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
def dfs(u, cost):
if dist[u]>=0: #if searched already
return
dist[u] = cost
e = edges[u]
for v in e:
dfs(v, cost+1)
ans = n
#when k is even, we should think about each node
if k%2==0:
for u in range(n):
dist = [-1]*n #if -1, it means not visited yet
dfs(u,0)
cnt = 0
for v in dist:
if v<=(k//2):
cnt += 1
ans = min(ans, n-cnt)
#when k is even, we should think about each edge
else:
for u,e in enumerate(edges):
for v in e:
cnt = 0
dist = [-1]*n #if -1, it means not visited yet
dist[v] = 0
dfs(u,0)
for v in dist:
if v<=(k//2):
cnt += 1
dist = [-1]*n #if -1, it means not visited yet
dist[u] = 0
dfs(v,0)
for v in dist:
if v<=(k//2):
cnt += 1
cnt -= 2
ans = min(ans, n-cnt)
print(ans)
|
s434611661 | p04049 | u693716675 | 1583471146 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4328 | 1520 | #C
n,k = [int(i) for i in input().split()]
edges = [[] for _ in range(n)]
for i in range(n-1):
a,b = [int(j) for j in input().split()]
edges[a-1].append(b-1)
edges[b-1].append(a-1)
ans = n
#when k is even, we should think about each node
if k%2==0:
def dfs(u, cost):
if dist[u]>=0: #if searched already
return
dist[u] = cost
e = edges[u]
for v in e:
dfs(v, cost+1)
for u in range(n):
dist = [-1]*n #if -1, it means not visited yet
dfs(u,0)
cnt = 0
for v in dist:
if v>(k//2):
cnt += 1
ans = min(ans, cnt)
print(ans)
#when k is even, we should think about each edge
else:
def dfs(u, cost):
if dist[u]>=0: #if searched already
return
dist[u] = cost
e = edges[u]
for v in e:
dfs(v, cost+1)
for u,e in enumerate(edges):
for v in e:
cnt = 0
dist = [-1]*n #if -1, it means not visited yet
dist[v] = 0
dfs(u,0)
for v in dist:
if v>(k//2):
cnt += 1
dist = [-1]*n #if -1, it means not visited yet
dist[u] = 0
dfs(v,0)
for v in dist:
if v>(k//2):
cnt += 1
ans = min(ans, cnt)
print(ans)
|
s296170347 | p04049 | u076506345 | 1581785258 | Python | Python (3.4.3) | py | Runtime Error | 91 | 4672 | 1814 | n, k = map(int, input().split())
tree = [[] for i in range(n)]
for _ in range(n - 1):
a, b = sorted(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
def search(tree, pos, past=None, depth=0):
"""
子孫ノードを探索して、最深のノードとその深さを返す
"""
# 子ノードを探索する
ress = [] # 子ノードの探索結果
for next_node in tree[pos]:
# next_nodeが親なら探索しない
if next_node == past:
continue
res = search(tree, next_node, pos, depth + 1)
ress.append(res)
ress.sort(reverse=True)
# 子ノードがいないならばこのノードとその深さを返す
if len(ress) == 0:
ress = [[depth, pos]]
return ress[0]
def countChildren(tree, pos):
"""
ノードposを根ノードとした場合の
深さ毎のノードを数える
"""
def dfs(tree, pos, child_list=[], past=None, depth=0):
child_list += [0] * (depth + 1 - len(child_list))
child_list[depth] += 1
# 子ノードを探索する
for next_node in tree[pos]:
# next_nodeが親なら探索しない
if next_node == past:
continue
dfs(tree, next_node, child_list, pos, depth + 1)
child_list = []
dfs(tree, pos, child_list)
return child_list[:]
# 最遠頂点対 u,vと直径diameterを求める
_, u = search(tree, 0)
diameter, v = search(tree, u)
# u,vを頂点ノードとしたときの深さ毎のノードを数える
u_list = countChildren(tree, u)
v_list = countChildren(tree, v)
# 縮める木の直径の長さ
clip_len = max(diameter - k, 0)
u_ans = sum(u_list[-clip_len:])
v_ans = sum(v_list[-clip_len:])
print(min(u_ans, v_ans))
|
s989027159 | p04049 | u076506345 | 1581784614 | Python | Python (3.4.3) | py | Runtime Error | 92 | 4672 | 1893 | n, k = map(int, input().split())
tree = [[] for i in range(n)]
for _ in range(n - 1):
a, b = sorted(map(int, input().split()))
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
def search(tree, pos, past=None, depth=0):
"""
子孫ノードを探索して、最深のノードとその深さを返す
"""
# 子ノードを探索する
ress = [] # 子ノードの探索結果
for next_node in tree[pos]:
# next_nodeが親なら探索しない
if next_node == past:
continue
res = search(tree, next_node, pos, depth + 1)
ress.append(res)
ress.sort(reverse=True)
# 子ノードがいないならばこのノードとその深さを返す
if len(ress) == 0:
ress = [[depth, pos]]
return ress[0]
def countChildren(tree, pos):
"""
ノードposを根ノードとした場合の
深さ毎のノードを数える
"""
def dfs(tree, pos, child_list=[], past=None, depth=0):
child_list += [0] * (depth + 1 - len(child_list))
child_list[depth] += 1
# 子ノードを探索する
for next_node in tree[pos]:
# next_nodeが親なら探索しない
if next_node == past:
continue
dfs(tree, next_node, child_list, pos, depth + 1)
child_list = []
dfs(tree, pos, child_list)
return child_list[:]
# 最遠頂点対 u,vと直径diameterを求める
_, u = search(tree, 0)
diameter, v = search(tree, u)
# u,vを頂点ノードとしたときの深さ毎のノードを数える
u_list = countChildren(tree, u)
v_list = countChildren(tree, v)
removed_nodes = 0
while diameter > k:
if u_list[-1] < v_list[-1]:
removed_nodes += u_list[-1]
u_list.pop()
else:
removed_nodes += v_list[-1]
v_list.pop()
diameter -= 1
print(removed_nodes)
|
s406256226 | p04049 | u803848678 | 1576341539 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1475 | 119260 | 763 | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n,k = map(int, input().split())
G = [[] for i in range(n)]
edges = []
for i in range(n-1):
a,b = map(int, input().split())
a,b = a-1,b-1
G[a].append(b)
G[b].append(a)
edges.append((a,b))
cnt = [0]
def search(cur, prev, depth, k):
if depth > k:
cnt[0] += 1
for to in G[cur]:
if to != prev:
search(to, cur, depth+1, k)
ans = float("inf")
# 点中心
if k % 2 == 0:
for i in range(n):
cnt = [0]
search(i, -1, 0, k//2)
ans = min(ans, cnt[0])
# 辺中心
else:
for a, b in edges:
cnt = [0]
search(a, b, 0, k//2)
search(b, a, 0, k//2)
ans = min(ans, cnt[0])
print(ans) |
s510777512 | p04049 | u495699318 | 1573878803 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 1872 | #include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
#define INF 1e9+7
#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;
vector<vec> G;
int n,k;
int dfs(int e,int x,int t);
int calc(int x){
int res=INF;
for(auto e:G[x]){
res=min(n-1-dfs(e,x,1),res);
}
return res;
}
int dfs(int e,int x,int t){
int res=1;
if(t>k)return 0;
for(auto s:G[e]){
if(s==x)continue;
res+=dfs(s,e,t+1);
}
return res;
}
main(){
cin>>n>>k;
G.resize(n+1);
rep(i,n-1){
int a=in(),b=in();
G[a].pb(b);G[b].pb(a);
}
int ans=INF;
rep2(i,1,n){
ans=min(ans,calc(i));
}
cout<<ans<<endl;
} |
s076769013 | p04049 | u352623442 | 1551780301 | Python | Python (3.4.3) | py | Runtime Error | 2111 | 118872 | 942 | n,k = map(int,input().split())
INF = float("inf")
edges = [[] for i in range(n)]
ega = []
for i in range(n-1):
a,b = map(int,input().split())
a = a-1
b = b-1
edges[a].append(b)
edges[b].append(a)
ega.append([a,b])
def dfs(v):
d= [0] * n
q=[v]
visited = [0] * n
while q:
v=q.pop()
visited[v] = 1
visited.append(v)
for i in edges[v]:
if not visited[i]:
d[i] = d[v] + 1
q.append(i)
return d
mi = INF
table = []
for i in range(n):
table.append(dfs(i))
if k%2 == 0:
for i in range(n):
disi = table[i]
c = 0
for m in range(n):
if disi[m] > k/2:
c += 1
if mi>c:
mi = c
print(mi)
else:
for edge in ega:
c = 0
if table[edge[0]] + table[edge[1]] > k-1:
c += 1
if mi>c:
mi = c
print(mi)
|
s188294736 | p04049 | u352623442 | 1551780236 | Python | PyPy3 (2.4.0) | py | Runtime Error | 611 | 83800 | 942 | n,k = map(int,input().split())
INF = float("inf")
edges = [[] for i in range(n)]
ega = []
for i in range(n-1):
a,b = map(int,input().split())
a = a-1
b = b-1
edges[a].append(b)
edges[b].append(a)
ega.append([a,b])
def dfs(v):
d= [0] * n
q=[v]
visited = [0] * n
while q:
v=q.pop()
visited[v] = 1
visited.append(v)
for i in edges[v]:
if not visited[i]:
d[i] = d[v] + 1
q.append(i)
return d
mi = INF
table = []
for i in range(n):
table.append(dfs(i))
if k%2 == 0:
for i in range(n):
disi = table[i]
c = 0
for m in range(n):
if disi[m] > k/2:
c += 1
if mi>c:
mi = c
print(mi)
else:
for edge in ega:
c = 0
if table[edge[0]] + table[edge[1]] > k-1:
c += 1
if mi>c:
mi = c
print(mi)
|
s963926242 | p04049 | u352623442 | 1551779820 | Python | PyPy3 (2.4.0) | py | Runtime Error | 188 | 38384 | 1048 | n,k = map(int,input().split())
import numpy as np
INF = float("inf")
edges = [[] for i in range(n)]
ega = []
for i in range(n-1):
a,b = map(int,input().split())
a = a-1
b = b-1
edges[a].append(b)
edges[b].append(a)
ega.append([a,b])
def dfs(v):
visited = []
INF = float("inf")
d=[INF for i in range(n)]
q=[]
d[v]=0
q.append(v)
while len(q):
v=q.pop()
visited.append(v)
for i in edges[v]:
if i not in visited:
d[i] = d[v] + 1
q.append(i)
else:
continue
return d
mi = INF
table = []
for i in range(n):
table.append(dfs(i))
if k%2 == 0:
for i in range(n):
disi = table[i]
c = 0
for m in range(n):
if disi[m] > k/2:
c += 1
if mi>c:
mi = c
print(mi)
else:
for edge in ega:
c = 0
if table[edge[0]] + table[edge[1]] > k-1:
c += 1
if mi>c:
mi = c
print(mi)
|
s215625013 | p04049 | u214617707 | 1550955362 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1180 | 129696 | 440 | N, K = map(int, input().split())
G = [[] for i in range(N)]
for i in range(N - 1):
a, b = map(int, input().split())
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
def dfs(u, par, d):
global tmp
if d > K // 2:
tmp += 1
for w in G[u]:
if w == par:
continue
dfs(w, u, d + 1)
num = float("inf")
for i in range(N):
tmp = 0
dfs(i, -1, 0)
num = min(num, tmp)
print(num)
|
s609326818 | p04049 | u284854859 | 1550824657 | Python | PyPy3 (2.4.0) | py | Runtime Error | 1436 | 112728 | 755 | #import sys
#input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append((a-1,b-1))
def f(x,y,c):
global tmp
c += 1
for e in edge[x]:
if e == y:
continue
if c > d:
tmp +=1
f(e,x,c)
#sys.setrecursionlimit(4100000)
if k % 2 == 0:
d = k//2
ass = 2001
for i in range(n):
tmp = 0
f(i,-1,0)
ass = min(ass,tmp)
print(ass)
else:
d = (k-1)//2
ass = 2001
for e1 in alledge:
tmp = 0
f(e1[0],e1[1],0)
f(e1[1],e1[0],0)
ass = min(ass,tmp)
print(ass)
|
s532382604 | p04049 | u284854859 | 1550818480 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 787 | import sys
sys.setrecursionlimit(5000000)
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append((a-1,b-1))
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e in edge[x]:
if e != y:
if c > d:
used[e] = 1
f(e,x,c)
if k % 2 == 0:
d = k//2
res = []
for i in range(n):
used = [0]*n
f(i,-1,0)
res.append(sum(used))
print(min(res))
else:
d = (k-1)//2
res = []
for e1 in alledge:
used = [0]*n
f(e1[0],e1[1],0)
f(e1[1],e1[0],0)
res.append(sum(used))
print(min(res))
|
s931452563 | p04049 | u284854859 | 1550815806 | Python | Python (3.4.3) | py | Runtime Error | 1790 | 4652 | 816 | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e in edge[x]:
if e != y:
if c > d and e >= 0 and e<= n-1:
used[e] = 1
if len(edge[e])>=2:
f(e,x,c)
if k % 2 == 0:
d = k//2
res = []
for i in range(n):
used = [0]*n
f(i,-1,0)
res.append(sum(used))
print(min(res))
else:
d = (k-1)//2
res = []
for e1 in alledge:
used = [0]*n
f(e1[0],e1[1],0)
f(e1[1],e1[0],0)
res.append(sum(used))
print(min(res))
|
s238312663 | p04049 | u284854859 | 1550815527 | Python | Python (3.4.3) | py | Runtime Error | 81 | 4596 | 732 | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x):
#c +=1
for e in edge[x]:
#if e != y:
#if c > d:
# used[e] = 1
f(e)
if k % 2 == 0:
d = k//2
res = []
for i in range(n):
used = [0]*n
f(i,-1,0)
res.append(sum(used))
print(min(res))
else:
d = (k-1)//2
res = []
for e1 in alledge:
used = [0]*n
f(e1[0])
f(e1[1])
res.append(sum(used))
print(min(res))
|
s587581130 | p04049 | u284854859 | 1550815420 | Python | Python (3.4.3) | py | Runtime Error | 1004 | 4628 | 751 | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x,y):
#c +=1
for e in edge[x]:
if e != y:
#if c > d:
# used[e] = 1
f(e,x)
if k % 2 == 0:
d = k//2
res = []
for i in range(n):
used = [0]*n
f(i,-1,0)
res.append(sum(used))
print(min(res))
else:
d = (k-1)//2
res = []
for e1 in alledge:
used = [0]*n
f(e1[0],e1[1])
f(e1[1],e1[0])
res.append(sum(used))
print(min(res))
|
s300255193 | p04049 | u284854859 | 1550812219 | Python | Python (3.4.3) | py | Runtime Error | 1867 | 4668 | 781 | import sys
input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
alledge.append([a-1,b-1])
if n==2:
print(0)
exit()
def f(x,y,c):
c += 1
for e in edge[x]:
if e != y:
if c > d and e >= 0 and e<= n-1:
used[e] = 1
f(e,x,c)
if k % 2 == 0:
d = k//2
res = []
for i in range(n):
used = [0]*n
f(i,-1,0)
res.append(sum(used))
print(min(res))
else:
d = (k-1)//2
res = []
for e1 in alledge:
used = [0]*n
f(e1[0],e1[1],0)
#f(e1[1],e1[0],0)
res.append(sum(used))
print(min(res))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.