#P4323. [JSOI2016] 独特的树叶

    ID: 3253 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016江苏深度优先搜索,DFS哈希,HASH

[JSOI2016] 独特的树叶

Description

JYY has two trees AA and BB: tree AA has NN nodes labeled from 11 to NN; tree BB has N+1N + 1 nodes labeled from 11 to N+1N + 1.

JYY knows that tree BB is obtained from tree AA by adding one leaf node and then shuffling the node labels. He wants to determine which leaf node in tree BB is the extra one.

Input Format

The first line contains a positive integer NN.
The next N1N - 1 lines describe tree AA, each containing two integers that represent an edge of tree AA.
The next NN lines describe tree BB, each containing two integers that represent an edge of tree BB.

Output Format

Output a single integer: the label in tree BB of the extra leaf compared to tree AA. If multiple leaves satisfy the condition, output the smallest label among them.

5
1 2
2 3
1 4
1 5
1 2
2 3
3 4
4 5
3 6
1

Hint

For all testdata, 1N1051 \leq N \leq 10^{5}.

Translated by ChatGPT 5