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. 瞎折腾实录:构建 Armel 版本的 .NET Core 教程和资料资源

    目录 首先我要说明,我失败了~ 我把我的进度和经验放出来,希望能够帮助别人完成编译工作~ 背景:最近接手一个华为某型号的嵌入式设备,需要在上面搭建 .NET Core 环境. 设备是 Armel 架构 ...

  2. DFS深度优先算法学习

    刚开始学习算法,参考大佬博客还是有很多不明白的,于是一步步解析,写下笔记记录. 大佬博客地址: https://blog.csdn.net/fuzekun/article/details/852204 ...

  3. 大宇java面试系列(二):jvm组成部分

    1. 说一下 JVM 的主要组成部分?及其作用? 类加载器(ClassLoader) 运行时数据区(Runtime Data Area) 执行引擎(Execution Engine) 本地库接口(Na ...

  4. linux系统LNMP环境部署

    源码安装 nginx# yum -y install gcc openssl-devel# useradd -s /sbin/nologin nginx# tar xf nginx-1.14.0.ta ...

  5. 轻松实现C/C++各种常见进制相互转换

    其它进制转为十进制 在实现这个需求之前,先简单介绍一个c标准库中的一个函数: long strtol( const char *str, char **str_end, int base); 参数详细 ...

  6. Redis 工具 redis-port 使用

    redis-port 是一个 Redis 工具,通过解析 rdb 文件,实现 Redis 主节点和从节点的数据同步.   摘要: 一个可以将redis主从集群,cluster上的数据实时迁移到 cod ...

  7. 稀疏数组 python描述

    什么是稀疏矩阵? 在矩阵中,若数值为0的元素数目远远多于非0元素的数目,并且非0元素分布没有规律时,则称该矩阵为稀疏矩阵. 作用: 在这种情况下,很多0值无疑是很浪费空间的,当我们要把数组存储在磁盘中 ...

  8. 以太网驱动的流程浅析(一)-Ifconfig主要流程【原创】

    以太网驱动的流程浅析(一)-Ifconfig主要流程 Author:张昺华 Email:920052390@qq.com Time:2019年3月23日星期六 此文也在我的个人公众号以及<Lin ...

  9. 微信中使用popup等弹窗组件时点击输入框input键盘弹起导致IOS中按钮无效处理办法

    因为在IOS微信中在弹窗中使用input使键盘弹起,使弹窗的位置上移,当键盘关闭时页面还在上面,弹窗位移量也在上面,只有下拉才能回到原位,这样弹窗也消失了.我的处理办法就是在键盘弹起和消失的时候,让页 ...

  10. SpringBoot学习(六)—— springboot快速整合RabbitMQ

    目录 Rabbit MQ消息队列 简介 Rabbit MQ工作模式 交换机模式 引入RabbitMQ队列 代码实战 Rabbit MQ消息队列 @ 简介 优点 erlang开发,并发能力强. 社区活跃 ...