Reprint Please specify source: http://blog.csdn.net/vmurder/article/details/42671851
In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...
Bare topic only to template.
Tarjan can be implemented.
Too much water is not solved.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 1010# Define M 2020using namespace std;struct ksd{int v,next;} E[m];int head[n],cnt;inline void Add (int u,int v) {e[++cnt].v=v;e[cnt].next=head[u];head[u]=cnt;} int Dfn[n],low[n],n,m;int Id[n],group,d[n];int ans,edges; Edge-Double number, bridge number int stk[n],top;void Tarjan (int x,int p)//Edge dual connected component, i.e. no bridge. {int i,v,temp;dfn[x]=low[x]=++cnt;stk[++top]=x;for (i=head[x];i;i=e[i].next) {v=e[i].v;if (v==p) continue;if (!dfn[v ] {Tarjan (v,x); Low[x]=min (Low[x],low[v]);} else Low[x]=min (Low[x],dfn[v]);//if (Dfn[x]<low[v]) edges++; Number of bridges}if (Dfn[x]==low[x]) {group++;d o{temp=stk[top--];id[temp]=group;} while (temp!=x);} return;} int main () {//freopen ("test.in", "R", stdin), int i,j,k;int a,b,c;while (scanf ("%d%d", &n,&m)!=eof) {memset (head , 0,sizeof (head)), memset (dfn,0,sizeof (DFN)), memset (d,0,sizeof (d)), Cnt=group=ans=0;for (i=1;i<=m;i++) {scanf ("% d%d ", &a,&b); Add (A, B), add (B,a);} Cnt=0;for (i=1;i<=n;i++) if (!dfn[i]) tArjan (i,0); for (j=1;j<=n;j++) for (I=head[j];i;i=e[i].next) if (ID[J]!=ID[E[I].V]) d[id[e[i].v]]++;for (i=1;i<= n;i++) if (d[i]==1) ans++;p rintf ("%d\n", ans+1>>1);} return 0;}
"POJ3352" Road construction Tarjan seeking edge-double connected component, bare question template problem