Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import coo_matrix

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())
AB = np.array(AB, np.int32).reshape(N - 1, 2)

a = AB[:, 0]
b = AB[:, 1]
d = np.ones_like(a, np.int32)

graph = coo_matrix((d, (a, b)), shape=(N + 1, N + 1))
graph.tocsr()
takahashi = dijkstra(graph, directed=False, indices=u)
aoki = dijkstra(graph, directed=False, indices=v)

print(int(aoki[takahashi < aoki].max()) - 1)

Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())
AB = np.array(AB, np.int32).reshape(N - 1, 2)

a = AB[:, 0]
b = AB[:, 1]
d = np.ones_like(a, np.int32)

graph = csr_matrix((d, (a, b)), shape=(N + 1, N + 1))
takahashi = dijkstra(graph, directed=False, indices=u)
aoki = dijkstra(graph, directed=False, indices=v)

print(int(aoki[takahashi < aoki].max()) - 1)

Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())
AB = np.array(AB, np.int32).reshape(N - 1, 2)

a = AB[:, 0]
b = AB[:, 1]
d = np.ones_like(a, np.int32)

graph = csr_matrix((d, (a, b)), shape=(N + 1, N + 1))
takahashi, aoki = dijkstra(graph, directed=False, indices=[u, v])

print(int(aoki[takahashi < aoki].max()) - 1)

Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import coo_matrix

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

a = AB[::2]
b = AB[1::2]
d = [1] * (N - 1)

graph = coo_matrix((d, (a, b)), shape=(N + 1, N + 1))
takahashi, aoki = dijkstra(graph, directed=False, indices=[u, v])

print(int(aoki[takahashi < aoki].max()) - 1)

Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import coo_matrix


def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])


def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and pred_row[i] > 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]


read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

a = AB[::2]
b = AB[1::2]
d = [1] * (N - 1)

graph = coo_matrix((d, (a, b)), shape=(N + 1, N + 1))
takahashi, aoki = dijkstra(graph, directed=False, indices=[u, v])
n = np.where(takahashi < aoki)
print(int(aoki[n].max()) - 1)


Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
from scipy.sparse.csgraph import shortest_path, dijkstra
from scipy.sparse import coo_matrix


def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])


def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and pred_row[i] > 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]


read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

a = AB[::2]
b = AB[1::2]
d = [1] * (N - 1)

graph = coo_matrix((d, (a, b)), shape=(N + 1, N + 1))
l, p = shortest_path(graph, directed=False, indices=u, return_predecessors=True)
dist = int(l[v]) // 2
s = get_path_row(u, v, p)[dist]
tour = shortest_path(graph, directed=False, indices=s)

print(int(max(i for i in tour if i != np.inf)) + dist - 1)

Fixed submission:
import sys

read = sys.stdin.read
N, u, v, *AB = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    graph[a].append(b)
    graph[b].append(a)


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)

answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if u < v:
        tmp = v - 1
        if answer < tmp:
            answer = tmp

print(answer)