Xor thing
Practice
0 (0 votes)
Graph theory
Hard
Problem
20% Success 44 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Given a graph with vertices divided into N groups, each containing \(2^M\) vertices that are numbered from 0 inside the group.
Initially there is no edge. There are Q queries. Each query will be of one of the following 3 types:
\(1 \space i \space j \; p\): For every vertex numbered x from 0 to \(2^m-1\) add an edge between vertex x from group i and vertex \(x \oplus p\) from group j.
\(2 \; i \; x\): Find the size of component containing vertex x in group i.
3: Count the total number of connected components.

Input Format:
First line consists of three space separated integers denoting N, M and Q.
Q lines follow, each containing one of the given 3 types of queries.

Output Format:
For every query of type 2 and 3 print the required answer in a new line.

Constraints:
\(1 \le N \le 10^5\)
\(1 \le M \le 40\)
\(1 \le Q \le 4 \times 10^5\)
\(0 \le p, x \le 2^M-1\)
\(1 \le i, j \le N\)

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:10
2 votes
Tags:
ApprovedEasyGraphsReady
Points:50
1 votes
Tags:
Dynamic ProgrammingLinear AlgebraHardMatrix ExponentiationAlgorithmsMathematicsOpenApproved
Points:20
601 votes
Tags:
Easy