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) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 3840 Accepted Submission(s): 987
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.
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.
From the second line to the (n + 1)th line,output these key relations according to the order and format of the input.
题解:这是简单的无向图的桥的题,这一题需要注意的是要求如果有桥,则需要按输入的顺序输出;我门客为其打上标记,记录其输入位次,因为为字符串,我用了两个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(无向图的桥)的更多相关文章
- 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) ...
- 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 ...
- 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 ...
- 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 ...
- 【论文笔记】Social Role-Aware Emotion Contagion in Image Social Networks
Social Role-Aware Emotion Contagion in Image Social Networks 社会角色意识情绪在形象社交网络中的传染 1.摘要: 心理学理论认为,情绪代表了 ...
- 《Predict Anchor Links across Social Networks via an Embedding Approach》阅读笔记
基本信息 文献:Predict Anchor Links across Social Networks via an Embedding Approach 时间:2016 期刊:IJCAI 引言 预测 ...
- 谣言检测(RDCL)——《Towards Robust False Information Detection on Social Networks with Contrastive Learning》
论文信息 论文标题:Towards Robust False Information Detection on Social Networks with Contrastive Learning论文作 ...
- Deep learning-based personality recognition from text posts of online social networks 阅读笔记
文章目录 一.摘要 二.模型过程 1.文本预处理 1.1 文本切分 1.2 文本统一 2. 基于统计的特征提取 2.1 提取特殊的语言统计特征 2.2 提取基于字典的语言特征 3. 基于深度学习的文本 ...
随机推荐
- 4. 彤哥说netty系列之Java NIO实现群聊(自己跟自己聊上瘾了)
你好,我是彤哥,本篇是netty系列的第四篇. 欢迎来我的公从号彤哥读源码系统地学习源码&架构的知识. 简介 上一章我们一起学习了Java中的BIO/NIO/AIO的故事,本章将带着大家一起使 ...
- Serlvet之cookie和session学习
HTTP 协议 Web通信需要一种语言,就像中国人讲中文,欧美说英文,Web使用的HTTP协议,也叫超文本协议. 使用HTTP协议的人分为两类:客户端和服务端.请求资源的角色是客户端,提供资源的是服务 ...
- 一文教你快速读懂MQTT网关
MQTT是一种发布(publish)/订阅(subscribe)协议,MQTT协议采用发布/订阅模式,所有的物联网终端都通过TCP连接到云端,云端通过主题的方式管理各个设备关注的通讯内容,负责将设备与 ...
- Win32窗口消息机制 x Android消息机制 x 异步执行
如果你开发过Win32窗口程序,那么当你看到android代码到处都有的mHandler.sendEmptyMessage和 private final Handler mHandler = new ...
- 在ensp上利用三层交换机实现VLAN间路由
我们在实际生活中经常要跨vlan进行通信,我们的解决办法有单臂路由,但是单臂路由存在很大的局限性,带宽,转发效率等,所以单臂路由用的就有点少,所以就有了本章节 三层交换机在原有的二层交换机的基础上,增 ...
- 【Linux系列】Centos 7安装 Mysql8.0(五)
目的 本文主要介绍以下两点: 一. 如何安装Mysql8.0 二. Navicat连接Mysql 一. 如何安装Mysql8.0 安装Mysql有两种方式: 直接下载官方的源(比较慢) https:/ ...
- Laravel 菜鸟的晋级之路
第一阶段:简单的增删改查 这是最开始接触Laravel的一个阶段.如果有PHP经验,那么应该能很快找到MVC的路径,然后驾轻就熟的开始写起来.虽然还显得有些笨拙,不过很快就能做出一些内容了.如果没有P ...
- 【Luogu P2146】软件包管理器
Luogu P2146 由于对于每一个软件包有且只有一个依赖的软件包,且依赖关系不存在环. 很显然这是一个树形的结构. 再看题目要求的操作,安装实际上对应的是覆盖根节点到当前节点的路径,卸载则是覆盖该 ...
- day 40 文本属性 常用css属性 定位
一. 浮动的特性 1.浮动的元素脱标 2.浮动的元素互相贴靠 3.浮动的元素由"字围"效果 4.收缩的效果 前提是标准文档流,margin的垂直方向会出现塌陷问题. 如果盒子居中: ...
- scrapy的CrawlSpider类
了解CrawlSpider 踏实爬取一般网站的常用spider,其中定义了一些规则(rule)来提供跟进link的方便机制,也许该spider不适合你的目标网站,但是对于大多数情况是可以使用的.因此, ...