#P5258. [JSOI2013] 旅行时的困惑

    ID: 5988 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2013各省省选江苏O2优化上下界网络流

[JSOI2013] 旅行时的困惑

Problem Description

Waldives has NN small islands. The current transportation system contains N1N-1 express boat routes, and each express boat route connects two islands. These N1N-1 express boat routes form a tree.

For special reasons, all N1N-1 express boat routes are one-way. This makes many pairs of islands unable to reach each other. Therefore, the Waldives government wants to build some new bus routes so that after construction, any two islands can reach each other. To save money, the government wants to build as few bus routes as possible.

At the same time, for planning reasons, each bus route must satisfy the following requirements:

  1. Each transportation route contains several consecutive express boat routes. You may treat one bus route as a path on the tree, and the express boat routes it contains correspond to the tree edges covered by this path (that is, some express boat routes that already exist).

  2. Obviously, a transportation route can cover any edge on the tree at most once.

  3. Each express boat route included in a bus route has a direction, and this direction is opposite to the direction of the tree edge it covers.

  4. Different bus routes may cover the same vertices or the same edges on the tree.

The NN islands of Waldives are numbered from 00 to N1N-1. Now the existing express boat route information of Waldives is given. Please compute the minimum number of new transportation routes that need to be built.

Input Format

The first line contains an integer NN.

The next N1N-1 lines each contain two integers x, yx,~y, meaning that there is an express boat route from island xx to island yy.

Output Format

Output one line with one integer, representing the minimum number of transportation routes that need to be built.

4
0 1
1 2
1 3
2

Hint

1  N  1051~\leq~N~\leq~10^5

Translated by ChatGPT 5