Pagini recente » Cod sursa (job #1902061) | Cod sursa (job #2257671) | Cod sursa (job #1674818) | Cod sursa (job #2823556) | Cod sursa (job #2170298)
#include <fstream>
#define Nmax 100009
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n,m,x,y,p,root[Nmax];
int getroot(int x) {
if(root[x] != x) {
root[x] = getroot(root[x]);
}
return root[x];
}
void Solve1(int x, int y) {
root[getroot(y)]=getroot(x);
}
void Solve2(int x, int y) {
if (getroot(x) == getroot(y)) g<<"DA\n";
else g<<"NU\n";
}
void ReadInput() {
f>>n>>m;
for (int i=1; i<=n; ++i) root[i]=i;
for (int i=1; i<=m; ++i) {
f>>p>>x>>y;
if (p==1) {
Solve1(x,y);
}
else {
Solve2(x,y);
}
}
}
int main() {
ReadInput();
f.close();
g.close();
}