QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#6217. Unique Leaves

Statistiques

Background

JYY has been watching "Super Brain" and was deeply shocked by the problem "Finding the Identical Tree". Although JYY does not possess such great insight, he believes that as a computer scientist, it will not be too difficult to complete this task using programs and algorithms.

Description

JYY has two trees, A and B. Tree A has $N$ nodes, labeled from $1$ to $N$. Tree B has $N+1$ nodes, labeled from $1$ to $N+1$.

JYY knows that tree B is formed by adding exactly one leaf node to tree A, and then the labels of the nodes are shuffled.

He wants to know: which leaf node in tree B is the extra one?

Input

The first line contains an integer $N$.

The next $N-1$ lines describe tree A, each containing two integers representing an edge in tree A.

The next $N$ lines describe tree B, each containing two integers representing an edge in tree B.

Output

Output a single integer representing the label of the extra leaf node in tree B compared to tree A.

If there are multiple leaf nodes that satisfy the requirements, output the one with the smallest label in tree B.

Constraints

  • For 10% of the data, $N \le 8$.
  • For 30% of the data, $N \le 50$.
  • For 60% of the data, $N \le 2000$.
  • For 100% of the data, $1 \le N \le 10^5$.

Examples

Input 1

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

Output 1

1

Input 2

3
1 2
2 3
2 4
4 1
1 3

Output 2

2

Input 3

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

Output 3

5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.