Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #675364) | Cod sursa (job #2935662)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int Nmax=1e5;
int n,m;
vector <int> T[Nmax+3];
void leaga(int a,int b)
{
if(b<a)
swap(a,b);
for(auto pct : T[b])
T[a].push_back(pct);
}
int main()
{
f >> n >> m;
for(int i=1; i<=n; i++)
T[i].push_back(i);
for(int i=1; i<=m; i++)
{
int op,a,b;
f >> op >> a >> b;
if(op==1)
leaga(a,b);
else
{
bool gasit=0;
for(auto pct : T[a])
if(pct==b)
g << "DA\n", gasit=1;
if(!gasit)
g << "NU\n";
}
}
return 0;
}