Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ad
#include<bits/stdc++.h> using namespace std; #define mem(A) memset(A,0,sizeof(A)) #define loop(i,a,n) for(i=a;i<n;i++) #define pb push_back #define mkp make_pair #define prq priority_queue #define fir first #define sec second #define all(A) A.begin(),A.end() #define mod 1000000007 typedef long long ll; ll A[100005]; void init(ll n) { ll i; loop(i,0,n) { A[i]=i; } } ll root(ll i) { while(A[i]!=i) { i=A[i]; } return i; } void con(ll x,ll y) { ll rx=root(x); ll ry=root(y); if(rx==ry) return; if(A[rx]<A[ry]) A[rx]=A[ry]; else A[ry]=A[rx]; } int main() { //freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ll n,i,m,x,y,c,q,rx,ry; cin>>n>>q; init(n); while(q--) { cin>>c; if(c==1) { cin>>x>>y; rx=root(x-1); ry=root(y-1); A[rx]=A[ry]; } else if(c==2) { cin>>x; rx=root(x-1); A[rx]=x-1; } else { cin>>x; cout<<root(x-1)+1; } } }
run
|
edit
|
history
|
help
0
BubDoubArray2
Rubix
cppbasic
dia
Backpack with recursion
Quadratic Equation
Dynamic Programming For Combinatorics - 1
-Wall -std=c++14 -O0 -o a.out source_file.cpp
c2p_update
5