
Untitled
By: a guest on
Jul 29th, 2012 | syntax:
None | size: 1.37 KB | hits: 12 | expires: Never
#include <fstream>
#include <iostream>
#include <strstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N=0;
int M=0;
vector < vector <int> > Digraph;
vector<char> used;
int Time;
vector<int> tin, fup;
vector<int> br;
int count = 0;
void IsBridge(int from, int to){
count++;
int i = 0;
bool l = true;
while ((i < Digraph[from].size()) && (l)) {
if(Digraph[from][i] == to){
br.push_back(Digraph[from][i]);
l = false;
}
i++;
}
}
void dfs (int from, int p = 0) {
used[from] = true;
tin[from] = fup[from] = Time;
Time++;
for (int i=0; i < Digraph[from].size(); i++) {
int to = Digraph[from][i];
if (to == p) continue;
if (used[to]) fup[from] = min (fup[from], tin[to]);
else {
dfs (to, from);
fup[from] = min (fup[from], fup[to]);
if (fup[to] > tin[from])
IsBridge(from,to);
}
}
}
int main () {
freopen("bridges.in","r",stdin);
freopen("bridges.out","w",stdout);
cin >> N >> M;
for(int i = 1; i <= M; i++){
int a,b;
cin >> a >> b;
Digraph[a].push_back(b);
Digraph[b].push_back(a);
}
Time = 0;
dfs(1);
cout << count << "\n";
sort(br.begin(), br.end());
for (int i=0; i < br.size(); i++) {
cout << br[i] << " ";
}
return 0;
}