Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<< (x+1) <<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- int n,m;
- vector <int> clr, dp, mndp, ans;
- vector <vector <int> > G;
- map <pii, int> ed;
- void dfs(int v, int pr){
- clr[v] = 1;
- if (pr != -1){
- dp[v] = dp[pr] + 1;
- }
- for (int u: G[v]){
- if (u != pr && clr[u] == 0){
- dfs(u, v);
- }
- mndp[v] = min(mndp[v], mndp[u]);
- if (dp[v] < mndp[u]){
- ans.push_back(ed[{min(v,u), max(v,u)}]);
- }
- }
- clr[v] = 2;
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>m;
- G.assign(n, vector <int> (0));
- clr.assign(n, 0);
- dp.resize(n);
- mndp.resize(n);
- for (int i = 0; i < m; ++i){
- int a,b;
- cin>>a>>b; a--; b--;
- ed[{min(a,b), max(a,b)}] = i;
- G[a].push_back(b);
- G[b].push_back(a);
- }
- for (int i = 0; i < n; ++i){
- if (clr[i] == 0){
- dp[i] = 0;
- dfs(i, -1);
- }
- }
- sort(ans.begin(), ans.end());
- cout<<ans.size()<<"\n";
- cv(ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement