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. 基于深度学习的文本 ...
随机推荐
- 使用CBrother的CLIB库调用windows的API
使用CBrother的CLIB库调用windows的API 2.1.0版本CBrother加入了CLib库,最新需要写一个工具,根据路径查杀一个Windows进程,研究了一下,CLib库的用法,感觉还 ...
- Mysql主从同步的实现原理与配置实战
1.什么是mysql主从同步? 当master(主)库的数据发生变化的时候,变化会实时的同步到slave(从)库. 2.主从同步有什么好处? 水平扩展数据库的负载能力. 容错,高可用.Failover ...
- Jquery 处理返回的 Json 数组
Jquery 处理返回的 Json 数组 <script> for (var i = 0; i < photos.length; ++ i) { console.log(photos ...
- Python3.7.1(四) Print如何在输出中插入变量
# 如果想在打印的字符串中的任意地方加入任意的变量,可以使用python的格式化输出.## 用例代码如下:s = 'Hello'x = len(s)print("The length of ...
- 100天搞定机器学习|Day56 随机森林工作原理及调参实战(信用卡欺诈预测)
本文是对100天搞定机器学习|Day33-34 随机森林的补充 前文对随机森林的概念.工作原理.使用方法做了简单介绍,并提供了分类和回归的实例. 本期我们重点讲一下: 1.集成学习.Bagging和随 ...
- oracle:表重命名
SQL> rename test1 to test; Table renamed. SQL> alter table test rename to test1; Table altered ...
- RHEL7.2 安装Hadoop-2.8.2
创建三台虚拟机,IP地址为:192.168.169.101,192.168.169.102,192.168.169.103 将192.168.169.102为namenode,192.168.169. ...
- 精通awk系列(8):awk划分字段的3种方式
回到: Linux系列文章 Shell系列文章 Awk系列文章 详细分析awk字段分割 awk读取每一条记录之后,会将其赋值给$0,同时还会对这条记录按照预定义变量FS划分字段,将划分好的各个字段分别 ...
- 使用C#+FFmpeg+DirectX+dxva2硬件解码播放h264流
本文门槛较高,因此行文看起来会乱一些,如果你看到某处能会心一笑请马上联系我开始摆龙门阵 如果你跟随这篇文章实现了播放器,那你会得到一个高效率,低cpu占用(单路720p视频解码播放占用1%左右cpu) ...
- Linux\Nginx 虚拟域名配置及测试验证
使用 Nginx 虚拟域名配置,可以不用去购买域名,就可以通过特定的域名访问本地服务器.减少发布前不必要的开支. 配置步骤 1. 编辑 nginx.conf 配置文件 sudo vim /usr/lo ...