博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT (Advanced Level) 1034. Head of a Gang (30)
阅读量:6979 次
发布时间:2019-06-27

本文共 1155 字,大约阅读时间需要 3 分钟。

简单DFS。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=2000+10;map
m1;map
m2;int n,k,tot;struct Edge{ int u,v,val;}e[maxn];struct Ans{ string name; int cnt;}ans[maxn];int num;vector
g[maxn];int flag[maxn];int Block;int cnt[maxn];void dfs(int x){ num++; flag[x]=Block; for(int i=0;i
>a>>b>>e[i].val; if(m1[a]==0) { m1[a]=++tot; m2[tot]=a; } if(m1[b]==0) { m1[b]=++tot; m2[tot]=b; } e[i].u=m1[a]; e[i].v=m1[b]; cnt[e[i].v]+=e[i].val; cnt[e[i].u]+=e[i].val; g[e[i].u].push_back(e[i].v); g[e[i].v].push_back(e[i].u); } num=0; int t=0; for(int i=1;i<=tot;i++) { if(flag[i]!=0) continue; Block++; num=0; dfs(i); if(num<=2) continue; int sum=0; for(int j=1;j<=n;j++) if(flag[e[j].u]==Block&&flag[e[j].v]==Block) sum=sum+e[j].val; if(sum<=k) continue; int id,Max=-1; for(int j=1;j<=tot;j++) if(flag[j]==Block&&cnt[j]>Max) Max=cnt[j],id=j; ans[t].name=m2[id]; ans[t].cnt=num; t++; } sort(ans,ans+t,cmp); printf("%d\n",t); for(int i=0;i

 

转载于:https://www.cnblogs.com/zufezzt/p/5515740.html

你可能感兴趣的文章
四川成立大数据发展研究会 拟建公共云暨数据交易中心
查看>>
安全公司发现针对印度外交部与军事机构的间谍活动
查看>>
无接口.NET代码的单元测试
查看>>
数据库产品如何选型
查看>>
如何管理跨部门的沟通与协作?
查看>>
国防科大联合交流团来榕洽谈智慧城市建设合作
查看>>
日本外务省新设网络安全保障政策室
查看>>
美“智能城市挑战赛”决赛名单公布:7座城市入围
查看>>
企业全光网将成运营商部署千兆接入的商业驱动力
查看>>
sql 2000 分页存储过程
查看>>
2030年实现全球10TW的光伏目标 太阳能电池需要哪些突破?
查看>>
2017年物联网五大趋势
查看>>
卡巴斯基:智能汽车应用程序存在安全风险
查看>>
由一个营业厅投诉引发的思考
查看>>
智能家居火热但仍存缺陷,傻瓜式操作或成未来方向
查看>>
Win10 S是Windows RT第二?微软:差别很大
查看>>
流量劫持已成行业毒瘤,不正当竞争当严惩
查看>>
《IPv6精髓(第2版)》——第1章 为何使用IPv61.1 IPv6历史
查看>>
Whonix 8 发布,匿名通用操作系统
查看>>
《驯狮记——Mac OS X 10.8 Mountain Lion使用手册》——2.2 窗口
查看>>