Pagini recente » Cod sursa (job #1706858) | Cod sursa (job #2904670) | Cod sursa (job #179872) | Cod sursa (job #2904677) | Cod sursa (job #1290621)
# include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 5;
int s[nmax];
int find(int x)
{
return (x == s[x] ? x:s[x] = find(s[x]));
}
int main(void)
{
int n,m,t,x,y;
ifstream fi("disjoint.in");
ofstream fo("disjoint.out");
fi>>n>>m;
for (int i=1;i<=n;++i) s[i]=i;
while (m --)
{
fi>>t>>x>>y;
if (t == 1) s[x]=find(s[y]);else fo << (s[x] == s[y] ? "DA\n":"NU\n");
}
return 0;
}