Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- #include<set>
- #include<map>
- #include<fstream>
- using namespace std;
- const int maxn = 300113;
- vector<int> gr[maxn];
- bool used[maxn];
- int tin[maxn];
- int fup[maxn];
- int times = 0;
- map<pair<int, int>, int> d;
- map<pair<int, int>, int> kratnrebro;
- vector<pair<int, int>> qw;
- ifstream in("bridges.in");
- ofstream out("bridges.out");
- #define mp make_pair
- //#define in cin
- //#define out cout
- void dfs(int v, int p = -1)
- {
- used[v] = 1;
- tin[v] = fup[v] = times++;
- for (int i = 0; i < gr[v].size(); i++)
- {
- int to = gr[v][i];
- if (to == p) continue;
- if (used[to])
- {
- fup[v] = min(fup[v], tin[to]);
- }
- else
- {
- dfs(to, v);
- fup[v] = min(fup[v], fup[to]);
- if (fup[to] > tin[v] && kratnrebro[mp(v, to)] == 1)
- {
- pair<int, int> outr = mp(v, to);
- qw.push_back(outr);
- }
- }
- }
- }
- int main()
- {
- int n, m;
- in >> n >> m;
- int ap, bp;
- for (int i = 0; i < m; i++)
- {
- in >> ap >> bp;
- gr[ap].push_back(bp);
- gr[bp].push_back(ap);
- d[mp(ap, bp)] = i + 1;
- d[mp(bp, ap)] = i + 1;
- kratnrebro[mp(ap, bp)] += 1;
- kratnrebro[mp(bp, ap)] += 1;
- }
- for (int i = 1; i <= n; i++)
- {
- if (!used[i])
- {
- dfs(i);
- }
- }
- out << qw.size() << endl;
- for (int i = 0; i < qw.size(); i++)
- {
- out << d[mp(qw[i].first, qw[i].second)] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement