互相可以打电话是一个传递关系,所以Floyd求传递封包,dfs找一个尽量大的圈。

#include<bits/stdc++.h>
using namespace std; const int maxn = ;
map<string,int> mp;
map<string,int>::iterator it;
vector<string> names; bool d[maxn][maxn];
int ID(const string& s)
{
if((it = mp.find(s))!=mp.end()) return it->second;
mp.insert(make_pair(s,names.size()));
names.push_back(s);
return names.size()-;
}
bool vis[maxn];
int n,m; void dfs(int u)
{
vis[u] = true;
for(int i = ; i < n; i++){
if(!vis[i] && d[u][i] && d[i][u]){
printf(", %s",names[i].c_str());
dfs(i);
}
}
} int main()
{
//freopen("in.txt","r",stdin);
char s1[],s2[];
int kas = ;
while(scanf("%d%d",&n,&m),n){
if(kas) putchar('\n');
memset(d,,sizeof(d));
names.clear(); mp.clear();
while(m--) {
scanf("%s%s",s1,s2);
d[ID(s1)][ID(s2)] = true;
} for(int i = ; i < n; i++) d[i][i] = true;
for(int k = ; k < n; k++)
for(int i = ; i < n; i++)
for(int j = ; j < n; j++){
d[i][j] |= d[i][k]&&d[k][j];
}
printf("Calling circles for data set %d:\n",++kas);
fill(vis,vis+n,);
for(int i = ; i < n; i++){
if(!vis[i]){
printf("%s",names[i].c_str());
dfs(i);
putchar('\n');
}
}
}
return ;
}

最新文章

  1. ZKWeb网站框架介绍
  2. CSS background 属性
  3. ssh ip &quot;WARING:REMOTE HOST IDENTIFICATION HAS CHANGED!&quot;
  4. HDFS权限问题
  5. long和Long的区别
  6. hdu4756 Install Air Conditioning(MST + 树形DP)
  7. 用日志文件备份sqlserver
  8. 凭证(Credential)
  9. Windows 编程中恼人的各种字符以及字符指针类型
  10. 自己动手编写IOC框架(三)
  11. Java如何计算一个程序的运行时间
  12. sql注入-推断是否存在SQL注入-加法和减法
  13. 京东饭粒捡漏V1.0.7
  14. Leetcode 190.颠倒二进制位 By Python
  15. go学习day1
  16. TYPE_SCROLL_INSENSITIVE is not compatible with CONCUR_UPDATABLE
  17. HTTP首部字段
  18. linux下安装nginx,centos安装nginx
  19. 适配移动端的在图片上生成水波纹demo
  20. P1162 填涂颜色 洛谷

热门文章

  1. 发送邮件小工具(python)
  2. Linux 软链接 硬链接 ln命令(繁杂版)
  3. c++指针参数是如何传递内存的
  4. 洛谷 - SP3871 GCDEX - GCD Extreme - 莫比乌斯反演
  5. 洛谷 - P2158 - 仪仗队 - 欧拉函数
  6. 学习RESTFul架构
  7. Unity AnimatorController注意事项
  8. unity常用插件
  9. Unity3D之如何将包大小减少到极致
  10. native-echarts 在安卓上无法显示出来