-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccc13s4.cpp
More file actions
53 lines (43 loc) · 1020 Bytes
/
ccc13s4.cpp
File metadata and controls
53 lines (43 loc) · 1020 Bytes
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
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
bool dfs(int p, int q, vector<vector<bool>>& graph, vector<bool>& seen) {
// if (seen[p]) return false;
seen[p] = true;
if (p == q) return true;
for (int i = 1; i < graph[p].size(); i++) {
if (p == i) continue;
if (graph[p][i] && !seen[i]) {
if (dfs(i, q, graph, seen)) {
return true;
}
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<bool>> graph(n+1, vector<bool>(n+1));
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
graph[a][b] = true;
}
int p, q;
cin >> p >> q;
vector<bool> seen(n+1);
vector<bool> seen1(n+1);
if (dfs(p, q, graph, seen)) {
cout << "yes";
}
else if (dfs(q, p, graph, seen1)) {
cout << "no";
}
else {
cout << "unknown";
}
}