Boruto and Dojutsu
Practice
3 (10 votes)
Data structures
Disjoint set
Easy
Problem
76% Success 2034 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Boruto subconsciously awakened a Dojutsu (magic) in his right eye which has a lot of special powers. One of its powers includes the ability to track a target through its chakra (energy). One day while training, Boruto marks N targets, each of which has some color \(A_{i}\). Some of the targets are connected to each other, as a result of which these N targets form a colorful undirected graph G with N nodes (denoting the N targets), indexed from 1 to N and M edges (denoting the M connections between the targets), indexed from 1 to M.

Using the power of his eye, Boruto was able to find the number of distinct colors in the connected component containing any particular target. Now Boruto wants to know the number of distinct colors in the connected component containing any particular target if the connections between the targets are being removed dynamically. As he is at an early stage of learning how to use Dojutsu, he wants your help in getting the answer to this problem.

enter image description here

Input Format
The first line of input contains 3 space separated integers N, M and Q denoting the number of targets, the number of connections between the targets and the number of operations to be performed respectively.
The second line contains N space-separated integers, \(i^{th}\) of which denotes the color of the target i.
The next M lines contain 2 space separated integers U and V which depicts a connection between targets U and V. \(i^{th}\) line denotes the \(i^{th}\) edge.
This is followed by Q lines, each describing an operation in the following format:-

  1. \(1\;X\) : Remove the connection (edge) numbered X.
  2. \(2\;Y\) : Print the number of distinct colors in the connected component containing target (node) Y.

Output Format
The output should consist of the answer to each of the operation of the \(2^{nd}\) type printed on a new line.

Constraints

  • \(1 \le N \le 10^{5}\)
  • \(1 \le M,Q \le 2\times 10^{5}\)
  • \(1 \le A_{i} \le 10^{2}\)
  • \(1 \le U,V \le N\)
  • \(1 \le X \le M\)
  • \(1 \le Y \le N\)
  • There are no self loops or multiple edges in the graph.

Note
If there are multiple queries for removal of the same edge, then the last such query should be considered. Also, the index of the connections does not change after removal of any of the connections between the targets.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
Data StructuresDisjoint setEasyGraphs
Points:30
68 votes
Tags:
ApprovedData StructuresDisjoint setEasyOpen
Points:30
79 votes
Tags:
ApprovedData StructuresDisjoint setEasyOpen