Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <algorithm>
- #include <fstream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <string>
- #include <ctime>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <map>
- #include <set>
- #include <deque>
- using namespace std;
- #define fi first
- #define se second
- #define mp make_pair
- #define sz(x) ((int)(x).size())
- #define pb(x) push_back(x)
- #define pf(x) push_front(x)
- #define abs(x) ((x) < 0 ? -(x) : (x))
- #define INF 2000000000
- #define sqr(x) ((x) * (x))
- #define all(x) x.begin(), x.end()
- #define fname ""
- #define MOD 1000000007
- #define y1 google
- #define tim printf("%.4lf\n", (clock() * 1.) / CLOCKS_PER_SEC)
- int timer = 1, kol;
- int tin[100500], fup[100500];
- vector <int> a[200500],w[200500];
- int ans[200500];
- bool was[100500];
- void dfs(int v, int p) {
- was[v] = true;
- tin[v] = fup[v] = timer++;
- for (int j = 0; j < a[v].size(); ++j) {
- int to = a[v][j];
- if (to == p) continue;
- if (was[to]) {
- fup[v] = min(fup[v], tin[to]);
- } else {
- dfs(to, v);
- fup[v] = min(fup[to], fup[v]);
- if (fup[to] > tin[v]) {
- ans[++kol] = w[v][j];
- }
- }
- }
- }
- int main() {
- freopen(fname".in", "r", stdin);
- freopen(fname".out", "w", stdout);
- int n, m;
- scanf("%d%d", &n, &m);
- for (int i = 1; i <= m; ++i) {
- int x,y;
- scanf("%d%d", &x, &y);
- a[x].push_back(y);
- a[y].push_back(x);
- w[x].push_back(i);
- w[y].push_back(i);
- }
- for (int i = 1; i <= n; ++i) {
- if (!was[i]) {
- dfs(i, -1);
- }
- }
- sort(ans + 1, ans + 1 + kol);
- printf("%d\n", kol);
- for (int i = 1; i <= kol; ++i) {
- printf("%d ", ans[i]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment