TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
string = input().split()
print(string[1]+string[0])

string = input().split()
print(string[1]+string[0])

print("".join(str(a) for a in ({1,2,3}-{int(input()), int(input())})))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
N = int(input())
S,T = map(str,input().split())
A = ""
for i in S:
  A+=i
  for j in T:
    A+=j
print(A)


A = int(input())
B = int(input())
x=1
for i range(3):
  if x!=A and x!=B:
    print(str(x))
  x+=1

A = int(input())
B = int(input())
x=1
for i in range(3):
  if x!=A and x!=B:
    print(str(x))
  x+=1

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a = int(input())
b = int(input())
print(3^a^b)


a = input()
b = input()
print(3^a^b)

a = int(input())
b = int(input())
print(a^b)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a = int(input())
b = int(input())
list = [1,2,3]
list.remove(a)
list.remove(b)
print(list)

a = int(input())
b = int(input())
if a!=1 and b!=1:
  print(1)
elif a!=2 and b!=2:
  print(2)
else:
  print(3)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
n=int(input())
t=int(input())
print(3-n-t)

n=int(input())
t=int(input())
print(6-n-t)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
from sys import stdin

A = stdin.readline().rstrip()
B = stdin.readline().rstrip()

if A == 1:
    if B == 2:
        print(3)
        exit()
    else:
        print(2)
        exit()
elif A == 2:
    if B == 1:
        print(3)
        exit()
    else:
        print(1)
        exit()
else:
    if B == 1:
        print(2)
        exit()
    else:
        print(3)
        exit()


from sys import stdin

A = int(stdin.readline().rstrip())
B = int(stdin.readline().rstrip())

if A == 1:
    if B == 2:
        print(3)
        exit()
    else:
        print(2)
        exit()
elif A == 2:
    if B == 1:
        print(3)
        exit()
    else:
        print(1)
        exit()
else:
    if B == 1:
        print(2)
        exit()
    else:
        print(1)
        exit()


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a, b = int(input())
if a == 1 and b == 2:
  print("3")
elif a == 1 and b == 3:
  print("2")
elif a == 2 and b == 3:
  print("1")

a = int(input())
b = int(input())
if a == 1 and b == 2:
  print("3")
elif a == 1 and b == 3:
  print("2")
elif a == 2 and b == 3:
  print("1")
elif a == 2 and b == 1:
  print("3")
elif a == 3 and b == 1:
  print("2")
elif a == 3 and b == 2:
  print("1")



Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
A = int(input())
B = int(input())

if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)
elif (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)
elif (A == 2 and B == 3) or (A == 3) and B == 2):
    print(1)

A = int(input())
B = int(input())

if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)
elif (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)
elif (A == 2 and B == 3) or (A == 3 and B == 2):
    print(1)

Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
A=int(input())
B=int(input())
AB=[A,B]
C=[1,2,3]
C.remove(A)
C.remove(B)
print(C)



A=int(input())
B=int(input())

s={A,B}
D={1,2,3}
for i in (D-s):
  print(i)
  

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
answer = [1, 2, 3]

in1, in2 = map(int, input().split())

answer.remove(in1)
answer.remove(in2)

return answer[0]

answer = [1,2,3]
in1 = int(input())
in2 = int(input())
answer.remove(in1)
answer.remove(in2)
print(answer[0])

Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a,b=map(int,input().split())
print(6-a-b)

a=int(input())
b=int(input())
c=6-a-b
print(c)

Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a = int(input())
b = int(input())

if a == 1:
  if b == 2:
    print(3)
elif a == 2:
  if b == 3:
    print(2)
elif a == 3:
  if b == 2 :
    print(1)

a = int(input())
b = int(input())

if a == 1 and b == 2:
    print(3)
elif a == 2 and b == 1:
    print(2)
elif a == 3 and b == 2 :
    print(1)

a = int(input())
b = int(input())

if a == 1 and b == 2:
    print(3)
elif a == 1 and b == 3:
    print(2)
elif a == 2 and b == 1 :
    print(3)
elif a == 2 and b == 3 :
    print(1)
elif a == 3 and b == 1 :
    print(2)
elif a == 3 and b == 2 :
    print(1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
nums = [1,2,3]
a = int(input())
b = int(input())
c = 0

for i in nums:
  if i != a || i != b:
    c = i
    
print(c)


nums = [1,2,3]
a = int(input())
b = int(input())
c = 0

for i in nums:
  if i != a && i != b:
    c = i
    
print(c)

nums = [1,2,3]
a = int(input())
b = int(input())
c = 0

for i in nums:
  if int(i) != a and int(i) != b:
    c = int(i)
    
print(c)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
import math

# from operator import xor
# import re


# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    A,B=map(int,input().split())
    val=A* B // math.gcd(A, B)
    print(val)

resolve()

sol=[1,2,3]
ch_1=int(input())
ch_2=int(input())
sol.remove(ch_1)
sol.remove(ch_2)
print(sol[0])

Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
N = int(input())
S, T  = input().split()

S_list = list(S)
T_list = list(T)
U_list = []
for i in range(N):
    U_list.append(S_list[i])
    U_list.append(T_list[i])

U = ''.join(U_list)
print(U_list)

N = int(input())
S, T  = input().split()

S_list = list(S)
T_list = list(T)
U_list = []
for i in range(N):
    U_list.append(S_list[i])
    U_list.append(T_list[i])

U = ''.join(U_list)
print(U)

l1 = [1,2,3]
l2 = [int(input()) for i in range(2)]
ans = list(set(l1) - set(l2))
print(ans[0])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a=int(input())
b=int(input())
print(int(((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2)))

a=int(input())
b=int(input())
print(int((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2))

a=int(input())
b=int(input())
print(int(((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2)))

a=int(input())
b=int(input())
l=[1,2,3]
l[a-1]=0
l[b-1]=0
print(sum(l))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):


A,B=map(int, input().split())

print(str(6-A-B))



A=int(input())
B=int(input())

print(str(6-A-B))

Verdicts: Runtime Error

Accepted
Problem: Takahashi is solving quizzes. He has easily solved all but the last one.  The last quiz has three choices: 1, 2, and 3.  With his supernatural power, Takahashi has found out that the choices A and B are both wrong.  Print the correct choice for this problem.

Submission attempts (in order):
a,b=map(int,input())
if a==3:
  print(3-b)
elif b==3:
  print(3-a)
else:
  print(a+b)    
  

a=int(input())
b=int(input())
print(6-a-b)

Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
import heapq;

n, u, v = [int(v) for v in input().split()]

vert = []

for i in range(n):
    vert.append([])

for i in range(n - 1):
    a, b = [int(v) - 1 for v in input().split()]
    vert[a].append(b)
    vert[b].append(a)

taka = u-1
aoki = v-1

if taka == aoki:
    return 0

q = [(0, aoki)]
aoki_dist = [-1] * n
aoki_dist[aoki] = 0

index = 0
while index < len(q):
    c0, i = q[index]
    c = c0 + 1
    for l in vert[i]:
        if aoki_dist[l] >= 0:
            continue
        aoki_dist[i] = c
        q.append((c, l))
    index += 1

q = [(0, taka)]
max_dist = aoki_dist[taka]

index = 0
while index < len(q):
    c0, i = q[index]
    c = c0 + 1
    for l in vert[i]:
        if aoki_dist[l] < 0:
            continue
        if c >= aoki_dist[l]:
            continue
        if max_dist < aoki_dist[l]:
            max_dist = aoki_dist[l]
        aoki_dist[l] = -1
        q.append((c, l))
    index += 1

print(max_dist - 1)

import heapq;

n, u, v = [int(v) for v in input().split()]

vert = []

for i in range(n):
    vert.append([])

for i in range(n - 1):
    a, b = [int(v) - 1 for v in input().split()]
    vert[a].append(b)
    vert[b].append(a)

taka = u-1
aoki = v-1

if taka == aoki:
    print(0)
    exit()

q = [(0, aoki)]
aoki_dist = [-1] * n
aoki_dist[aoki] = 0

index = 0
while index < len(q):
    c0, i = q[index]
    c = c0 + 1
    for l in vert[i]:
        if aoki_dist[l] >= 0:
            continue
        aoki_dist[l] = c
        q.append((c, l))
    index += 1

q = [(0, taka)]
max_dist = aoki_dist[taka]
aoki_dist[taka] = -1

index = 0
while index < len(q):
    c0, i = q[index]
    c = c0 + 1
    for l in vert[i]:
        if aoki_dist[l] < 0:
            continue
        if c >= aoki_dist[l]:
            continue
        if max_dist < aoki_dist[l]:
            max_dist = aoki_dist[l]
        aoki_dist[l] = -1
        q.append((c, l))
    index += 1

print(max_dist - 1)



Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
N, u, v = list(map(int, input().split()))
graph = [[] for _ in range(N+1)]
for i in range(N-1):
  A, B = list(map(int, input().split()))
  graph[A].append(B)
  graph[B].append(A)
#print(graph)

def dfs(v):
  dist = [-1] * (N+1)
  dist[v] = 0
  stack = [v
 # print(dist)
  while stack:
    now = stack.pop()
    dw = dist[now] + 1

    for ne in graph[now]:
      if dist[ne] >= 0:
        continue
      dist[ne] = dw
      stack.append(ne)
      #print(ne)
  return dist

Taka = dfs(u)
#Ao = dfs(v)

print(Taka)
#print(Ao)

ans = 0
for t, a in zip(Takahashi[1:], Aoki[1:]):
  if t < a:
    ans = max(ans, a-1)

print(ans)

import sys

n, u, v = map(int, sys.stdin.readline().split())
graph = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    graph[a].append(b)
    graph[b].append(a)

def dfs(v):
    dist = [-1] * (n+1)
    dist[v] = 0
    stack = [v]
    while stack:
        now = stack.pop()
        dw = dist[now] + 1
        for ne in graph[now]:
            if dist[ne] >= 0:
                continue
            dist[ne] = dw
            stack.append(ne)
    return dist

Takahashi = dfs(u)
Aoki = dfs(v)

ans = 0
for t, a in zip(Takahashi[1:], Aoki[1:]):
    if t < a:
        ans = max(ans, a - 1)

print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
import sys
input = sys.stdin.readline
from collections import deque
import numpy as np

n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]

graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


def dfs(graph, start):
    visited = [0]*n
    stack = deque([start])
    distance = [-1]*n
    dis = 0
    while stack:
        node = stack.pop()
        visited[node] = 1
        if len(graph[node]) == 1:
            if node == start:
                distance[node] = 0
            else:
                distance[node] = dis
                dis -= 1
        for child in graph[node]:
            if visited[child] == 1:
                continue
            stack.append(child)
        dis += 1
    return distance

distance1 = np.array(dfs(graph, u-1))
distance2 = np.array(dfs(graph, v-1))
distance = distance2-distance1
dis = max(distance) 
# print(distance1, distance2)
if dis%2 == 0:
    dis -= 1
else:
    dis -= 2
if dis < 0:
    print(0)
else:
    print(dis)


import sys
input = sys.stdin.readline
from collections import deque
import numpy as np

n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]

graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


def dfs(graph, start):
    stack = deque([start])
    dist = [-1]*n
    dist[start] = 0
    while stack:
        node = stack.pop()
        dist_x = dist[node] + 1
        for child in graph[node]:
            if dist[child] != -1:
                continue
            dist[child] = dist_x
            stack.append(child)
    return dist

distance1 = np.array(dfs(graph, u-1))
distance2 = np.array(dfs(graph, v-1))

distance = distance2[distance1<distance2]
ans = max(distance)-1
print(ans)



Verdicts: Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
n, r0, g0 = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(n-1)]

connects = [[] for i in range(n+1)]
for e in edges:
    connects[e[0]].append(e[1])
    connects[e[1]].append(e[0])    

import numpy as np
rL, gL = np.array([-1]*(n+1)), np.array([-1]*(n+1))
rL[r0], gL[g0] = 0, 0

from collections import deque
rQ, gQ = deque([r0]), deque([g0])

for L, Q in [(rL, rQ), (gL, gQ)]:
    while Q:
        node = Q.popleft()
        for ni in connects[node]:
            if L[ni] == -1:
                L[ni] = L[node] + 1
                print((node, L[node]), (ni, L[ni]), L)
                Q.append(ni)
    
print(max(gL[i] for i in range(1, n+1) if rL[i] < gL[i]) - 1)


n, r0, g0 = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(n-1)]

connects = [[] for i in range(n+1)]
for e in edges:
    connects[e[0]].append(e[1])
    connects[e[1]].append(e[0])    

rL, gL = [-1]*(n+1), [-1]*(n+1)
rL[r0], gL[g0] = 0, 0

from collections import deque
rQ, gQ = deque([r0]), deque([g0])

for L, Q in [(rL, rQ), (gL, gQ)]:
    while Q:
        node = Q.popleft()
        for ni in connects[node]:
            if L[ni] == -1:
                L[ni] = L[node] + 1
                ### print((node, L[node]), (ni, L[ni]))
                Q.append(ni)

print(max(gL[i] for i in range(1, n+1) if rL[i] < gL[i]) - 1)

Verdicts: Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
N,U,V = map(int,input().split())
U,V = U-1, V-1

adj = [list() for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)



dist_u = [None]*N
dist_u[U] = 0
stack = [U]

while stack:
    x = stack.pop()
    d = dist_u[x]+1
    for y in adj[x]:
        if dist_u[y] is None:
            dist_u[y] = d
            stack.append(y)


dist_v = [None]*N
dist_v[V] = 0
stack = [V]

while stack:
    x = stack.pop()
    d = dist_v[x]+1
    for y in adj[x]:
        if dist_v[y] is None:
            dist_v[y] = d
            stack.append(y)

m,n = max((a,b) for a,b in zip(dist_u, dist_v) if a < b)
print(n-(m-n)%2)N,U,V = map(int,input().split())
U,V = U-1, V-1

adj = [list() for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)



dist_u = [None]*N
dist_u[U] = 0
stack = [U]

while stack:
    x = stack.pop()
    d = dist_u[x]+1
    for y in adj[x]:
        if dist_u[y] is None:
            dist_u[y] = d
            stack.append(y)


dist_v = [None]*N
dist_v[V] = 0
stack = [V]

while stack:
    x = stack.pop()
    d = dist_v[x]+1
    for y in adj[x]:
        if dist_v[y] is None:
            dist_v[y] = d
            stack.append(y)

m,n = max((a,b) for a,b in zip(dist_u, dist_v) if a < b)
print(n-(m-n)%2)

N,U,V = map(int,input().split())
U,V = U-1, V-1

adj = [list() for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)



dist_u = [None]*N
dist_u[U] = 0
stack = [U]

while stack:
    x = stack.pop()
    d = dist_u[x]+1
    for y in adj[x]:
        if dist_u[y] is None:
            dist_u[y] = d
            stack.append(y)


dist_v = [None]*N
dist_v[V] = 0
stack = [V]

while stack:
    x = stack.pop()
    d = dist_v[x]+1
    for y in adj[x]:
        if dist_v[y] is None:
            dist_v[y] = d
            stack.append(y)

n = max(b for a,b in zip(dist_u, dist_v) if a < b)
m = min((b for a,b in zip(dist_u, dist_v) if a <= b), default=n)

print(max(n,m)-1)

Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
#!python3

def resolve():
    N, u, v = map(int, input().rstrip().split())
    N1 = N + 1

    d = [[] for _ in range(1, N1)]
    for i in range(1, N):
        a, b = map(int, input().rstrip().split())

        d[a].append(b)
        d[b].append(a)

    from collections import deque

    def f(x):
        q = deque()
        q.append(x)
        X = [-1] * N1

        while q:
            x = q.popleft()
            for i in d[x]:
                if X[i] == -1:
                    X[i] = X[x] + 1
                    q.append(i)
        return q

    U = f(u)
    V = f(v)

    m = 0
    for uu, vv in zip(U, V):
        if uu < vv:
            if vv > m:
                m = vv
    print(m-1)

if __name__ == "__main__":
    resolve()


#!python3

def resolve():
    N, u, v = map(int, input().rstrip().split())
    N1 = N + 1

    d = [[] for _ in range(0, N1)]
    for i in range(1, N):
        a, b = map(int, input().rstrip().split())

        d[a].append(b)
        d[b].append(a)

    from collections import deque

    def f(x):
        q = deque()
        q.append(x)
        X = [-1] * N1

        X[x] = 0
        while q:
            x = q.popleft()
            for i in d[x]:
                if X[i] == -1:
                    X[i] = X[x] + 1
                    q.append(i)
        return X

    U = f(u)
    V = f(v)

    m = 0
    for uu, vv in zip(U, V):
        if uu < vv:
            if vv > m:
                m = vv
    print(m-1)

if __name__ == "__main__":
    resolve()


Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
n,u,v = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)
print(0)

n,u,v = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)
print(1)

import sys
input=sys.stdin.readline
n,u,v = map(int, input().split())
link = [[] for _ in range(n)]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

from collections import deque
Q = deque()
Q.append([v-1,0])
visited=[-1]*n
visited[v-1]=0
while Q:
    now,cnt = Q.popleft()
    for nxt in link[now]:
        if visited[nxt]!=-1:
            continue
        visited[nxt]=cnt+1
        Q.append([nxt,cnt+1])
Q = deque()
Q.append([u-1,0])
v_taka=[-1]*n
v_taka[u-1]=0
while Q:
    now,cnt = Q.popleft()
    for nxt in link[now]:
        if v_taka[nxt]!=-1:
            continue
        if visited[nxt] <= cnt+1:
            continue
        v_taka[nxt]=cnt+1
        Q.append([nxt,cnt+1])
ans=-1
for i in range(n):
    if v_taka[i] == -1:
        continue
    if ans < visited[i]:
        ans=visited[i]
print(ans-1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
n,u,v = map(int,input().split())
u,v = u-1,v-1
link = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  link[a].append(b)
  link[b].append(a)
tree = [[] for i in range(n)]
for i in [u,v]:
  stack = [i]
  vi = [0] * n
  tree[i].append(0)
  vi[i] = 1
  while stack:
    cur = stack.pop()
    for j in link[cur]:
      if vi[j] == 0:
        stack.append(j)
        vi[j] = 1
        tree[j].append(tree[cur][-1]+1)
m = 0
c = 0
for i,j in tree:
  print(i,j)
  if i < j:
    if m < j:
      m = j
      #c = (j-i) % 2
print(m-1)

n,u,v = map(int,input().split())
u,v = u-1,v-1
link = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  link[a].append(b)
  link[b].append(a)
tree = [[] for i in range(n)]
for i in [u,v]:
  stack = [i]
  vi = [0] * n
  tree[i].append(0)
  vi[i] = 1
  while stack:
    cur = stack.pop()
    for j in link[cur]:
      if vi[j] == 0:
        stack.append(j)
        vi[j] = 1
        tree[j].append(tree[cur][-1]+1)
m = 0
c = 0
for i,j in tree:
  if i < j:
    if m < j:
      m = j
      #c = (j-i) % 2
print(m-1)

Verdicts: Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
n, u, v = int(input())
print(n, u, v)


n, u, v = map(int, input().split())
mapdata = [list(map(int,input().split())) for _ in range(n-1)]


graph = [[] for _ in range(n+1)]
for i, j in mapdata:
  graph[i].append(j)
  graph[j].append(i)


def dfs(v):
  dist = [-1] * (n + 1)
  stack = [v]
  dist[v] = 0
  while stack:
    v = stack.pop()
    dw = dist[v] + 1
    for w in graph[v]:
      if dist[w] >= 0:
        continue
      dist[w] = dw
      stack.append(w)
  return dist

du, dv = dfs(u), dfs(v)
ans = 0

for u, v in zip(du[1:], dv[1:]):
  if u < v:
    x = v-1
    if ans < x:
      ans = x

print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
N,U,V = map(int, input().split())



from collections import deque

G = [[] for i in range(N)]
for i in range(N-1):
    
    u,v = map(int,input().split())
    G[u-1].append((v-1))
    G[v-1].append((u-1))


used = [-1] * N
used[V-1] = 0 

q = deque([V-1])
while len(q) > 0:
    a = q.popleft()
    Vs = G[a]
    for u in Vs: 
        if used[u] == -1:
            q.append(u)
            
            used[u] = used[a] + 1


used_t = [-1] * N
used_t[U-1] = 0 
q = deque([U-1])
while len(q) > 0:
    a = q.popleft()
    Vs = G[a]
    for u in Vs: 
        if used_t[u] == -1:
            q.append(u)
            
            used_t[u] = used_t[a] + 1
# print(used)
# print(used_t)


diff = []
ind = []
for i,(a,t) in enumerate(zip(used,used_t)):
    diff.append(a-t)
    ind.append((t,i))
# print(diff)
ind.sort(reverse=True)
# print(ind)

start = diff[V-1]
ans = 0
for d_taka,i in ind:
    # print("info",d_taka,i,diff[i])
    if diff[i] < 0:
        continue
    ans = d_taka - 1
    break
print(ans)

N,U,V = map(int, input().split())



from collections import deque

G = [[] for i in range(N)]
for i in range(N-1):
    
    u,v = map(int,input().split())
    G[u-1].append((v-1))
    G[v-1].append((u-1))



used_a = [-1] * N
used_a[V-1] = 0 
q = deque([V-1])
while len(q) > 0:
    a = q.popleft()
    Vs = G[a]
    for u in Vs:
        if used_a[u] == -1:
            q.append(u)
            used_a[u] = used_a[a] + 1

## takahashi
used_t = [-1] * N
used_t[U-1] = 0 
q = deque([U-1])
while len(q) > 0:
    a = q.popleft()
    Vs = G[a]
    for u in Vs: 
        if used_t[u] == -1:
            q.append(u)
            used_t[u] = used_t[a] + 1

ans = 0
# print("aoki",used_a)
# print("taka",used_t)
for a,t in zip(used_a,used_t):
    if a > t: 
        ans = max(ans,a-1)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
from collections import deque

di_lst = []
N, U, V = map(int, input().split())
edges = {tuple(map(int, input().split())) for i in range(N - 1)}

stack = deque()


def BFS(X, edges, N):
    roots = [set() for _ in range(N + 1)]
    for a, b in edges:
        roots[a].add(b)
        roots[b].add(a)
    dist = {}
    stack = deque()
    stack.append(X)
    dist[X] = 0
    while stack:
        parent = stack.pop()
        for child in roots[parent]:
            if not child in dist:
                dist[child] = dist[parent] + 1
                stack.append(child)
    return dist


U_dist = BFS(U, edges, N)
V_dist = BFS(V, edges, N)

ans = 0
for i in range(1, N + 1):
    u, v = U_dist[i], V_dist[i]
    if u > v:
        ans = max(v - 1, ans)
print(ans)


from collections import deque

di_lst = []
N, U, V = map(int, input().split())
edges = {tuple(map(int, input().split())) for i in range(N - 1)}

stack = deque()


def BFS(X, edges, N):
    roots = [set() for _ in range(N + 1)]
    for a, b in edges:
        roots[a].add(b)
        roots[b].add(a)
    dist = {}
    stack = deque()
    stack.append(X)
    dist[X] = 0
    while stack:
        parent = stack.pop()
        for child in roots[parent]:
            if not child in dist:
                dist[child] = dist[parent] + 1
                stack.append(child)
    return dist


U_dist = BFS(U, edges, N)
V_dist = BFS(V, edges, N)

ans = 0
for i in range(1, N + 1):
    u, v = U_dist[i], V_dist[i]
    if u < v:
        ans = max(v - 1, ans)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
N,u,v = map(int,input().split())
E = [[] for _ in range(N + 1)]
for i in range(N-1):
    a,b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)
#print(E)
def bfs(start,N):
    d = [-1]*(N+1)
    d[start] = 0
    q = [start]
    while q:
        #print(d,q)
        v = q.pop()
        cnt = d[v]+1
        for i in E[v]:
            if(d[i] == -1):
                q.append(i)
                d[i] = cnt
    return d
taka = bfs(u,N)
aoki = bfs(v,N)
#print(taka,aoki)
for i in range(N+1):
    if(taka[i] < aoki[i]):
        fin = max(fin,aoki[i])
print(fin - 1)

from collections import deque
N,u,v = map(int,input().split())
E = [[] for _ in range(N + 1)]
for i in range(N-1):
    a,b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)
print(E)
def bfs(start,N,AB):
    d = [-1]*(N+1)
    d[start] = 0
    q = [start]
    while q:
        print(d,q)
        v = q.pop()
        cnt = d[v]+1
        for i in E[v]:
            if(d[i] == -1):
                q.append(i)
                d[i] = cnt
    return d
taka = bfs(u,N,AB)#takahashi
aoki = bfs(v,N,AB)
print(taka,aoki)
fin = -1
for i in range(N+1):
    if(taka[i] < aoki[i]):
        fin = max(fin,aoki[i])
        ans = fin - (aoki[i]-taka[i]+1)//2
print(ans)

N,u,v = map(int,input().split())
E = [[] for _ in range(N + 1)]
for i in range(N-1):
    a,b = map(int,input().split())
    E[a].append(b)
    E[b].append(a)
#print(E)
def bfs(start,N):
    d = [-1]*(N+1)
    d[start] = 0
    q = [start]
    while q:
        #print(d,q)
        v = q.pop()
        cnt = d[v]+1
        for i in E[v]:
            if(d[i] == -1):
                q.append(i)
                d[i] = cnt
    return d
taka = bfs(u,N)
aoki = bfs(v,N)
#print(taka,aoki)
fin = 0
for i in range(N+1):
    if(taka[i] < aoki[i]):
        fin = max(fin,aoki[i])
print(fin - 1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**5)

# input
n, u, v = map(int, list(input().split()))

tree = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, list(input().split()))
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

# process
def getdis(idx, num, dis):
    dis[idx] = num
    for i in tree[idx] :
        if dis[i] < 0:
            dis = getdis(i, num+1, dis)
    return dis

dis_u = [-1]*n
dis_u = getdis(u-1, 0, dis_u)
dis_v = [-1]*n
dis_v = getdis(v-1, 0, dis_v)

print(dis_u)
print(dis_v)

ans = 0
for i in range(n):
    if dis_u[i] == dis_v[i] or dis_u[i]+1 == dis_v[i]:
        ans = max(ans, dis_v[i]-1)

# output
print(ans)


import sys
sys.setrecursionlimit(10**5)

# input
n, u, v = map(int, list(input().split()))

tree = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, list(input().split()))
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

print(tree)

# process
def f(line, maxlen):
    print(line)
    edges = tree[line[-1]]
    if len(line) == 1 or len(edges) > 1:
        for e in edges :
            if len(line) ==1 or not e == line[-2]:
                l = line[:]
                l.append(e)
                maxlen = f(l, maxlen)
        return maxlen

    else:
        if len(line) > maxlen: maxlen = len(line)
        return maxlen

# output
print(f([v-1], 0)-2)


import sys
sys.setrecursionlimit(10**5)

# input
n, u, v = map(int, list(input().split()))

tree = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, list(input().split()))
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

# process
def getdis(idx, num, dis):
    dis[idx] = num
    for i in tree[idx] :
        if dis[i] < 0:
            dis = getdis(i, num+1, dis)
    return dis

dis_u = [-1]*n
dis_u = getdis(u-1, 0, dis_u)
dis_v = [-1]*n
dis_v = getdis(v-1, 0, dis_v)

ans = 0
for i in range(n):
    if dis_u[i] <= dis_v[i]:
        ans = max(ans, dis_v[i]-1)

# output
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.  Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.  Now, they will play a game of tag as follows:    * 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.    * 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.    * 3. Go back to step 1.  Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.  Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.  It can be proved that the game is bound to end.

Submission attempts (in order):
def dfs(v, dist, d = 0, p = -1):
#     print(v, d)
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(u, dist, d + 1, v)
def calcDist(s, dist):
    dfs(s, dist)        
n, u, v = map(int, input().split())
u -= 1
v -= 1
to = [[] for _ in range(10000005)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
distS = [0] * n
distT = [0] * n
calcDist(u, distS)
calcDist(v, distT)
mx = 0
for i in range(n):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)

import sys
sys.setrecursionlimit(10 ** 8)

n, u, v = map(int, input().split())
to = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

def DFS(s, dist, to, d = 0, p = -1):
    dist[s] = d
    for v in to[s]:
        if v == p:
            continue
        DFS(v, dist, to, d + 1, s)
    
def calcDict(s, dist, to):
    DFS(s, dist, to)
    
distU = [0] * (n + 1)
distV = [0] * (n + 1)

calcDist(u, distU, to)
calcDist(v, distV, to)
ans = 0
for i in range(n + 1):
    if dictU[i] < dictV[i]:
        ans = max(ans, dictV[i])
print(ans - 1)

import sys
sys.setrecursionlimit(10 ** 8)

n, u, v = map(int, input().split())
to = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

def DFS(s, dist, to, d = 0, p = -1):
    dist[s] = d
    for v in to[s]:
        if v == p:
            continue
        DFS(v, dist, to, d + 1, s)
    
def calcDist(s, dist, to):
    DFS(s, dist, to)
    
distU = [0] * (n + 1)
distV = [0] * (n + 1)

calcDist(u, distU, to)
calcDist(v, distV, to)
ans = 0
for i in range(n + 1):
    if distU[i] < distV[i]:
        ans = max(ans, distV[i])
print(ans - 1)


Verdicts: Time Limit Exceeded

Runtime Error

Accepted