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. ThreadLocal<T> 源码解析

    在activeJDBC框架内部的实现中看到了 ThreadLocal 这个类,记录下了每个线程独有的连接 private static final ThreadLocal<HashMap< ...

  2. 网站搭建 - 虚拟机的安装 - Linux 本地网站搭建第一步

    搭建网站-1-域名申请参见公众号 生物信息系统(swxxxt) 搭建网站-域名绑定见稍后的一章,就是直接点解析,然后就完事了,可以不看的. 首先准备材料: 先装虚拟机,会要求重启,那就重启吧,安装界面 ...

  3. 怎样在PaaS平台上搭建一个会自动关闭的会议室

    首相得解释一下,什么叫做会自动关闭的会议室.我们的会议室是存在一个会议预定系统的,一般情况下,我们需要开会的时候,需要先抢占会议室.等待要开会的时候,去会议室里边开会,如果里边有别人,我们可以告诉他们 ...

  4. Nginx做缓存服务器

    Nginx做缓存服务器 Nginx配置 1.主配置/etc/nginx/nginx.conf worker_processes 1; events { worker_connections 1024; ...

  5. idea2017建立jsp工程及tomcat等配置

    1:建立工程,选择Java Enterprise,可能需要选择tomcat路径和jdk路径: =============================== 以下作为第二种方式参考: 1:创建新工程 ...

  6. 05-商品类别数据和VUE展示

    一.商品类别数据和VUE展示 1.商品类别数据接口 将商品类别数据展示出来,视图(views.py)代码如下: class CategoryViewset(mixins.ListModelMixin, ...

  7. 【python测试开发栈】python基础语法大盘点

    周边很多同学在用python,但是偶尔会发现有人对python的基础语法还不是特别了解,所以帮大家梳理了python的基础语法(文中的介绍以python3为例).如果你已然是python大牛,可以跳过 ...

  8. QQ是怎样创造出来的?——解密好友系统的设计

    本篇介绍笔者接触的第一个后台系统,从自身见闻出发,因此涉及的内容相对比较基础,后台大牛请自觉略过. 什么是好友系统? 简单的说,好友系统是维护用户好友关系的系统.我们最熟悉的好友系统案例当属QQ,实际 ...

  9. suseoj 1209: 独立任务最优调度问题(动态规划)

    1209: 独立任务最优调度问题 时间限制: 1 Sec  内存限制: 128 MB提交: 3  解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 用2台处理机A和B处理 ...

  10. 【Oracle】Oracle ASM管理监控命令

    目录 Oracle ASM管理监控命令 目的: 1.查看磁盘组 2.查看目前归档 3.查看ASM的磁盘路径 4. asmcmd Oracle ASM管理监控命令 目的: 查看目前Oracle ASM相 ...