Cod sursa(job #3373325)
| Utilizator | Data | 6 noiembrie 2026 16:36:54 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.63 kb |
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n,m,parent[nmax]={0},x,y,cod;
int getroot(int nod){
if(parent[nod]==0)return nod;
int rad=getroot(parent[nod]);
parent[nod]=rad;
return rad;
}
void unite(int x, int y){
parent[getroot(x)]=getroot(y);
}
int main()
{
f>>n>>m;
for(int i=1;i<=m;i++)
{
f>>cod>>x>>y;
if(cod==1){
unite(x,y);
}
else {
if(getroot(x)==getroot(y)) g<<"DA\n";
else g<<"NU\n";
}
}
return 0;
}
