Pagini recente » Cod sursa (job #1527501) | Cod sursa (job #2876513) | Cod sursa (job #2435417) | Cod sursa (job #2650988) | Cod sursa (job #369709)
Cod sursa(job #369709)
#include<fstream>
#include<stdlib.h>
using namespace std;
#define endl '\n'
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int v[100001],n,m;
int main(){
int op,i,x,y,j,z,w;
char s[30],*p;
fin>>n>>m;
fin.get();
for(i=1;i<=n;i++) v[i]=i;
for(i=1;i<=m;i++){
fin.get(s,29);
fin.get();
p=s;
op=atoi(s);p+=2;
x=atoi(p);
while(*p!=' ')p++;
p++;
y=atoi(p);
z=v[x];
w=v[y];
if(op==1){
for(j=1;j<=n;j++)
if(v[j]==w) v[j]=z;
}
else
if(v[x]==v[y]) fout<<"DA"<<endl;
else fout<<"NU"<<endl;
}
return 0;
}