By Recognizing These Guys, We Find Social Networks Useful

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 3840    Accepted Submission(s): 987

Problem Description
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
 
Recommend
chenyongfu   |   We have carefully selected several similar problems for you:  3848 3851 3854 3857 3858 

题解:这是简单的无向图的桥的题,这一题需要注意的是要求如果有桥,则需要按输入的顺序输出;我门客为其打上标记,记录其输入位次,因为为字符串,我用了两个map存储他们;

代码为:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
struct Node {
int x, y, id, id1, id2;
bool operator < (const Node c) const
{
return id<c.id;
}
} node[maxn << ];
struct Node2 {
int y, id, id1, id2;
};
vector<Node2> ve[maxn];
map<string, int> ma;
map<int, string> mb;
int low[maxn], dfn[maxn], visited[maxn];
int n, m, dfn_clock;
int nu; void init()
{
for (int i = ; i <= n; i++) ve[i].clear();
ma.clear(); mb.clear();
memset(dfn, -, sizeof dfn);
memset(visited, , sizeof visited);
} void dfs(int u, int fa)
{
Node p; Node2 q;
low[u] = dfn[u] = dfn_clock++;
visited[u] = ;
for (int i = ; i<ve[u].size(); i++)
{
q = ve[u][i];
if (q.y == fa) continue;
if (!visited[q.y])
{
dfs(q.y, u);
low[u] = min(low[u], low[q.y]);
if (low[q.y]>dfn[u])
{
p.x = u; p.y = q.y; p.id = q.id;
p.id1 = q.id1; p.id2 = q.id2;
node[nu++] = p;
}
}
else low[u] = min(low[u], dfn[q.y]);
}
} main()
{
int t, i, k, id;
string s1, s2;
Node2 p;
cin >> t;
while (t--)
{
cin >> n >> m;
init(); k = ; id = ;
while (m--)
{
cin >> s1 >> s2;
if (ma[s1] == ) ma[s1] = k, mb[k] = s1, ++k;
if (ma[s2] == ) ma[s2] = k, mb[k] = s2, ++k;
int x = ma[s1], y = ma[s2];
p.y = ma[s2]; p.id = id++; p.id1 = ; p.id2 = ;
ve[x].push_back(p);
p.y = ma[s1]; p.id = id++; p.id1 = ; p.id2 = ;
ve[y].push_back(p);
} dfn_clock = nu = ;
dfs(, -);
int f = ;
for (i = ; i <= n; i++)
{
if (dfn[i] == -) break;
}
if (i <= n)
{
cout << << endl;
continue;
}
sort(node, node + nu);
cout << nu << endl;
for (i = ; i<nu; i++)
{
if (node[i].id1<node[i].id2)
cout << mb[node[i].x] << " " << mb[node[i].y] << endl;
else cout << mb[node[i].y] << " " << mb[node[i].x] << endl;
}
}
}

HDU3849-By Recognizing These Guys, We Find Social Networks Useful(无向图的桥)的更多相关文章

  1. 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)     ...

  2. 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)     ...

  3. 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 ...

  4. HDU 3849 By Recognizing These Guys, We Find Social Networks Useful

    By Recognizing These Guys, We Find Social Networks Useful Time Limit: 1000ms Memory Limit: 65536KB T ...

  5. Social networks and health: Communicable but not infectious

    Harvard Men’s Health Watch Poet and pastor John Donne famously proclaimed “No man is an island.” It ...

  6. 【论文笔记】Social Role-Aware Emotion Contagion in Image Social Networks

    Social Role-Aware Emotion Contagion in Image Social Networks 社会角色意识情绪在形象社交网络中的传染 1.摘要: 心理学理论认为,情绪代表了 ...

  7. 《Predict Anchor Links across Social Networks via an Embedding Approach》阅读笔记

    基本信息 文献:Predict Anchor Links across Social Networks via an Embedding Approach 时间:2016 期刊:IJCAI 引言 预测 ...

  8. 谣言检测(RDCL)——《Towards Robust False Information Detection on Social Networks with Contrastive Learning》

    论文信息 论文标题:Towards Robust False Information Detection on Social Networks with Contrastive Learning论文作 ...

  9. Deep learning-based personality recognition from text posts of online social networks 阅读笔记

    文章目录 一.摘要 二.模型过程 1.文本预处理 1.1 文本切分 1.2 文本统一 2. 基于统计的特征提取 2.1 提取特殊的语言统计特征 2.2 提取基于字典的语言特征 3. 基于深度学习的文本 ...

随机推荐

  1. shell的运用 : jenkins 编译 打包前端发布 生产(tomcat)

    生产隔离做得非常.....文件上传只能通过固定ip机器的sftp账户上传,账户密码每个月要写申请才能获得. 登陆生产服务只能通过浏览器登陆!!! 发布一次生产,很痛苦. 做了简单的shell来减轻痛苦 ...

  2. PHP+Swoole并发编程的魅力

    PHP语言是一个短生命周期的Web编程语言,很多PHPer已经形成了fpm下编程的思维定势.实际上在Swoole出现之后,这种串行化编程的模式早已被打破.使用Swoole完全可以轻易实现更灵活的并发编 ...

  3. nyoj 32-组合数(next_permutation, stack, set)

    32-组合数 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:8 submit:11 题目描述: 找出从自然数1.2.... .n(0<n< ...

  4. java中hashmap容量的初始化

    HashMap使用HashMap(int initialCapacity)对集合进行初始化. 在默认的情况下,HashMap的容量是16.但是如果用户通过构造函数指定了一个数字作为容量,那么Hash会 ...

  5. python:类5——Python 的类的下划线命名有什么不同?

    首先是单下划线开头,这个被常用于模块中,在一个模块中以单下划线开头的变量和函数被默认当作内部函数,如果使用 from a_module import * 导入时,这部分变量和函数不会被导入.不过值得注 ...

  6. Spring Boot: Spring Doc生成OpenAPI3.0文档

    1. 概述 公司正好最近在整理项目的文档,且文档对于构建REST API来说是至关重要的.在这篇文章中,我将介绍Spring Doc , 一个基于OpenAPI 3规范简化了Spring Boot 1 ...

  7. 作业要求2018092609-2 选题 Scrum立会报告+燃尽图 01

    本组第一次作业 已由组员刘信鹏同学个人博客提交 链接 :  [https://www.cnblogs.com/liuxp775/p/11595227.html]

  8. 详解在Linux系统中安装JDK

    本文以在CentOS 7.6中安装JDK8为例进行安装,其他系统和版本都是大同小异的. 下载 进入Oracle官方网站的下载页面. 首先,接受许可协议,如下图: 然后,根据Linux系统的位数选择要下 ...

  9. Linux配置SSH和Xshell连接服务器

    >>>>>Ubuntu安装和配置ssh教程 SSH分为客户端 openssh-client 和服务器 openssh-server,可以利用以下命令确认电脑 上是否安装了 ...

  10. 菜鸟系列Fabric源码学习—orderer服务启动

    Fabric 1.4 orderer 服务启动流程 1.提要 orderer提供broadcast和deliver两个服务接口.orderer节点与各个peer节点通过grpc连接,orderer将所 ...