| 2 | using namespace std; |
| 3 | |
| 4 | void dfs(unordered_set<int> &artpoints, vector<int> &time, vector<int> &lowest, vector<int> adj[], |
| 5 | vector<int> &visited, int node, int &currTime, int parent) |
| 6 | { |
| 7 | visited[node] = 1; |
| 8 | time[node] = lowest[node] = currTime++; |
| 9 | for (int adjacent : adj[node]) |
| 10 | { |
| 11 | if (adjacent == parent) |
| 12 | continue; |
| 13 | |
| 14 | if (visited[adjacent] == 0) |
| 15 | { |
| 16 | dfs(artpoints, time, lowest, adj, visited, adjacent, currTime, node); |
| 17 | lowest[node] = min(lowest[node], lowest[adjacent]); |
| 18 | |
| 19 | if (parent != -1 and lowest[adjacent] >= time[node]) |
| 20 | artpoints.insert(node); |
| 21 | } |
| 22 | |
| 23 | lowest[node] = min(lowest[node], lowest[adjacent]); |
| 24 | } |
| 25 | // specific case for starting point |
| 26 | if (parent == -1 and adj[node].size() > 1) |
| 27 | { |
| 28 | for (int adjacent : adj[node]) |
| 29 | { |
| 30 | if (lowest[adjacent] > time[node]) |
| 31 | { |
| 32 | artpoints.insert(node); |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | int main() |
| 40 | { |
no test coverage detected