#DSU0000071. Tập đỉnh có thể đến (Reachable Set)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tập đỉnh có thể đến (Reachable Set)
Reachable Set
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an undirected simple graph with vertices and edges. Independently for each , you may erase vertices and their incident edges. Decide whether the vertices reachable from vertex can be made exactly .
Vertices required to remain reachable cannot be erased. If the target reachable set is achievable, minimize the number of deleted vertices. Each value of starts with the original graph.
Each operation deletes one vertex together with all its incident edges; no edge can be added. To obtain exactly the reachable set from vertex , every vertex in that set must remain and must be reachable from vertex .
Vertices with labels greater than do not all have to be deleted: any such vertex that is unreachable from vertex may remain. Conversely, if deleting vertices cannot make all of reachable without including any other vertex, output -1. Each value of starts from the original graph.
Input
The first line contains , followed by lines describing edges .
Output
Print lines. Line contains the minimum number of deletions, or -1 if the reachable set cannot be exactly .
Subtasks
- Subtask 1 (20 points): ; ; ; edges are distinct and .
- Subtask 2 (30 points): ; ; ; edges are distinct and .
- Subtask 3 (50 points): ; ; ; edges are distinct and .
Examples
Input
6 7
1 2
1 5
2 3
2 4
2 5
3 6
5 6
Output
2
3
3
2
1
0
Explanation
For , vertices must be deleted to make precisely reachable from vertex , so the answer is . The answers for the other values of are in order. For , no deletion is necessary because every vertex is already reachable from vertex .