Under construction

Still being built. Things may change

Navy

Time limit25sMemory limit1024 MB

Summary
For each night t, count the rivers whose removal splits the graph, where the rivers are the union of the sets A for weather B_t and B_(t+1).
Level

Hard9 of 10

Topics
Divide and conquer, Union-find, Graph
Solved
No attempts yet

Problem

Byteland has NN lakes, and some rivers directly connect pairs of lakes. You are the naval commander of Byteland, and you want to plan a strategy for the coming war.

Byteland's intelligence service reports that the war will last T+1T+1 days, and that a battle takes place on each night between consecutive days. That is, for every 1≤i≤T1 \le i \le T, a battle takes place on the night between day ii and day i+1i+1.

Treat the lakes and rivers of Byteland as a graph. If removing a river increases the number of connected components, the river is called a critical river. (In graph theory, such a river is called a cut edge.)

Lakes always hold water, but rivers may dry up depending on the weather. That is, a pair of lakes may or may not be directly connected by a river. Byteland has MM kinds of weather, and weather ii creates a river for each pair of lakes in the set AiA_i.

Scientists found the weather BiB_i for each day ii from 11 to T+1T+1. Scientists predicted that on the night between day ii and day i+1i+1, when a battle takes place, the set of rivers is ABi∪ABi+1A_{B_i} \cup A_{B_{i+1}}.

Using these predictions, output the number of critical rivers for each of the TT battles.

A set may contain the same element two or more times (a multiset), and the lakes and rivers may not form a planar graph.

Input

The first line contains three integers NN, MM, and TT. (1≤N,M≤100 0001 \le N, M \le 100\,000, 1≤T≤200 0001 \le T \le 200\,000)

The second line contains T+1T+1 integers B1,B2,…,BT+1B_1, B_2, \ldots, B_{T+1}. (1≤Bi≤M1 \le B_i \le M)

The next MM lines describe the sets AiA_i. Each line contains 2Ki+12K_i + 1 integers. The first integer is the size KiK_i of AiA_i. The next 2Ki2K_i integers list, in order, the numbers of the lakes that each pair of lakes in that weather connects. The two lake numbers in each pair are different.

The sum of all KiK_i does not exceed 200 000200\,000.

Output

Print TT lines. Line ii contains the number of critical rivers for the ii-th battle.

Examples2

  1. Example 1

    Input
    4 3 4
    1 1 2 3 1
    1 1 2
    1 3 4
    2 2 3 2 3
    
    Expected output
    0
    2
    1
    1
    
  2. Example 2

    Input
    7 3 3
    1 2 3 1
    4 1 2 1 3 5 7 6 7
    4 2 3 3 4 4 5 5 6
    3 1 4 4 7 2 6
    
    Expected output
    2
    2
    2