By recognizing these Guys, We Find social Networks useful
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
1#include <cstdio>2#include <iostream>3#include <vector>4#include <cstring>5#include <string>6#include <stack>7#include <algorithm>8#include <map>9 using namespacestd;Ten One structEdge A { - intu,v; - }; the - Const intn=10005; - intDfn[n],low[n]; - intDfs_clock,m,n; +map<string,int>ver; -vector<int>G[n]; +Vector<edge>Bridge; AVector<edge>edges; at stringGuy[n]; - - BOOLCMP (Edge A,edge B) - { - if(a.u==b.u) - returna.v<B.V; in returna.u<b.u; - } to + voidInit () - { thememset (Low,0,sizeof(Low)); *memset (DFN,0,sizeof(DFN)); $dfs_clock=0;Panax Notoginseng edges.clear (); - bridge.clear (); the ver.clear (); + for(intI=0; i<n;i++) A g[i].clear (); the } + - intTarjan (intUintFA) $ { $ intlowu=dfn[u]=++Dfs_clock; - for(intI=0; I<g[u].size (); i++) - { the intv=G[u][i]; - if(!Dfn[v])Wuyi { the intlowv=Tarjan (v,u); -lowu=min (LOWU,LOWV); Wu } - Else if(dfn[v]<dfn[u]&&v!=FA) Aboutlowu=min (DFN[V],LOWU); $ } -low[u]=Lowu; - returnLowu; - } A + intMain () the { - intT; $scanf"%d",&T); the while(t--) the { the init (); thescanf"%d%d",&n,&m); - intnum=0; in for(intI=0; i<m;i++) the { the stringTMP1,TMP2; About intu,v; theCin>>tmp1>>TMP2; the if(!Ver.count (TMP1)) the { +ver[tmp1]=num; -guy[num]=Tmp1; thenum++;Bayi } the if(!Ver.count (TMP2)) the { -ver[tmp2]=num; -guy[num]=TMP2; thenum++; the } theu=ver[tmp1],v=VER[TMP2]; the Edges.push_back (Edge) {u,v}); - G[u].push_back (v); the g[v].push_back (u); the } theTarjan (0,-1);94 intj=0; the for(j=0; j<n;j++) the if(!dfn[j]) Break; the if(j!=N)98printf"0\n"); About Else - {101Vector<edge>:: iterator it;102 for(It=edges.begin (); It!=edges.end (); it++)103 {104 if(low[it->u]>dfn[it->v]| | Low[it->v]>dfn[it->u]) theBridge.push_back (*it);106 }107printf"%d\n", Bridge.size ());108 sort (Bridge.begin (), Bridge.end (), CMP);109Vector<edge>:: iterator iter; the for(Iter=bridge.begin (); Iter!=bridge.end (); iter++)111cout<<guy[iter->u]<<" "<<guy[iter->v]<<Endl; the }113 } the return 0; the}
HDU 3849 (bridge)