Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #include "optimization.h"
- using namespace std;
- vector<vector<int>> tree;
- vector<bool> mark;
- map<pair<int, int>, bool> rebra;
- int n, e;
- map<pair<int, int>, pair<int, int>> mem;
- vector<int> time_;
- vector<int> min_time;
- int T = 0;
- vector<int>result;
- int dfs(int root, int parent) {
- time_[root] = min_time[root] = ++T;
- for (auto x : tree[root]) {
- if (x == parent) continue;
- if (time_[x] == 0){
- dfs(x, root);
- if (min_time[x] > time_[root] && mem[{min(x, root), max(x,root)}].second == 1){
- result.push_back(mem[{min(x, root), max(x,root)}].first);
- }
- min_time[root] = min(min_time[root], min_time[x]);
- }
- else{
- min_time[root] = min(min_time[root], time_[x]);
- }
- }
- }
- int main() {
- cin >> n >> e;
- mark.resize(n+1, false);
- tree.resize(n+1);
- time_.resize(n+1);
- min_time.resize(n+1);
- for (int i = 1; i <= e; i++) {
- int a, b;
- cin >> a >> b;
- if (a > b){
- swap(a,b);
- }
- if (mem.count({a,b}) == 0){
- mem[{a, b}] = {i, 1};
- }
- else{
- mem[{a, b}].second += 1;
- }
- tree[a].push_back(b);
- tree[b].push_back(a);
- }
- dfs(1, 0);
- cout << result.size() << '\n';
- for (auto x : result){
- cout << x << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement