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. C算法与数据结构-线性表的应用,多项式求和---ShinePans

    /*---上机作业作业,二项式加法---*/ /*---By 潘尚 ---*/ /*---日期: 2014-5-8 . ---*/ /*---题目:---*/ //如果有两个稀疏多项式A和B,设计算法 ...

  2. 【翻译自mos文章】 asmcmd cp命令不能拷贝大于2GB的文件。

    asmcmd cp命令不能拷贝大于2GB的文件. 參考原文: Asmcmd CP Command Can Not Copy Files Larger Than 2 GB (Doc ID 786258. ...

  3. 《深入浅出 Java Concurrency》——原子操作

    part1 从AtomicInteger開始 从相对简单的Atomic入手(java.util.concurrent是基于Queue的并发包.而Queue.非常多情况下使用到了Atomic操作.因此首 ...

  4. luogu1920 成功密码

    题目大意:给出x∈(0,1)以及n∈(0,1e18),求sum foreach i(1<=i<=n) (x^i/i)保留四位小数的值. 用快速幂暴力求.考虑到题目只要求保留四位小数,而随着 ...

  5. adbd cannot run as root in production builds的解决方法

    部分手机root后,使用adb root会出现这个提示. 原因是root不彻底. adb shell之后进入到$界面,su一下才进入到#. 这个之后可以使用root功能了. 注意到,这个时候exit的 ...

  6. 【NOIP 2009】 Hankson的趣味题

    [题目链接] https://www.luogu.org/problemnew/show/P1072 [算法] x是b1的约数 筛出b1的约数,判断是否符合条件即可 [代码] #include< ...

  7. Angular2之路由学习笔记

    目前工作中项目的主要技术栈是Angular2 在这里简单记录一下遇到的问题以及解决方案. 这篇笔记主要记录Angular2 的路由. 官方文档链接:https://angular.cn/docs/ts ...

  8. 工厂方法模式(Product)C++实现

    意图:定义一个用于创建对象的接口,让子类觉定实例化哪一个类. 适用性:1.一个类不知道它必须创建的对象的时候. 2.一个类希望由它的子类指定它所创建的对象的时候. 3.当类将创建对象的职责委托给多个帮 ...

  9. Css问题 margin float 文档流 背景图底部充满

    今天来整理一下做网页遇到的问题吧 1.插入背景图片并使图片居于div底部充满整个行. <style> background:url(xxx.jpg) no-repeat; backgrou ...

  10. 部署TaskBoard

    部署TaskBoard kiswa/TaskBoard: A Kanban-inspired app for keeping track of things that need to get done ...