Ap.c++ ==== ``` #include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <set> using namespace std; vector<vector<int>> adj; vector<int> DFN, Low, parent; vector<bool> visited; int timer = 0; set<int> articulation_points; void DFS(int u) { visited[u] = true; DFN[u] = Low[u] = timer++; int children = 0; for (int v : adj[u]) { if (!visited[v]) { children++; parent[v] = u; DFS(v); Low[u] = min(Low[u], Low[v]); if (parent[u] == -1 && children > 1) articulation_points.insert(u); if (parent[u] != -1 && Low[v] >= DFN[u]) articulation_points.insert(u); } else if (v != parent[u]) { Low[u] = min(Low[u], DFN[v]); } } } int main() { ifstream file("AP.txt"); if (!file) { cerr << "Unable to open file AP.txt"; exit(1); } int n; file >> n; vector<int> values(n); vector<int> index(n); vector<int> search_order(10); for (int i = 0; i < n; i++) file >> index[i]; for (int i = 0; i < n; i++) file >> values[i]; for (int i = 0; i < values[0]-1; i++) file >> search_order[i]; adj.resize(values[0]-1); DFN.resize(values[0]-1, -1); Low.resize(values[0]-1, -1); parent.resize(values[0]-1, -1); visited.resize(values[0]-1, false); for (int i = 0; i < values[0]-1; i++) { int start = values[i]; int end = values[i+1]; for (int j = start; j < end; j++) { adj[i].push_back(values[j]); adj[values[j]].push_back(i); } } for (int i = 0; i < values[0]-1; i++) { if (!visited[search_order[i]]) DFS(search_order[i]); } for (int i = 0; i < values[0]-1; i++) { cout << "Node " << i << ": DFN = " << DFN[i] << ", Low = " << Low[i] << endl; } cout << "Articulation points: "; for (int point : articulation_points) { cout << point << " "; } cout << endl; return 0; } ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up