Under construction

Still being built. Things may change

Godzilla

Time limit1sMemory limit128 MB

Summary
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 nn nodes and mm 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 kk attacks, determine the minimum number of broadcast nodes required immediately after that attack.

Input

The first line contains two integers nn and mm (1≤n,m≤1000001 \le n, m \le 100000): the number of nodes and the number of connections in the network.

Each of the next mm lines contains two integers aa and bb (1≤a,b≤n1 \le a, b \le n, a≠ba \ne b), describing a one-way connection from node aa to node bb. 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 11 in the order they appear.

The next line contains an integer kk (1≤k≤m1 \le k \le m): the number of attacked connections. Each of the next kk lines contains the number of the connection attacked that day, given in chronological order.

Output

Print exactly kk lines. The ii-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 ii attacks (that is, once the first ii attacked connections have all been removed).

Examples1

  1. Example 1

    Input
    3 2
    1 2
    2 3
    2
    2
    1
    
    Expected output
    2
    3