-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBFS_13700_완전 범죄.cpp
55 lines (45 loc) · 967 Bytes
/
BFS_13700_완전 범죄.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
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int tower, pawn, home, gofront, goback, police, result;
vector <int> town;
queue <int> q;
bool bfs(int start, int end)
{
q.push(start);
town[start] = 1;
while (!q.empty() && q.front() != end)
{
if (q.front() + gofront < town.size() && town[q.front() + gofront] == 0)
{
q.push(q.front() + gofront);
town[q.front() + gofront] = town[q.front()] + 1;
}
if (q.front() - goback >= 0 && town[q.front() - goback] == 0)
{
q.push(q.front() - goback);
town[q.front() - goback] = town[q.front()] + 1;
}
q.pop();
}
if (town[end] != 0)
return true;
else
return false;
}
int main()
{
cin >> tower >> pawn >> home >> gofront >> goback >> police;
town.resize(tower);
for (int i = 0; i < police; i++)
{
int temp;
cin >> temp;
town[temp - 1] = -1;
}
if (bfs(pawn - 1, home - 1) == true)
cout << town[home - 1] - 1;
else
cout << "BUG FOUND";
}