-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAkbar.cpp
82 lines (66 loc) · 1.42 KB
/
Akbar.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Author - Kevin Mathew
// Birla Institute of Technology, Mesra
ll n, r, m, vis[1000100];
vector<ll> graph[1000100];
void init(){
for(ll i=0;i<1000100;i++)
vis[i] = 0;
}
void te(){
cin >> n >> r >> m;
for(ll i=0;i<n;i++)
graph[i].clear();
for(ll i=0;i<r;i++){
ll u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
init();
queue<pair<pair<ll, ll>, ll> > q;
for(ll i=0;i<m;i++){
ll k, s;
cin >> k >> s;
q.push(make_pair(make_pair(k, s), i + 1));
vis[k] = i + 1;
}
while(!q.empty()){
pair<pair<ll, ll>, ll> a = q.front();
q.pop();
// cout << a.first.first << " " << a.first.second << " " << a.second << "\n";
if(vis[a.first.first] != 0 && vis[a.first.first] != a.second){
cout << "No\n";
return;
}
vis[a.first.first] = a.second;
if(a.first.second == 0)
continue;
for(ll v : graph[a.first.first]){
// cout << v << " " << vis[v] << "--\n";
if(vis[v] != a.second)
q.push(make_pair(make_pair(v, a.first.second - 1), a.second));
}
}
for(ll i=1;i<=n;i++)
if(vis[i] == 0){
cout << "No\n";
return;
}
cout << "Yes\n";
}
int main()
{
// freopen("input.txt", "r", stdin); //Comment
// freopen("output.txt", "w", stdout); //this out.
ios::sync_with_stdio(false); //Not
cin.tie(NULL); //this.
cout.tie(0); //or this.
ll T;
cin >> T;
while(T--)
te();
return 0;
}