Pagini recente » Monitorul de evaluare | Diferente pentru utilizator/protoman intre reviziile 74 si 63 | Monitorul de evaluare | Cod sursa (job #2677493) | Cod sursa (job #2615878)
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int t[100005],n,m;
int Find(int x){
int r=x,r1;
while(t[r]){
r=t[r];
}
while(t[x]){
r1=t[x];
t[x]=r;
x=r1;
}
return r;
}
void Union(int x,int y){
t[y]=x;
}
void rez(){
f>>n>>m;
int i,c,x,y;
for(i=1;i<=m;i++){
f>>c>>x>>y;
x=Find(x);
y=Find(y);
if(c==1){
Union(x,y);
}else{
if(x==y){
g<<"DA \n";
}else{
g<<"NU \n";
}
}
}
}
int main()
{
rez();
return 0;
}