Pagini recente » Cod sursa (job #1249203) | Cod sursa (job #2622536) | Cod sursa (job #3261381) | Cod sursa (job #1497920) | Cod sursa (job #542348)
Cod sursa(job #542348)
#include <stdio.h>
#include <vector>
#include <set>
#include <queue>
using namespace std;
#define nmax 100005
vector<int> Gs[nmax], Gf[nmax], stie;
set<int> G[nmax];
int N, M, Q;
queue<int> Coada;
void citire ()
{
int i, x, y;
scanf("%d%d%d", &N, &M, &Q);
for (i = 1; i <= M; ++i)
{
scanf("%d%d", &x, &y);
Gs[x].push_back(y);
Gf[y].push_back(x);
}
}
void solve ()
{
int tip, x, y, i, nod;
while (Q--)
{
scanf("%d%d%d", &tip, &x, &y);
if (tip == 2)
{
Coada.push(y);
while (!Coada.empty())
{
nod = Coada.front(); Coada.pop();
stie.push_back(nod);
for (i = 0; i < Gf[nod].size(); ++i)
Coada.push(Gf[nod][i]);
}
Coada.push(x);
while (!Coada.empty())
{
nod = Coada.front(); Coada.pop ();
for (i = 0; i < stie.size(); ++i) G[nod].insert(stie[i]);
for (i = 0; i < Gs[nod].size(); ++i)
Coada.push(Gs[nod][i]);
}
Coada.push(x);
while (!Coada.empty())
{
nod = Coada.front(); Coada.pop();
for (i = 0; i < stie.size(); ++i) G[nod].insert(stie[i]);
for (i = 0; i < Gf[nod].size(); ++i)
Coada.push(Gf[nod][i]);
}
stie.clear();
}
else
if (G[x].find(y) != G[x].end() ) printf("YES\n");
else printf("NO\n");
}
}
int main ()
{
freopen("gossips.in","r",stdin);
freopen("gossips.out","w",stdout);
citire ();
solve ();
return 0;
}