forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(SPOJ)AKBAR- Akbar, The great.cpp
89 lines (85 loc) · 1.31 KB
/
(SPOJ)AKBAR- Akbar, The great.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//https://www.spoj.com/problems/AKBAR/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct node
{
ll name,dis,prev;
};
vector<long> adj[1000002];
int flag[1000002];
bool bfs(ll s,ll d,ll prev)
{
bool result=true;
node temp;
temp.name=s;
temp.dis=d;
temp.prev=-1;
queue<node> q;
q.push(temp);
while(!q.empty())
{
temp=q.front();
q.pop();
flag[temp.name]++;
if(flag[temp.name]==1)
result=false;
if(temp.dis>0)
{
vector<long>::iterator ii;
for(ii=adj[temp.name].begin();ii!=adj[temp.name].end();ii++)
{
if(*ii==temp.prev)
continue;
node temp1;
temp1.prev=temp.name;
temp1.name=*ii;
temp1.dis=temp.dis-1;
q.push(temp1);
}
}
}
return result;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n,r,m;
scanf("%lld%lld%lld",&n,&r,&m);
ll i;
for(i=0;i<=n;i++)
{
flag[i]=0;
adj[i].clear();
}
for(i=0;i<r;i++)
{
ll s,d;
scanf("%lld%lld",&s,&d);
adj[s].push_back(d);
adj[d].push_back(s);
}
bool res=false;
for(i=0;i<m;i++)
{
ll s,d;
scanf("%lld%lld",&s,&d);
if(!res)
{
if(bfs(s,d,-1))
{
res=true;
}
}
}
if(res)
printf("No");
else
printf("Yes");
printf("\n");
}
return 0;
}