-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode : Has Path
More file actions
51 lines (51 loc) · 941 Bytes
/
Code : Has Path
File metadata and controls
51 lines (51 loc) · 941 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 <iostream>
using namespace std;
void printDFS(int **arr,int V,int si,int ei,int *v){
v[si]=true;
for(int i=0;i<V;i++){
if(si==i){
continue;
}
if(arr[si][i]==1){
if(v[i]) {
continue;
}
printDFS(arr,V,i,ei,v);
}
}
}
int main() {
int V, E;
cin >> V >> E;
int **arr=new int*[V];
for(int i=0;i<V;i++){
arr[i]=new int[V];
for(int j=0;j<V;j++){
arr[i][j]=0;
}
}
for(int i=0;i<E;i++){
int f,s;cin>>f>>s;
arr[f][s]=1;
arr[s][f]=1;
}
int *v=new int[V];
for(int i=0;i<V;i++){
v[i]=false;
}
int si,ei;
cin>>si>>ei;
printDFS(arr,V,si,ei,v);
if(v[ei]){
cout<<"true";
}
else{
cout<<"false";
}
for(int i=0;i<V;i++){
delete [] arr[i];
}
delete [] arr;
delete [] v;
return 0;
}