Hate Stagnant Water
InterviewTime limit1sMemory limit1024 MB
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 water tanks. Each tank stores either clean water or stagnant water. The tanks are connected to each other by pipes for easier supply.
When he visits tank to get clean water, he can get clean water if, among tank and the tanks he can reach from tank 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 (), the number of pipes (), and the number of visits ().
The second line contains the type of water in tanks through , in order. Clean water is given as 1 and stagnant water as 0.
From the 3rd line to the th line, each line contains two tank numbers and (, ) connected by a pipe. Multiple pipes may connect the same pair of tanks.
From the th line to the th line, each line contains a tank number () 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 lines.