Experiment in Berland
Practice
4.8 (6 votes)
Data structures
Depth first search
Algorithms
Disjoint set union
Graphs
Problem
73% Success 592 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Alice, a well-known scientist in Berland, has a floor of size \(N*M\) in his research laboratory, with each tile measuring \(1X1\). If a drop of chemical falls on a tile, it will combine to form a larger drop if there is a drop of chemical solution present in the adjacent tile that shares the common sides or edges.
Note: If a chemical solution falls on the same tile, the size does not change and all indexing are 1 based


You will be given \(Q\) queries, each of which can be of two types .
Type \(1\): Represents coordinates of point on which chemical drop falls
Type \(0\): Print total number of large drops formed till now.

query of type \(1\) representing the coordinates of a cell on which chemical drop will fall and for each query of type \(0\)find the number of connected components in the grid.

Input Format

First line contain \(3\) integers \(N,M\) and \(Q\) representing the number of rows, columns and the number of queries.

Next \(Q\) lines contain \(1\) integer which represents the type of query that has been asked.


For query of type \(1\), there will be \(2\) more integer \(x\) and \(y\) which represent the coordinate of cells on which chemical solution is falling on.

for query of type \(0\)you have to output the number of large drops till now

Output Format

For each query of type \(0\) output the total number of large drops till now

Constraints

\(1 \leq N,M \leq 10^3\)

\(1 \leq x \leq N\)

\(1 \leq y \leq M\)

\(1 \leq Q \leq 101000\)

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
2 votes
Tags:
AlgorithmsDepth First SearchGraphsMedium
Points:30
16 votes
Tags:
AlgorithmsApprovedGraphsMediumOpenTrees
Points:30
10 votes
Tags:
Binary SearchGraphsAlgorithmsDepth First SearchDFS