Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define endl '\n'
- #define MAX 412
- #define NIL -1
- int bg[MAX], low[MAX];
- vector<int> adj[MAX];
- int T = 1;
- set <int> articulation;
- void dfs (int v, int anc) {
- low[v] = bg[v] = T++;
- int children = 0;
- for (int i = 0; i < adj[v].size(); i++) {
- int u = adj[v][i];
- if( bg[u] == 0 ) {
- children++;
- dfs(u, v);
- low[v] = min(low[v], low[u]);
- if (anc == NIL) {
- if (children > 1)
- articulation.insert(v);
- }
- else {
- if (bg[v] <= low[u])
- articulation.insert(v);
- }
- }
- else if (u != anc)
- low[v] = min(low[v], low[u]);
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int N, M;
- int test = 1;
- for (cin >> N >> M; N; cin >> N >> M) {
- for (int n = 0; n < N; n++) {
- low[n] = bg[n] = 0;
- adj[n].clear();
- }
- articulation.clear();
- for (int m = 0; m < M; m++) {
- int a, b;
- cin >> a >> b;
- a--, b--;
- adj[a].push_back(b);
- adj[b].push_back(a);
- }
- for (int n = 0; n < N; n++)
- if (!bg[n])
- dfs(n, NIL);
- cout << "Teste " << test++ << endl;
- if ( articulation.empty() )
- cout << "nenhum";
- for(set<int>::iterator it = articulation.begin(); it != articulation.end(); ++it)
- cout << *it + 1 << " ";
- cout << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement