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

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

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+最小生成树,,结果屡次W A,发现有些不妥,,,毕竟单线边。。
然后考虑~~~所点后,用数组存到下一个强连通的代价,最后统一答案即可、、
1 #include 
2 #include
3 #include
4 5 using namespace std; 6 7 const int INF(0x7fffffff); 8 const int N(50000+15); 9 const int M(100000+5);10 int n,m,head[N],sumedge;11 struct Edge12 {13 int v,next,dis;14 Edge(int v=0,int next=0,int dis=0):15 v(v),next(next),dis(dis){}16 }edge[M<<1];17 inline void ins(int u,int v,int w)18 {19 edge[++sumedge]=Edge(v,head[u],w);20 head[u]=sumedge;21 }22 23 int low[N],dfn[N],tim;24 int top,Stack[N],instack[N];25 int col[N],sumcol,val[N];26 void DFS(int now)27 {28 low[now]=dfn[now]=++tim;29 Stack[++top]=now; instack[now]=1;30 for(int i=head[now];i;i=edge[i].next)31 {32 int v=edge[i].v;33 if(!dfn[v]) DFS(v),low[now]=min(low[now],low[v]);34 else if(instack[v]) low[now]=min(low[now],dfn[v]);35 }36 if(low[now]==dfn[now])37 {38 col[now]=++sumcol;39 for(;Stack[top]!=now;top--)40 {41 col[Stack[top]]=sumcol;42 instack[Stack[top]]=0;43 }44 instack[now]=0; top--;45 }46 }47 48 inline void init()49 {50 sumedge=sumcol=tim=top=0;51 memset(low,0,sizeof(low));52 memset(dfn,0,sizeof(dfn));53 memset(col,0,sizeof(col));54 memset(edge,0,sizeof(edge));55 memset(head,0,sizeof(head));56 memset(Stack,0,sizeof(Stack));57 memset(instack,0,sizeof(instack));58 }59 60 int main()61 {62 for(int u,v,w;~scanf("%d%d",&n,&m);init())63 {64 for(int i=1;i<=m;i++)65 {66 scanf("%d%d%d",&u,&v,&w);67 ins(u+1,v+1,w);68 }69 for(int i=1;i<=n;i++)70 if(!dfn[i]) DFS(i);71 for(int i=1;i<=n;i++) val[i]=INF;72 for(int u=1;u<=n;u++)73 for(int i=head[u];i;i=edge[i].next)74 {75 int v=edge[i].v;76 if(col[u]==col[v]) continue;77 val[col[v]]=min(val[col[v]],edge[i].dis);78 }79 long long ans=0;80 for(int i=1;i<=sumcol;i++)81 if(val[i]!=INF) ans+=(long long)val[i];82 printf("%I64d\n",ans);83 }84 return 0;85 }

 

转载于:https://www.cnblogs.com/Shy-key/p/7401521.html

你可能感兴趣的文章
无线通信基础(一):无线网络演进
查看>>
如何在工作中快速成长?阿里资深架构师给工程师的10个简单技巧
查看>>
WebSocket 时时双向数据,前后端(聊天室)
查看>>
关于python中带下划线的变量和函数 的意义
查看>>
linux清空日志文件内容 (转)
查看>>
安卓第十三天笔记-服务(Service)
查看>>
Servlet接收JSP参数乱码问题解决办法
查看>>
【bzoj5016】[Snoi2017]一个简单的询问 莫队算法
查看>>
Ajax : load()
查看>>
MySQL-EXPLAIN执行计划Extra解释
查看>>
Zookeeper概述
查看>>
Zookeeper一致性级别
查看>>
单例模式的几种实现方式及对比
查看>>
邓白氏编码 申请
查看>>
Linux远程登录
查看>>
Linux自己安装redis扩展
查看>>
HDU 1016 Prime Ring Problem(dfs)
查看>>
C#中结构体与字节流互相转换
查看>>
session和xsrf
查看>>
跟随大神实现简单的Vue框架
查看>>