-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcriticalIntersections.cpp
More file actions
53 lines (43 loc) · 1.03 KB
/
criticalIntersections.cpp
File metadata and controls
53 lines (43 loc) · 1.03 KB
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
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjList;
vector<bool> visited;
void dfs(int node, int forbidden) {
visited[node] = true;
for (auto i: adjList[node]) {
if (!visited[i]) {
if (i == forbidden) continue;
dfs(i, forbidden);
}
}
}
int main ()
{
int n, m;
cin >> n >> m;
adjList = vector<vector<int>>(n+1);
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
adjList[x].emplace_back(y);
adjList[y].emplace_back(x);
}
vector<int> ansFin;
for (int i = 1; i <= n; i++) {
visited = vector<bool> (n+1, false);
int forbid = 1;
if (i == 1) forbid = 2;
dfs(forbid, i);
for (int j = 1; j <= n; j++) {
if (i == j) continue;
if (!visited[j]) {
ansFin.push_back(i);
break;
}
}
}
cout << ansFin.size() << "\n";
for (auto i: ansFin) cout << i << " ";
cout << "\n";
}