Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# coding: utf-8

# In[1]:
import sys
sys.setrecursionlimit(1000000)


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[2]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[3]:


eda


# In[ ]:





# In[4]:


def dfs(n1, n0):
    houmon[n1] = True
    par[n1] = n0
    for n2 in eda[n1]:
        if not houmon[n2]:
            dfs(n2, n1)
    


# In[5]:


houmon = [False] * N
par = [0] * N
dfs(v, v)


# In[6]:


par


# In[7]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[8]:


dis


# In[9]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[10]:


n


# In[11]:


def dfs2(n1):
    ret = 0
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        ret = max(ret, dfs2(n2) + 1)
    return ret


# In[12]:


y = (dis - 1) // 2
x = dis - y
z = dfs2(n)


# In[13]:


print(y + z + 1 if dis % 2 == 0 else y + z)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[21]:


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[22]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[25]:


par = [0] * N
# depth = [0] * N

stack = [v]
par[v] = -1

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        par[n2] = n1
#         depth[n2] = depth[n1] + 1
        stack.append(n2)
        


# In[26]:


par


# In[27]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[28]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[29]:


y = (dis - 1) // 2
x = dis - y
# z = depth[n]


# In[38]:


stack = [n]
depth = [0] * N
maxd = 0

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        depth[n2] = depth[n1] + 1
        maxd = max(maxd, depth[n2])
        stack.append(n2)
        


# In[41]:


z = maxd


# In[43]:


if dis % 2 == 0:
    print(y + z + 1)
else:
    print(y + z)


# In[ ]:

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[1]:
import sys
sys.setrecursionlimit(10000)


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[2]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[3]:


eda


# In[ ]:





# In[4]:


def dfs(n1, n0):
    houmon[n1] = True
    par[n1] = n0
    for n2 in eda[n1]:
        if not houmon[n2]:
            dfs(n2, n1)
    


# In[5]:


houmon = [False] * N
par = [0] * N
dfs(v, v)


# In[6]:


par


# In[7]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[8]:


dis


# In[9]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[10]:


n


# In[11]:


def dfs2(n1):
    ret = 0
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        ret = max(ret, dfs2(n2) + 1)
    return ret


# In[12]:


y = (dis - 1) // 2
x = dis - y
z = dfs2(n)


# In[13]:


print(y + z + 1 if dis % 2 == 0 else y + z)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[21]:


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[22]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[25]:


par = [0] * N
# depth = [0] * N

stack = [v]
par[v] = -1

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        par[n2] = n1
#         depth[n2] = depth[n1] + 1
        stack.append(n2)
        


# In[26]:


par


# In[27]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[28]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[29]:


y = (dis - 1) // 2
x = dis - y
# z = depth[n]


# In[38]:


stack = [n]
depth = [0] * N
maxd = 0

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        depth[n2] = depth[n1] + 1
        maxd = max(maxd, depth[n2])
        stack.append(n2)
        


# In[41]:


z = maxd


# In[43]:


if dis % 2 == 0:
    print(y + z + 1)
else:
    print(y + z)


# In[ ]:

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[2]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[3]:


eda


# In[ ]:





# In[4]:


def dfs(n1, n0):
    houmon[n1] = True
    par[n1] = n0
    for n2 in eda[n1]:
        if not houmon[n2]:
            dfs(n2, n1)
    


# In[5]:


houmon = [False] * N
par = [0] * N
dfs(v, v)


# In[6]:


par


# In[7]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[8]:


dis


# In[9]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[10]:


n


# In[11]:


def dfs2(n1):
    ret = 0
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        ret = max(ret, dfs2(n2) + 1)
    return ret


# In[12]:


y = (dis - 1) // 2
x = dis - y
z = dfs2(n)


# In[13]:


print(y + z + 1 if dis % 2 == 0 else y + z)



Fixed submission:
#!/usr/bin/env python
# coding: utf-8

# In[21]:


N, u, v = map(int, input().split())
u = u - 1
v = v - 1


# In[22]:


eda = [[] for _ in range(N)]
for _ in range(N-1):
    A, B = map(int, input().split())
    eda[A-1].append(B-1)
    eda[B-1].append(A-1)


# In[25]:


par = [0] * N
# depth = [0] * N

stack = [v]
par[v] = -1

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        par[n2] = n1
#         depth[n2] = depth[n1] + 1
        stack.append(n2)
        


# In[26]:


par


# In[27]:


dis = 0
n = u
while n != v:
    n = par[n]
    dis += 1


# In[28]:


n = u
for _ in range((dis - 1) // 2):
    n = par[n]


# In[29]:


y = (dis - 1) // 2
x = dis - y
# z = depth[n]


# In[38]:


stack = [n]
depth = [0] * N
maxd = 0

while stack:
    n1 = stack.pop()
    for n2 in eda[n1]:
        if n2 == par[n1]:
            continue
        depth[n2] = depth[n1] + 1
        maxd = max(maxd, depth[n2])
        stack.append(n2)
        


# In[41]:


z = maxd


# In[43]:


if dis % 2 == 0:
    print(y + z + 1)
else:
    print(y + z)


# In[ ]: