Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <vector>
- #include <tuple>
- #include <map>
- #include <set>
- #include <queue>
- #include <fstream>
- using namespace std;
- vector<vector<int>> g;
- vector<int> tin, up;
- vector<char> used;
- map<pair<int, int>, int> section;
- set<pair<int, int>> bridge;
- int timer = 0;
- void dfs(int v, int p){
- timer++;
- used[v] = true;
- tin[v] = up[v] = timer;
- for (auto to : g[v]){
- if (to == p) continue;
- if (used[to]){
- up[v] = min(up[v], tin[to]);
- } else {
- dfs(to, v);
- up[v] = min(up[v], up[to]);
- if (up[to] > tin[v]){
- bridge.insert({to, v});
- bridge.insert({v, to});
- }
- }
- }
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n, m;
- cin >> n >> m;
- g.resize(n + 1);
- tin.resize(n + 1);
- up.resize(n + 1);
- used.resize(n + 1, false);
- map<pair<int, int>, bool> f;
- for (int i = 1; i <= m; i++){
- int a, b;
- cin >> a >> b;
- if (section.count({a, b}) || section.count({b, a})){
- f[{a, b}] = true;
- f[{b, a}] = true;
- } else if (a != b){
- section[{a, b}] = i;
- g[a].push_back(b);
- g[b].push_back(a);
- }
- }
- for (int i = 1; i <= n; i++){
- if (!used[i]) dfs(i, -1);
- }
- int summ = 0;
- vector<int> ans;
- for (auto i: section){
- if (bridge.count(i.first) && !f[i.first]){
- summ++;
- ans.push_back(i.second);
- }
- }
- cout << summ << "\n";
- for (auto i: ans){
- cout << i << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement