-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
76 lines (44 loc) · 929 Bytes
/
graph.cpp
File metadata and controls
76 lines (44 loc) · 929 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
int mx = INT_MAX;
const int arr_limit = 1e7+10;
//int arr[arr_limit];
const int graph_v_limit = 1e5+10;
vector<int> g[graph_v_limit];
bool visited[graph_v_limit];
void dfs(int vertex){
cout << vertex<< endl;
visited[vertex] = 1;
for(auto child : g[vertex]){
if(visited[child]) continue;
dfs(child);
}
}
bool has_cycle(int vertex){
cout << vertex<< endl;
visited[vertex] = 1;
for(auto child : g[vertex]){
if(visited[child]){
cout<<" making cycle";
return true;
}
has_cycle(child);
}
cout << " oustside for";
return false;
}
int main(){
// int l = sizeof(g)/sizeof(g[0]);
// cout<< "hello world " << l << typeid(g[0]).name() << endl;
// cout<< mx;
int v,e;
cin >> v >> e;
for(int i=0; i<e;++i){
int v1,v2;
cin >> v1 >>v2;
g[v1].push_back(v2);
g[v2].push_back(v1);
}
cout << has_cycle(0) << endl;
return 1;
}