-
Notifications
You must be signed in to change notification settings - Fork 0
/
Two hop
39 lines (35 loc) · 837 Bytes
/
Two hop
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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--) {
int n, m, q;
cin >> n >> m >> q;
vector< vector<int> > matrix(n + 1, vector<int>(n + 1, 0));
while (m--) {
int u, v;
cin >> u >> v;
matrix[u][v] = 1;
matrix[v][u] = 1;
}
while (q--) {
int u, v;
cin >> u >> v;
bool fi = false;
for (int i = 0; i < matrix[u].size(); ++i) {
if (matrix[u][i] == 1 && matrix[i][v] == 1) {
fi = true;
cout << "Y\n";
break;
}
}
if (!fi) {
cout << "N\n";
}
}
}
return 0;
}