-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19.cpp
49 lines (47 loc) · 1.02 KB
/
19.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
/*
基于图的深度优先搜索策略
*/
#include<iostream>
#define MAX 200
using namespace std;
bool visit[MAX]={false};
class Grap{
private:
int m, n; //n:顶点数 m:边数
int vi[MAX]; //顶点信息
int ver[MAX][2]; //边的信息
public:
Grap();
bool deep_serch(int vi, int vj);
};
Grap::Grap(){
cin>>n>>m;
for(int i = 0; i < n; i++){
cin>>vi[i];
}
for(int i = 0; i < m; i++){
cin>>ver[i][0]>>ver[i][1];
}
}
bool Grap::deep_serch(int vi, int vj){
for(int i = 0; i < m; i++){
if(ver[i][0] == vi){
visit[vi] = true;
if(ver[i][1] == vj){
return true;
}else{
if(!visit[ver[i][1]] && deep_serch(ver[i][1], vj)) return true;
}
}
}
return false;
}
int main()
{
Grap M;
int vi, vj;
cin>>vi>>vj;
if(M.deep_serch(vi, vj)) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
}