-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathda_pra_chegar.cpp
More file actions
51 lines (38 loc) · 805 Bytes
/
da_pra_chegar.cpp
File metadata and controls
51 lines (38 loc) · 805 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
#include <bits/stdc++.h>
#include <array>
using namespace std;
void dfs(int u, int f, int *vis, array<vector<int>, 100000> &nodes) {
vis[u] = 1;
for (int i = 0; i < nodes[u].size(); i++) {
int v = nodes[u][i];
if (v == f)
{
cout << "SIM" << endl;
exit(0);
}
if (vis[v] == 0) {
dfs(v, f, vis, nodes);
}
}
}
int main() {
int n, m, a, b, c, d;
cin >> n;
cin >> m;
cin >> a;
cin >> b;
if (a == b) {
cout << "SIM\n";
return 0;
}
array<vector<int>, 100000> nodes;
int vis[n+1] = {0};
for (int i = 0; i < m; i++) {
cin >> c;
cin >> d;
nodes[c].push_back(d);
}
dfs(a, b, vis, nodes);
cout << "NAO\n";
return 0;
}