Pagini recente » Profil StarGold2 | Cod sursa (job #2968368) | Cod sursa (job #2956648) | Cod sursa (job #1567630) | Cod sursa (job #2816466)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
vector <vector<int>>v;
int f(int x,int y)
{
vector <int> viz;
viz.resize(100001);
queue<int> Q;
Q.push(x);
viz[x]=1;
while (!Q.empty())
{
int i=Q.front();
Q.pop();
for (int j=0;j<v[i].size();j++)
{
if (v[i][j]==y) return 1;
if (!viz[v[i][j]])
{
viz[v[i][j]]=1;
Q.push(v[i][j]);
}
}
}
return 0;
}
int main()
{
int n,m;
fin >>n>>m;
v.resize(1000001);
for (int i=1;i<=m;i++)
{
int intr;
fin >>intr;
int x,y;
fin >>x>>y;
if (intr==1)
{
v[x].push_back(y);
v[y].push_back(x);
}
else
{
if (f(x,y)==1) fout << "DA";
else fout << "NU";
fout <<"\n";
}
}
}