Godzilla
Time limit1sMemory limit128 MB
After each of k edge deletions in a directed graph, the task asks for the smallest number of start vertices that reach every vertex.
- Level
Hard9 of 10
- Topics
- Graph, Union-find, Topological sort
- Solved
- No attempts yet
Problem
The residents of a small village love watching a popular TV drama. It reaches every corner of the village through a cable broadcast network. The network has nodes and one-way connections, and at least one house is attached to every node.
Some nodes are designated as broadcast nodes: the program is transmitted directly to them. A house can watch the drama if there is a path of connections (not necessarily a direct one) from some broadcast node to the node its house is attached to. To keep costs down, the number of broadcast nodes must be as small as possible.
Then Godzilla shows up. Godzilla feeds on the cable network, devouring exactly one connection each day. The operator cannot afford to lose viewers, so after every attack it must re-designate the broadcast nodes to guarantee that every house can still watch the drama. For each of the attacks, determine the minimum number of broadcast nodes required immediately after that attack.
Input
The first line contains two integers and (): the number of nodes and the number of connections in the network.
Each of the next lines contains two integers and (, ), describing a one-way connection from node to node . Between any pair of nodes there is at most one direct connection in a given direction, and each connection appears in the input exactly once. Connections are numbered from in the order they appear.
The next line contains an integer (): the number of attacked connections. Each of the next lines contains the number of the connection attacked that day, given in chronological order.
Output
Print exactly lines. The -th line must contain a single integer: the minimum number of broadcast nodes needed so that every house can watch the drama after the first attacks (that is, once the first attacked connections have all been removed).