By Recognizing These Guys, We Find Social Networks Useful

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on HDU. Original ID: 3849
64-bit integer IO format: %I64d      Java class name: Main

 
Social Network is popular these days.The Network helps us know about those guys who we are 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 leaders".It seems that they know every lately news and are always online.They are alway publishing breaking news and by our relations with them we are informed of "almost everything".
(Aha,"almost everything",what an impulsive society!)
Now,it's time to know what our problem is.We want to know which are 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 will permanently lose the relations with some guys in the social network.Apparently,we don't wanna lose relations with those guys.We must know which are these key relations so that we can maintain these relations better.
We will give you a relation description map and you should find the key relations in it.
We all know that the relation bewteen two guys is mutual,because this relation description map doesn't describe the relations in twitter or google+.For example,in the situation of this problem,if I know you,you know me,too.

 

Input

The 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 number of relations between those guys(0 <= m <= 100000).
From the second to the (m + 1)the line,in each line,there are two strings A and B(1 <= length[a],length[b] <= 15,assuming that only lowercase letters exist).
We guanrantee that in the relation description map,no one has relations with himself(herself),and there won't be identical relations(namely,if "aaa bbb" has already exists in one line,in the following lines,there won't be any more "aaa bbb" or "bbb aaa").
We won't guarantee that all these guys have relations with each other(no matter directly or indirectly),so of course,maybe there are no key relations in the relation description map.

 

Output

In 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 Input

1
4 4
saerdna aswmtjdsj
aswmtjdsj mabodx
mabodx biribiri
aswmtjdsj biribiri

Sample Output

1
saerdna aswmtjdsj

Source

 
解题:求割边
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct arc {
int to,next;
bool cut;
arc(int x = ,bool y = false,int z = -) {
to = x;
cut = y;
next = z;
}
} e[];
unordered_map<string,int>ump;
int head[maxn],dfn[maxn],low[maxn],clk,tot;
void add(int u,int v) {
e[tot] = arc(v,false,head[u]);
head[u] = tot++;
}
int ret;
void tarjan(int u,int fa) {
dfn[u] = low[u] = ++clk;
bool flag = false;
for(int i = head[u]; ~i; i = e[i].next) {
if(!flag && e[i].to == fa) {
flag = true;
continue;
}
if(!dfn[e[i].to]) {
tarjan(e[i].to,u);
low[u] = min(low[u],low[e[i].to]);
if(low[e[i].to] > dfn[u]) {
e[i].cut = e[i^].cut = true;
++ret;
}
} else low[u] = min(low[u],dfn[e[i].to]);
}
}
char name[][];
void init() {
ump.clear();
for(int i = tot = clk = ret = ; i < maxn; ++i) {
head[i] = -;
dfn[i] = ;
}
}
int main() {
int kase,n,m,p;
scanf("%d",&kase);
while(kase--) {
init();
scanf("%d%d",&n,&m);
for(int i = p = ; i < m; ++i) {
scanf("%s",name[p+]);
int a = ump[name[p+]];
if(!a) {
ump[name[p+]] = a = p+;
++p;
}
scanf("%s",name[p+]);
int b = ump[name[p+]];
if(!b) {
ump[name[p+]] = b = p + ;
++p;
}
add(a,b);
add(b,a);
}
int cnt = ;
for(int i = ; i <= n; ++i)
if(!dfn[i]) {tarjan(i,-);cnt++;}
if(cnt > ){
puts("");
continue;
}
printf("%d\n",ret);
for(int i = ; i < tot; i += )
if(e[i].cut) printf("%s %s\n",name[e[i+].to],name[e[i].to]);
}
return ;
}

HDU 3849 By Recognizing These Guys, We Find Social Networks Useful的更多相关文章

  1. HDU 3849 By Recognizing These Guys, We Find Social Networks Useful(双连通)

    HDU 3849 By Recognizing These Guys, We Find Social Networks Useful pid=3849" target="_blan ...

  2. hdoj 3849 By Recognizing These Guys, We Find Social Networks Useful【双连通分量求桥&&输出桥&&字符串处理】

    By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others)     ...

  3. hdu3849-By Recognizing These Guys, We Find Social Networks Useful:双连通分量

    By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others)     ...

  4. HDU3849-By Recognizing These Guys, We Find Social Networks Useful(无向图的桥)

    By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others)     ...

  5. hdu 3849 (双联通求桥)

    一道简单的双联通求桥的题目,,数据时字符串,,map用的不熟练啊,,,,,,,,,,,,, #include <iostream> #include <cstring> #in ...

  6. Tarjan & LCA 套题题目题解

    刷题之前来几套LCA的末班 对于题目 HDU 2586 How far away 2份在线模板第一份倍增,倍增还是比较好理解的 #include <map> #include <se ...

  7. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  8. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

随机推荐

  1. android中图型的阴影效果(shadow-effect-with-custom-shapes)

    思路: 在自己定义shape中添加一层或多层,并错开.就可以显示阴影效果.为添加立体感,button按下的时候,仅仅设置一层.我们能够通过top, bottom, right 和 left 四个參数来 ...

  2. 具体解释linux文件处理的的经常使用命令

    原创Blog.转载请注明出处 附上之前訪问量比較高的几篇linux博客 本人使用shell的8个小技巧 grep的九个经典使用场景 sed命令具体解释 awk命令具体解释 linux中全部的东西都是文 ...

  3. 单片机小白学步系列(十四) 点亮第一个LED的程序分析

    本篇我们将分析上一篇所写的程序代码.未来学习单片机的大部分精力,我们也将放在程序代码的编写上. 可是不用操心.我会很具体的介绍每一个程序的编写思路和各种注意事项等. 之前我们写的程序例如以下: #in ...

  4. CSS艺术之---负margin之美

    CSS中负边距(nagative margin)是布局中常常使用的一个技巧.仅仅要运用得当时常会产生奇异的效果.勘称CSS中的奇淫巧计,非常多CSS布局方法都依赖于负边距.掌握它对于前端童鞋来说还是非 ...

  5. POJ3177 Redundant Paths 图的边双连通分量

    题目大意:问一个图至少加多少边能使该图的边双连通分量成为它本身. 图的边双连通分量为极大的不存在割边的子图.图的边双连通分量之间由割边连接.求法如下: 求出图的割边 在每个边双连通分量内Dfs,标记每 ...

  6. 关于Spring中的<context:annotation-config/>配置作用

    转自:https://www.cnblogs.com/iuranus/archive/2012/07/19/2599084.html 当我们需要使用BeanPostProcessor时,直接在Spri ...

  7. BZOJ 1061费用流

    思路: 我们可以列出几个不等式 用y0带进去变成等式 下-上 可以消好多东西 我们发现 等式左边的加起来=0 可以把每个方程看成一个点 正->负 连边 跑费用流即可 //By SiriusRen ...

  8. B - Mike and Cellphone(map)

    Problem description While swimming at the beach, Mike has accidentally dropped his cellphone into th ...

  9. android黑科技系列——微信抢红包插件原理解析和开发实现

    一.前言 自从几年前微信添加抢红包的功能,微信的电商之旅算是正式开始正式火爆起来.但是作为Android开发者来说,我们在抢红包的同时意识到了很多问题,就是手动去抢红包的速度慢了,当然这些有很多原因导 ...

  10. [原创]C++中一些重要概念

    1.虚函数 虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数.当把基类的某个成员函数声明为虚函数后,允许在其派生类中对该函数重新定义,赋予 ...