HDU 3849 By Recognizing These Guys, We Find Social Networks Useful
By Recognizing These Guys, We Find Social Networks Useful
This problem will be judged on HDU. Original ID: 3849
64-bit integer IO format: %I64d Java class name: Main
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
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
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的更多相关文章
- 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 ...
- 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) ...
- 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) ...
- 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) ...
- hdu 3849 (双联通求桥)
一道简单的双联通求桥的题目,,数据时字符串,,map用的不熟练啊,,,,,,,,,,,,, #include <iostream> #include <cstring> #in ...
- Tarjan & LCA 套题题目题解
刷题之前来几套LCA的末班 对于题目 HDU 2586 How far away 2份在线模板第一份倍增,倍增还是比较好理解的 #include <map> #include <se ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
随机推荐
- putty和xshell使用和免密登录
putty和xshell使用和免密登录 XSHELL的设置 事前:我们先去关闭防火墙和selinux 关闭防火墙: ufw disable 再去看看selinux 一.查看SELinux状态命令: ...
- Mysql外键的变种 三种关系
一.介绍 因为有foreign key的约束,使得两张表形成了三种了关系: 多对一 多对多 一对一 二.重点理解如果找出两张表之间的关系 分析步骤: #1.先站在左表的角度去找 是否左表的多条记录可以 ...
- Spring《七》ApplicationContext
1.国际化支持 getMessage()提供了国际化支持. Bean中必须定义为messageSource. <bean id="messageSource" class=& ...
- C# List<T>转成DataTable
//将List<T>转成DataTable public static DataTable ToDataTable(List<T> collection) ...
- Aspose.Words进行Word替换(插入图片和水印)
由于最近一直在忙着做着Word打印模板的一些工作,就整理一些Asponse.Words对Word文档进行操作的资料. using System; using System.Collections.Ge ...
- Windows系统开发常用类-------------Environment类
Windows系统开发常用类-------------Environment类: SystemDirectory//显示系统目录 MachineName//计算机名称 ...
- hdu3873 Invade the Mars 有限制的最短路
此段略过.看完题目,觉得这真的是一道好题目.自己有想法,但是实现起来却很难.看题解,写代码,然后写题解,意义何在?我不认为自己总是这么弱.就算抄代码,我也要有自己的理解.菜鸟总会成长. 首先,题目必须 ...
- Django rest_framework API 随笔
分页 需要对数量进行限制 ./settings.py REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination ...
- I/O多路复用技术
典型应用于以下场合 1.处理多个描述字时,比如同时处理套接字和磁盘IO.终端IO 2.一个客户同时处理多个套接字 3.服务器既要处理监听套接字,又要处理已连接套接字 4.既要处理TCP.也要处理UDP ...
- 使用Windows上Eclipse远程调试Linux上的Hadoop
一.设置Eclipse运行用户 如果以与Hadoop运行用户名(比如grid)不同的用户运行Eclipse,则无法对Hadoop运行用户所属的文件进行管理,运行Map/Reduce程序也会报& ...