Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<vector<int> > g;
- vector<int> tin, fup, used;
- int timer = 0;
- void dfs(int v, int p = -1){
- used[v] = 1;
- tin[v] = timer;
- fup[v] = tin[v];
- timer++;
- int ch = 0;
- for(auto to: g[v]){
- if(to == p) continue;
- if(used[to]) {
- fup[v] = min(fup[v], tin[to]);
- } else {
- dfs(to, v);
- ch++;
- fup[v] = min(fup[v], fup[to]);
- if(fup[to] >= tin[v] && p != -1){
- cout << v << endl;
- }
- }
- }
- if(ch > 1 && p == -1)
- cout << v << endl;
- }
- signed main() {
- #ifdef DEBUG
- freopen("input.txt", "r", stdin);
- #endif
- int n, m;
- cin >> n >> m;
- g.resize(n);
- used.resize(n, 0);
- tin.resize(n, 0);
- fup.resize(n, 1e9+9);
- for(int i = 0; i < m; i++){
- int u, v;
- cin >> u >> v;
- u--, v--;
- g[u].push_back(v);
- g[v].push_back(u);
- }
- dfs(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement