-
Notifications
You must be signed in to change notification settings - Fork 1
/
AKBAR - Akbar , The great.cc
57 lines (54 loc) · 1.3 KB
/
AKBAR - Akbar , The great.cc
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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int seen[1000010];
vvi edges;
bool BFS(const int K, const int S, const int id) {
if (seen[K])
return false;
seen[K] = id;
queue<int> Q;
Q.push(K);
int curr, until;
for (int i = 0; i < S; i++) {
until = (int)Q.size();
while (until--) {
curr = Q.front();
Q.pop();
for (auto& e : edges[curr]) {
if (seen[e] && seen[e] != id)
return false;
else if (!seen[e])
Q.push(e), seen[e] = id;
}//for
}//while
}//for
return true;
}//BFS
int main() {
int T, N, R, M, n1, n2, k, s;
bool valid;
scanf("%d", &T);
while (T--) {
scanf("%d %d %d", &N, &R, &M);
edges.assign(N + 5, vi());
memset(seen, 0, sizeof(int) * (N + 5));
while (R--) {
scanf("%d %d", &n1, &n2);
edges[n1].push_back(n2);
edges[n2].push_back(n1);
}//while
valid = true;
for (int i = 1; i <= M; i++) {
scanf("%d %d", &k, &s);
if (valid)
valid = BFS(k, s, i);
}//for
for (int i = 1; i <= N && valid; i++)
if (!seen[i])
valid = false;
valid ? puts("Yes") : puts("No");
}//while
return 0;
}//main