Pagini recente » Cod sursa (job #2406401) | Cod sursa (job #467496) | Cod sursa (job #3261265) | Cod sursa (job #3196116) | Cod sursa (job #260537)
Cod sursa(job #260537)
#include <stdio.h>
struct nod
{
int x;
nod *urm;
};
nod *A[100001],*sol[200001];
int sir[100001],s1[100001],s2[100001],prt[100001];
int st[200001],vf;
int n,m,nrsol,nr;
int min(int x,int y)
{
if (x>y) return y;
return x;
}
void add(int x,int y)
{
nod *urm;
urm = new nod;
urm->x = y;
urm->urm = A[x];
A[x] = urm;
}
void update(int x,int y)
{
nod *q;
int z1,z2;
nrsol++;
/*do
{
z1 = st[vf-1];
z2 = st[vf];
q = new nod;
q->x = z1;
q->urm = sol[nrsol];
sol[nrsol]=q;
q = new nod;
q->x = z2;
q->urm = sol[nrsol];
sol[nrsol]=q;
vf-=2;
} while ((z1-x)||(z2-y)); */
}
void dfs(int x)
{
nod *q;
sir[x]=1;
s1[x]=s2[x]=nr++;
for (q=A[x];q!=NULL;q=q->urm)
{
if (!sir[q->x])
{
st[++vf]=x;
st[++vf]=q->x;
prt[q->x]=x;
dfs(q->x);
if (s2[q->x]>=s1[x])
update(x,q->x);
s2[x] = min(s2[x],s2[q->x]);
}
if (q->x-prt[x]) s2[x] = min(s2[x],s1[q->x]);
}
}
void solve()
{
int i;
for (i=1;i<=n;i++)
if (!sir[i])
{nr=1;dfs(i);}
}
void afisare()
{
nod *q;
printf("%d\n",nrsol);
/*int i;
for (i=1;i<=nrsol;i++)
{
for (q=sol[i];q!=NULL;q=q->urm)
sir[q->x] = 0;
for (q=sol[i];q!=NULL;q=q->urm);
{
if (!sir[q->x])
{
sir[q->x] = 1;
printf("%d ",q->x);
}
}
printf("\n");
} */
}
int main()
{
freopen("biconex.in","r",stdin);
freopen("biconex.out","wt",stdout);
scanf("%d%d",&n,&m);
int x,y;
while (m)
{
m--;
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
solve();
afisare();
}