Pagini recente » Cod sursa (job #861745) | Statistici Andronache Madalina (madalina.andron) | Cod sursa (job #1504789) | Cod sursa (job #2795866) | Cod sursa (job #729620)
Cod sursa(job #729620)
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int m,n;
int t[100000];
int sefu(int x)
{
if(t[x]==0)
return x;
int s= sefu(t[x]);
t[x] =s;
return s;
}
int main()
{
string tmp;
in>>tmp;
n = atoi(tmp.c_str());
in>>tmp;
m = atoi(tmp.c_str());
int x,y;
for(int i=1;i<=m;i++)
{
in>>tmp;
if(atoi(tmp.c_str())==1)
{in>>tmp;
x = atoi(tmp.c_str());
in>>tmp;
y = atoi(tmp.c_str());
t[sefu(x)]=sefu(x);}
else
{in>>tmp;
x = atoi(tmp.c_str());
in>>tmp;
y = atoi(tmp.c_str());
if((sefu(x)==sefu(y))&&(sefu(x)!=0))
out<<true<<endl;
else out<<false<<endl;}
}
return 0;
}