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 ...
随机推荐
- Java类的多态机制
Java中将一个方法调用同一个方法主体关联起来被称作绑定. 绑定分为前期绑定和后期绑定.前期绑定是在编译器决定的,而后期绑定是在程序运行时决定的.Java中除了static方法和final方法(pri ...
- [MSSQL]採用pivot函数实现动态行转列
环境要求:2005+ 在日常需求中常常会有行转列的事情需求处理.假设不是动态的行,那么我们能够採取case when 罗列处理. 在sql 2005曾经处理动态行或列的时候,通常採用拼接字符串的方法处 ...
- android app 架构设计01
1:本文有摘抄, 1 2 3 4 5 - 开发过程中.需求.设计.编码的一致性 - 整个程序具有统一的风格,比方对话框样式,button风格,色调等UI元素 - 整个程序详细统一的结构,比方不同模块訪 ...
- 软件开发 —— 极限编程(XP:Extreme Programming)
1. 软件开发的基本概念 软件开发的过程是:需求分析.设计.编码和测试. 2. 极限编程基本内涵 极限编程是一个轻量级的.灵巧的软件开发方法:同时它也是一个非常严谨和周密的方法. 它的基础和价值观是交 ...
- 利用python开发的flappy bird 游戏
python 中 pygame模块能让我们很方便的编写游戏,16年我用python 仿制了flappy bird 游戏,下面是游戏的完整代码以及素材,分享给大家. 第一个python文件,flappy ...
- C - Game With Sticks
Problem description After winning gold and silver in IOI 2014, Akshat and Malvika want to have some ...
- HTML与CCS(十一)
1.1 HTML介绍 1.1.1 Web服务本质 import socket sk = socket.socket() sk.bind(("127.0.0.1", 8080)) s ...
- hdu2853 Assignment 完美匹配 多校联赛的好题
PS:好题.不看题解绝对AC不了. 题解来源: http://blog.csdn.net/niushuai666/article/details/7176290 http://www.cnblogs. ...
- Django[pronounced dʒ] installation on windows
1.Install python, download python windows installer from http://www.python.org/download/ and do inst ...
- C# 时间日期(函数,解释)
C#时间/日期格式大全,C#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6- ...