Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define ll long long
- #define ld long double
- #define sqr(a) (a) * (a)
- #define F first
- #define S second
- using namespace std;
- //mt19937 gen(time(0));
- const int maxn = 1e4 + 10;
- vector <int> g[maxn];
- map <pair <int, int>, int> mp;
- map <pair <int, int>, int> cnmp;
- int tin[maxn];
- int up[maxn];
- int timer = 0;
- bool dot[maxn];
- bool bridge[maxn * 10];
- void dfs(int v, int pr)
- {
- timer++;
- tin[v] = timer;
- up[v] = timer;
- int cnt = 0;
- for(int to:g[v])
- {
- if (to == pr) continue;
- if (tin[to] == 0)
- {
- cnt++;
- dfs(to, v);
- up[v] = min(up[v], up[to]);
- if (up[to] >= tin[v] && pr != -1)
- {
- dot[v] = true;
- }
- int x = v;
- int y = to;
- if (y > x) swap(x, y);
- if (up[v] < up[to] && cnmp[make_pair(x, y)] == 1)
- {
- bridge[mp[make_pair(x, y)]] = true;
- }
- }
- else
- {
- up[v] = min(up[v], tin[to]);
- }
- }
- if (pr == -1 && cnt > 1)
- {
- dot[v] = true;
- }
- return;
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- cin >> n >> m;
- for(int i = 0; i < m; i++)
- {
- int x, y;
- cin >> x >> y;
- x--;
- y--;
- if (y > x) swap(x, y);
- g[x].pb(y);
- g[y].pb(x);
- mp[make_pair(x, y)] = i;
- cnmp[make_pair(x, y)]++;
- }
- for(int i = 0; i < n; i++)
- if (tin[i] == 0) dfs(i, -1);
- int cnt = 0;
- for(int i = 0; i < m; i++)
- if (bridge[i]) cnt++;
- cout << cnt << '\n';
- for(int i = 0; i < m; i++)
- if (bridge[i]) cout << i + 1 << '\n';
- cnt = 0;
- for(int i = 0; i < n; i++)
- if (dot[i]) cnt++;
- cout << cnt << '\n';
- for(int i = 0; i < n; i++)
- if (dot[i]) cout << i + 1 << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement