Under construction

Still being built. Things may change

Hate Stagnant Water

Interview

Time limit1sMemory limit1024 MB

Summary
For each visited tank K, decide whether its connected component has more clean (1) tanks than stagnant (0) tanks.
Level

Easy3 of 10

Topics
Union-find, Graph
Solved
No attempts yet

Problem

Jaehyeong likes clean water and hates stagnant water. Today he also visits a village with water tanks to get clean water.

The village has NN water tanks. Each tank stores either clean water or stagnant water. The tanks are connected to each other by MM pipes for easier supply.

When he visits tank KK to get clean water, he can get clean water if, among tank KK and the tanks he can reach from tank KK through zero or more pipes, the number of tanks with clean water is greater than the number of tanks with stagnant water.

For each visit described in the input, determine whether he can get clean water.

Input

The first line contains the number of tanks NN (1≤N≤100 0001 \leq N \leq 100\,000), the number of pipes MM (0≤M≤200 0000 \leq M \leq 200\,000), and the number of visits QQ (1≤Q≤100 0001 \leq Q \leq 100\,000).

The second line contains the type of water in tanks 11 through NN, in order. Clean water is given as 1 and stagnant water as 0.

From the 3rd line to the (M+2)(M+2)th line, each line contains two tank numbers uu and vv (1≤u,v≤N1 \leq u, v \leq N, u≠vu \neq v) connected by a pipe. Multiple pipes may connect the same pair of tanks.

From the (M+3)(M+3)th line to the (M+Q+2)(M+Q+2)th line, each line contains a tank number KK (1≤K≤N1 \leq K \leq N) that Jaehyeong visits.

Output

For each visit, print 1 if he can get clean water at that tank, and 0 otherwise. Print the answers in the order of the input queries, one per line, a total of QQ lines.

Examples2

  1. Example 1

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

    Input
    5 5 3
    1 0 1 1 0
    1 2
    1 3
    1 4
    2 3
    3 4
    1
    5
    4
    
    Expected output
    1
    0
    1