"POJ3352" Road construction Tarjan seeking edge-double connected component, bare question template problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.