Cod sursa(job #721085)
| Utilizator | Data | 23 martie 2012 11:48:57 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream d("disjoint.in"); ofstream o("disjoint.out");
int cd,t,t1,t2,i,j,n,m,x,y;
int ta[100002];
int main()
{
d>>n>>m;
for (i=1;i<=m;i++)
{
d>>cd>>x>>y;
if (cd==1)
{
while (ta[x]!=0) x=ta[x];
while (ta[y]!=0) y=ta[y];
ta[x]=y;
}
else
{
while (ta[x]!=0) x=ta[x];
while (ta[y]!=0) y=ta[y];
if (x==y) o<<"DA"<<'\n'; else o<<"NU"<<'\n';
}
}
}