hdu3849 by recognizing these Guys, We Find social Networks useful

Source: Internet
Author: User

The number of bridge edges is not shown, and the bridge edge is output according to the problem input sequence.

Note the correspondence between the brig and the edges.


#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio > #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map > #define INF 0x3f3f3f3f#pragma COMMENT (linker, "/stack:16777216") #define EPS 1e-6#define ll long longusing namespace s TD; #define M 200003#define N 10003int head[n],num,dfn[n],low[n],n,m,idx,brig[m<<1],bum;struct edge{int St,ed,ne XT;}    E[m<<1];void addedge (int x,int y) {e[num].st=x;    E[num].ed=y;    E[NUM].NEXT=HEAD[X]; head[x]=num++;}    void Tarjan (int u,int father) {int i,v;    low[u]=dfn[u]=idx++;        for (I=head[u];i!=-1;i=e[i].next) {V=e[i].ed;        if (v==father) continue;            if (dfn[v]==-1) {Tarjan (v,u);            low[u]=low[u]>low[v]?low[v]:low[u];        if (Low[v]>dfn[u])//bum bridge corresponding to the side of the number brig[bum++]=i;    } else low[u]=low[u]>dfn[v]?dfn[v]:low[u]; }}void INIT () {memset (dfn,-1,sizeof DFN);    memset (head,-1,sizeof head); num=bum=idx=0;} String hash[n];string s1,s2;bool cmp (int a,int b) {return a<b;}    int main () {int icy,i,cnt;    scanf ("%d", &icy);        while (icy--) {scanf ("%d%d", &n,&m);        Init ();        Map<string,int> MP;        Cnt=1;            for (i=0;i<m;i++) {cin>>s1>>s2;            if (!mp[s1]) hash[cnt]=s1,mp[s1]=cnt++;            if (!mp[s2]) hash[cnt]=s2,mp[s2]=cnt++;            Addedge (Mp[s1],mp[s2]);        Addedge (Mp[s2],mp[s1]);        } Tarjan (1,-1);        for (i=1;i<=n;i++)//judgment diagram not connected if (dfn[i]==-1) break;            if (i<=n) {printf ("0\n");        Continue        } printf ("%d\n", bum);        Sort (brig,brig+bum,cmp);            for (int j=0;j<bum;j++) {i=brig[j];            if (i&1) i--; cout<

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.