Bus Routes
Time limit1sMemory limit512 MB
Cover every edge of a tree with the fewest simple paths, where each path visits distinct vertices in order along tree edges.
- Level
Medium7 of 10
- Topics
- Tree, DFS, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
Ulsan is a large city with a complex transportation system. This system can be represented by bus stops (vertices) and the roads (edges) that connect them. In the graph formed by the stops and roads, there are no cycles, and a path always exists between any two distinct stops. That is, it is a tree.
Yunpyo, who recently got a job in the transportation department, thinks there are too many bus routes and decides to clean them up. Boldly, he will remove all existing bus routes and design new ones. Each bus route is defined as follows.
- It has a starting stop and an ending stop.
- On the way from the starting stop to the ending stop, it may pass through several stops in a fixed order. There is no limit on the number of intermediate stops, and it may also go directly from the start to the end without passing through any stop. Of course, Yunpyo can decide the order in which the intermediate stops are visited.
- If a bus route visits K stops, and the stops it visits in order are stop 1, stop 2, ..., stop K, then a road must exist between stop i (1 ≤ i ≤ K-1) and stop i+1. The road connecting stop i and stop i+1 is said to be traversed by this bus route.
- The same stop must not be visited more than once. That is, the start, the end, and all intermediate stops must be distinct.
Yunpyo wants to design the bus routes so that at least one bus route traverses every road. (The direction in which a route traverses a road does not matter.) He also wants the number of bus routes to be minimized. Help Yunpyo by writing a program that finds the minimum number of bus routes such that at least one bus route traverses every road.
Input
The first line gives the number of stops N (2 ≤ N ≤ 200,000). The stops are numbered uniquely from 0 to N-1.
From the second line to the Nth line, pairs of stops connected by a road are given. The same road is not given more than once.
Output
Print the minimum number of bus routes after organizing the routes.