Pagini recente » Cod sursa (job #2711845) | Cod sursa (job #2535656) | Cod sursa (job #1742802) | Cod sursa (job #659038) | Cod sursa (job #939951)
Cod sursa(job #939951)
#include <fstream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
#define in "biconex.in"
#define out "biconex.out"
#define N 100005
ofstream fout (out);
vector <int> dfn (N, -1), low (N, -1), LIST[N];
vector <bool> A(N, 0);
struct muchie {
int x, y;
};
int n, m, st = 1, nf, num, nr;
deque <muchie> S;
muchie init (int x, int y)
{
muchie a;
a.x = x, a.y = y;
return a;
}
/*void Afis(int u, int x)
{
nr++;
do {
fout << S[S.size() -1].x << " " << S[S.size() - 1].y << "\n";
S.pop_back();
} while (S[S.size() -1].x != u && S[S.size() -1].y != x);
}*/
void Biconex (int u, int tu)
{
dfn[u] = low[u] = ++num;
for (unsigned z = 0; z < LIST[u].size(); ++z) {
int x = LIST[u][z];
if (x != tu && dfn[x] < dfn[u]) {
S.push_back (init (u, x));
if (dfn[x] == -1) {
if (u == st)
nf++;
Biconex (x, u);
low[u] = min (low[u], low[x]);
if (low[x] >= dfn[u]) {
if (u != st)
A[u] = 1;
nr++;
//Afis(u, x);
}
}
else
if (x != tu)
low[u] = min (low[u], dfn[x]);
}
}
}
int main ()
{
ifstream fin (in);
fin >> n >> m;
for (int i = 0; i < m; ++i) {
int x, y;
fin >> x >> y;
LIST[x].push_back (y);
LIST[y].push_back (x);
}
fin.close();
Biconex (st, -1);
if (nf > 1)
A[st] = 1;
fout << nr;
return 0;
}