hdu 4039 The Social Network
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4039
题目分类:字符串+bfs
题意:给一个人际关系图,根据关系图,给一个人推荐一个人认识
题目分析:
根据样例画出的关系图

代码:
#include<bits/stdc++.h> using namespace std; const int N=; map<string,int>mp;
vector<int>G[N*];
vector<string> ans; char s1[];
char s2[];
char ss[]; char s[N*][];
int Stack[N*];
int vis[N*]; bool bfs(int u)
{
memset(vis,,sizeof(vis));
vis[u]=-;
queue<int>q;
for(int i=;i<G[u].size();i++)
{
q.push(G[u][i]);
vis[G[u][i]]=-;
}
int siz=-;
int company=;
while(!q.empty())
{
u=q.front();
q.pop();
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(vis[v]==-) continue;
vis[v]++;
if(siz<vis[v])
{
siz=vis[v];
company=;
Stack[]=v;
}
else if(siz==vis[v])
{
Stack[company++]=v;
}
}
}
if(siz<) return false;
ans.clear(); for(int i=;i<company;i++)
ans.push_back(s[Stack[i]]);
sort(ans.begin(),ans.end()); for(int i=;i<ans.size();i++)
{
cout<<ans[i];
if(i<ans.size()-)
printf(" ");
}
printf("\n");
return true;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif int t,n,m;
scanf("%d",&t);
for(int kase=;kase<=t;kase++)
{
mp.clear();
scanf("%d %d",&n,&m);
for(int i=;i<=*n;i++)
G[i].clear();
int top=;
int num1,num2;
while(n--)
{
scanf("%s %s",s1,s2);
if(mp.find(s1)==mp.end())
{
mp[s1]=++top;
memcpy(s[top],s1,sizeof s1);
num1=top;
}
else
num1=mp.find(s1)->second; if(mp.find(s2)==mp.end())
{
mp[s2]=++top;
memcpy(s[top],s2,sizeof s2);
num2=top;
}
else
num2=mp.find(s2)->second; G[num1].push_back(num2);
G[num2].push_back(num1);
}
printf("Case %d:\n",kase);
while(m--)
{
scanf("%s",ss);
int i=mp.find(ss)->second;
if(bfs(i)==false)
puts("-");
}
}
return ;
}
hdu 4039 The Social Network的更多相关文章
- Call for Papers IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM)
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
- [CareerCup] 10.2 Data Structures for Large Social Network 大型社交网站的数据结构
10.2 How would you design the data structures for a very large social network like Facebook or Linke ...
- Social Network Analysis的Centrality总结,以及networkx实现EigenCentrality,PageRank和KatzCentrality的对比
本文主要总结近期学习的Social Network Analysis(SNA)中的各种Centrality度量,我暂且翻译为中心度.本文主要是实战,理论方面几乎没有,因为对于庞大的SNA,我可能连门都 ...
- IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 Industry Track Call for Papers
IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...
- 社会网络分析——Social Network Analysis
什么是社会网络分析,英文social network analysis.现在这个分析越来越时髦,也越来越显现其在社会科学的研究价值.我在2000年的时候受祝建华老师的邀请到香港城市大学作研究,接触到 ...
- Social Network 社交网络分析
Social Network 社交网络分析 一:什么是SNA-社交网络分析 社交网络分析的威力何在?我想几个案例来说明. 案例1:对一个毫无了解的组织(这个组织可以是一个公司,亦或是一个组织),如果能 ...
- Complex social network Partition for Balanced Subnetworks---Hao Lan Zhang,Jiming Liu,Chunyu Feng,Chaoyi Pang,Tongliang Li,Jing He阅读
摘要:Abstract—Complex social network analysis methods have been applied extensively in various domains ...
- Coursera Algorithms week1 查并集 练习测验:1 Social network connectivity
题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which ...
- Codeforces Round #590 (Div. 3) B2. Social Network (hard version)
链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard ver ...
随机推荐
- java.lang.NoClassDefFoundError: org/apache/lucene/analysis/synonym/SynonymFilter
2013-6-24 13:28:51 org.apache.solr.common.SolrException log 严重: java.lang.NoClassDefFoundError: org/ ...
- 用 PS 复制权限
用 PS 复制权限 我们要把源计算机上的文件权限复制到目的计算机上. get-acl .\s.txt | Export-Clixml sddl.xml 把 s.txt 文件的权限保存到 sddl.xm ...
- POJ 2112 Optimal Milking (二分+最短路径+网络流)
POJ 2112 Optimal Milking (二分+最短路径+网络流) Optimal Milking Time Limit: 2000MS Memory Limit: 30000K To ...
- Eclipse用法和技巧二十七:定义自己的快速联想词
某天在调试代码的时候,虽然是android的project还是习惯的输入syso,然后在ALT+/一下.旁边的同事就问了一下,这个log打印输出的tag是什么.接着又问了为什么syso能够智能联想出这 ...
- java操作oracle空间信息介绍
转自:http://www.cdtarena.com/javapx/201307/9088.html sde是Spatial Database Engine简写,中文全称:空间数据库引擎. SDE是一 ...
- Android-x86 4.4-r5 发布,PC 上的安卓系统
Android x86 即运行于 x86 PC上的Android操作系统,目前已经支持大部分安卓程序. Android X86平台是由Beyounn和Cwhuang主持设计的.项目的主要目的在于为X8 ...
- [linux]linux命令学习-netstat
linux非常多服务都与网络相关.当服务调不通或者是启动port被占用,或者是又是被防火墙挡住的时候,就须要查询网络相关的问题,netstat命令之前仅仅会用一两个參数这里.好好学习一番. 经常使用的 ...
- asp.net2.0安全性(1)--用户角色篇(代码实现2)--转载来自车老师
加载所有用户 MembershipUserCollection user = Membership.GetAllUsers(); listUser.DataSource = user; listUse ...
- Unknown database 'DB_NAME'
Cannot create PoolableConnectionFactory (Unknown database 'DB_NAME'): com.mysql.jdbc.exceptions.jdbc ...
- error -27257: Pending web_reg_save_param/reg_find/create_html_param[_ex] request(s) detected and reset at the end of iteration number 1
检查点函数 web_reg_find("Search=body", "savecount=num", "Text=test1&quo ...