HDU 3849 Non-direction graph finding Bridge

Source: Internet
Author: User

By recognizing these Guys, We Find social Networks useful

Time limit:2000/1000 MS (java/others) Memory limit:125536/65536 K (java/others)
Total submission (s): 2563 Accepted Submission (s): 671


Problem Descriptionsocial Network is popular these days. The Network helps us know about those guys who we is following intensely and makes us keep up our pace with the trend of Modern times.
But how?
By what method can we know the infomation we wanna? In some websites,maybe renren,based on social network,we mostly get the infomation by some relations with those "popular L Eaders ". It seems that they know every lately news and is always online. They is alway publishing breaking news and by our relations with them we is informed of "almost everything".
(Aha, "Almost everything", what's an impulsive society!)
Now,it ' s time to know what we problem is. We want to know which is the key relations make us related with other ones in the social network.
Well,what is the so-called key relation?
It means if the relation is cancelled or does not exist anymore,we would permanently lose the relations with some guys in t He social network. Apparently,we don ' t wanna lose relations with those guys. We must know which is these key relations so we can maintain these relations better.
We'll give you a relation description map and you should find the key relations in it.
We all know the relation bewteen and guys is mutual,because this relation description map doesn ' t describe the Relati ONS in Twitter or Google +. For example,in The situation of this problem,if I know you,you know Me,too.

Inputthe input is a relation description map.
In the first Line,an integer t,represents the number of cases (T <= 5).
In the second Line,an integer n,represents the number of guys (1 <= n <= 10000) and an integer m,represents the Numbe R of relations between those guys (0 <= m <= 100000).
From the second to the (M + 1) The Line,in each line,there is A strings A and B (1 <= length[a],length[b] <= 15,ass Uming that is only lowercase letters exist).
We guanrantee that in the relation description Map,no one have relations with himself (herself), and there won ' t be identical Relations (namely,if "AAA BBB" have already exists in one line,in the following Lines,there won ' t is any more "AAA BBB" or "BBB AAA").
We won ' t guarantee that all these guys has relations with each other (no matter directly or indirectly), so of Course,maybe There is no key relations in the relation description map.

Outputin the first line,output an integer n,represents the number of key relations in the relation description map.
From the second line to the (n + 1) th line,output These key relations according to the order and format of the input.

Sample Input14 4saerdna aswmtjdsjaswmtjdsj mabodxmabodx biribiriaswmtjdsj Biribiri

Sample Output1saerdna ASWMTJDSJ

Source2011 Invitational Contest Host by Bupt

Recommendchenyongfu
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <vector>6#include <map>7#include <string>8 using namespacestd;9 Const intmaxn=100007;Ten structnode One { A     int  from, to; - }; -Node edge[100007*2]; the intnext1[100007*2],first[maxn],pre[maxn],top; - intN,m,sum,ans[maxn],anstop; - voidAddedge (intUintv) - { +Edge[sum]. from=u;edge[sum].to=v; -next1[sum]=first[u];first[u]=sum;sum++; +Edge[sum]. from=v;edge[sum].to=u; Anext1[sum]=first[v];first[v]=sum;sum++; at } - intTarjain (intUintFA) - { -     intLowu=pre[u]=top++,child=0; -      for(inti=first[u];i!=-1; i=Next1[i]) -     { in         intv=edge[i].to; -         if(!Pre[v]) { tochild++; +             intlowv=Tarjain (v,u); -lowu=min (LOWV,LOWU); the             if(pre[u]<LOWV) { *ans[anstop++]=i; $             }Panax Notoginseng         } -         Else if(pre[v]<lowu&&v!=FA) { thelowu=min (lowu,pre[v]); +         } A     } the     returnLowu; + } - intMain () $ { $Ios::sync_with_stdio (false); -     intTstringS1,S2;intCNT; -Cin>>T; the      while(t--){ -memset (next1,-1,sizeof(NEXT1));Wuyimemset (first,-1,sizeof(first)); thememset (PRE,0,sizeof(pre)); -map<string,int>MP1; Wumap<int,string>MP2; -Cin>>n>>m; AboutCnt=1; anstop=0, sum=0; $          for(intI=1; i<=m;i++) -         { -Cin>>s1>>S2; -             if(mp1[s1]==0) mp1[s1]=cnt,mp2[cnt]=s1,cnt++; A             if(mp1[s2]==0) mp1[s2]=cnt,mp2[cnt]=s2,cnt++; + Addedge (Mp1[s1],mp1[s2]); the         } -top=1; $Tarjain (1,-1); the         BOOLflag=1; the          for(intI=1; i<=n;i++) the         { the             if(!pre[i]) flag=0; -         } in         if(!flag) {cout<<"0"<<endl;Continue;} theSort (ans,ans+anstop); thecout<<anstop<<Endl; About         intK; the          for(intI=0; i<anstop;i++) the         { thek=Ans[i]; +K=min (k,k^1); -COUT&LT;&LT;MP2[EDGE[K]. from].c_str () <<" "<<mp2[edge[k].to].c_str () <<Endl; the         }Bayi     } the     return 0; the}

HDU 3849 Non-direction graph finding Bridge

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.