-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTEOBALDO.cpp
48 lines (40 loc) · 1.01 KB
/
TEOBALDO.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
#include <bits/stdc++.h>
using namespace std;
int dist[101][2];
vector<int> adj[101];
void bfs(int n){
queue< pair<int, int> > q;
q.push(make_pair(n,0));
dist[n][0]=0;
while(!q.empty()){
pair<int,int> vertice = q.front();
q.pop();
for(int i=0; i<adj[vertice.first].size(); i++){
if(dist[adj[vertice.first][i]][!vertice.second] == 0x3f3f3f3f){
dist[adj[vertice.first][i]][!vertice.second] = dist[vertice.first][vertice.second]+1;
q.push(make_pair(adj[vertice.first][i],!vertice.second));
}
}
}
}
int main(){
int c,e;
while(cin >> c >> e, c+e != 0){
for(int i=1; i<=c; i++){
dist[i][0]=0x3f3f3f3f;
dist[i][1]=0x3f3f3f3f;
adj[i].clear();
}
for(int i=0; i<e; i++){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
int ini,fim,d;
cin >> ini >> fim >> d;
bfs(ini);
if((d%2==0 && dist[fim][0] <= d) || (d%2==1 && dist[fim][1] <= d)) cout << "Yes, Teobaldo can travel." << endl;
else cout << "No, Teobaldo can not travel."<< endl;
}
}