Problem list
Log in
#r03341 · Online Judge > GoldOJ

Distance Between Two Tree Nodes

Silver II 2.0 s 256 MB

Given a tree on $N$ nodes and two nodes $U$, $V$, print the number of edges on the unique path between them.

Input

First line $N$ ($2 \le N \le 1000$); then $N-1$ edge lines $u$, $v$; last line $U$, $V$ ($U \ne V$).

Output

Print the distance (edge count) between $U$ and $V$.

Example 1

Input
5
1 2
1 3
3 4
3 5
2 5
Output
3

Example 2

Input
4
1 2
2 3
3 4
1 4
Output
3
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code