博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU——3072 Intelligence System
阅读量:5830 次
发布时间:2019-06-18

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

          Intelligence System

        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

              Total Submission(s): 2909    Accepted Submission(s): 1259

Problem Description
After a day, ALPCs finally complete their ultimate intelligence system, the purpose of it is of course for ACM ... ... 
Now, kzc_tc, the head of the Intelligence Department (his code is once 48, but now 0), is sudden obtaining important information from one Intelligence personnel. That relates to the strategic direction and future development of the situation of ALPC. So it need for emergency notification to all Intelligence personnel, he decides to use the intelligence system (kzc_tc inform one, and the one inform other one or more, and so on. Finally the information is known to all).
We know this is a dangerous work. Each transmission of the information can only be made through a fixed approach, from a fixed person to another fixed, and cannot be exchanged, but between two persons may have more than one way for transferring. Each act of the transmission cost Ci (1 <= Ci <= 100000), the total cost of the transmission if inform some ones in our ALPC intelligence agency is their costs sum. 
Something good, if two people can inform each other, directly or indirectly through someone else, then they belong to the same branch (kzc_tc is in one branch, too!). This case, it’s very easy to inform each other, so that the cost between persons in the same branch will be ignored. The number of branch in intelligence agency is no more than one hundred.
As a result of the current tensions of ALPC’s funds, kzc_tc now has all relationships in his Intelligence system, and he want to write a program to achieve the minimum cost to ensure that everyone knows this intelligence.
It's really annoying!
 

 

Input
There are several test cases. 
In each case, the first line is an Integer N (0< N <= 50000), the number of the intelligence personnel including kzc_tc. Their code is numbered from 0 to N-1. And then M (0<= M <= 100000), the number of the transmission approach.
The next M lines, each line contains three integers, X, Y and C means person X transfer information to person Y cost C. 
 

 

Output
The minimum total cost for inform everyone.
Believe kzc_tc’s working! There always is a way for him to communicate with all other intelligence personnel.
 

 

Sample Input
3 3 0 1 100 1 2 50 0 2 100 3 3 0 1 100 1 2 50 2 1 100 2 2 0 1 50 0 1 100
 

 

Sample Output
150 100 50
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:            
 
思路:
 先tarjan缩点,然后贪心加边将这几个连通块连接起来
代码:
#include
#include
#include
#include
#include
#define N 300010using namespace std;bool vis[N];int n,m,x,y,z,s,tot,num,sum,ans,top,tim;int fa[N],low[N],dfn[N],stack[N],head[N],belong[N];int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){
if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x*f;}struct Edge{ int to,dis,next;}edge[N];struct Edde{ int x,y,z;}edde[N];int add(int x,int y,int z){ tot++; edge[tot].to=y; edge[tot].dis=z; edge[tot].next=head[x]; head[x]=tot;}int add1(int x,int y,int z){ s++; edde[s].x=x; edde[s].y=y; edde[s].z=z;}void begin(){ s=0,tim=0,sum=0,tot=0; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); memset(belong,0,sizeof(belong));}void tarjan(int now){ dfn[now]=low[now]=++tim; stack[++top]=now; vis[now]=true; for(int i=head[now];i;i=edge[i].next) { int t=edge[i].to; if(vis[t]) low[now]=min(low[now],dfn[t]); else if(!dfn[t]) tarjan(t),low[now]=min(low[now],low[t]); } if(low[now]==dfn[now]) { sum++;belong[now]=sum; for(;stack[top]!=now;top--) { int x=stack[top]; belong[x]=sum;vis[x]=false; } vis[now]=false;top--; }}void shrink_point(){ for(int i=1;i<=n;i++) { for(int j=head[i];j;j=edge[j].next) if(belong[i]!=belong[edge[j].to]) { int t=edge[j].to; add1(belong[i],belong[t],edge[j].dis); add1(belong[t],belong[i],edge[j].dis); } }}int cmp(Edde a,Edde b){ return a.z
wa、、、、

 

#include
#include
#include
#include
#include
#define N 300010#define maxn 0x7fffffffusing namespace std;bool vis[N];long long ans;int n,m,x,y,z,s,tot,num,sum,top,tim;int fa[N],low[N],dfn[N],cost[N],stack[N],head[N],belong[N];int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){
if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x*f;}struct Edge{ int to,dis,next;}edge[N];struct Edde{ int to,dis,next;}edde[N];int add(int x,int y,int z){ tot++; edge[tot].to=y; edge[tot].dis=z; edge[tot].next=head[x]; head[x]=tot;}void begin(){ s=0,tim=0,sum=0,tot=0; memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(vis,0,sizeof(vis)); memset(head,0,sizeof(head)); memset(belong,0,sizeof(belong));}void tarjan(int now){ dfn[now]=low[now]=++tim; stack[++top]=now; vis[now]=true; for(int i=head[now];i;i=edge[i].next) { int t=edge[i].to; if(vis[t]) low[now]=min(low[now],dfn[t]); else if(!dfn[t]) tarjan(t),low[now]=min(low[now],low[t]); } if(low[now]==dfn[now]) { sum++;belong[now]=sum; for(;stack[top]!=now;top--) { int x=stack[top]; belong[x]=sum;vis[x]=false; } vis[now]=false;top--; }}void work(){ ans=0; for(int i=1;i<=n;i++) for(int j=head[i];j;j=edge[j].next) { int t=edge[j].to; if(belong[i]!=belong[t]) cost[belong[t]]=min(cost[belong[t]],edge[j].dis); } for(int i=1;i<=sum;i++) if(cost[i]!=maxn) ans+=(long long)cost[i]; printf("%lld\n",ans);}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { begin(); for(int i=1;i<=n;i++) cost[i]=maxn; for(int i=1;i<=m;i++) x=read(),y=read(),z=read(),add(x+1,y+1,z); for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i); work(); } return 0;}

 

 

转载于:https://www.cnblogs.com/z360/p/7401660.html

你可能感兴趣的文章
opticom 语音质量验证白皮书
查看>>
3D实时渲染中的BSP树和多边形剔除
查看>>
Frank Klemm's Dither and Noise Shaping Page: Dither and Noise Shaping In MPC/MP+
查看>>
网络抓包的部署和工具Wireshark【图书节选】
查看>>
Redis在Windows+linux平台下的安装配置
查看>>
Maven入门实战笔记-11节[6]
查看>>
Local declaration of 'content' hides instance variable
查看>>
ASP.NET中 HTML标签总结及使用
查看>>
Linux下日志系统的设计
查看>>
爬虫IP被禁的简单解决方法——切换UserAgent
查看>>
php生成word,并下载
查看>>
紫书 习题8-11 UVa 1615 (区间选点问题)
查看>>
asp.net mvc学习(Vs技巧与Httpcontext)
查看>>
float数据在内存中是怎么存储的
查看>>
dedecms 修改标题长度可以修改数据库
查看>>
Matplotlib学习---用matplotlib画直方图/密度图(histogram, density plot)
查看>>
MySQL案列之主从复制出错问题以及pt-slave-restart工具的使用
查看>>
linux 查看剩余内存数
查看>>
测试人员容易遗漏的隐藏缺陷
查看>>
maven+SpringMVC搭建RESTful后端服务框架
查看>>