http://acm.hdu.edu.cn/showproblem.php?pid=3072

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:  3069 3077 3070 3071 3073 
 
一开始考虑Tarjan+最小生成树,,结果屡次W A,发现有些不妥,,,毕竟单线边。。
然后考虑~~~所点后,用数组存到下一个强连通的代价,最后统一答案即可、、
 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int INF(0x7fffffff);
const int N(+);
const int M(+);
int n,m,head[N],sumedge;
struct Edge
{
int v,next,dis;
Edge(int v=,int next=,int dis=):
v(v),next(next),dis(dis){}
}edge[M<<];
inline void ins(int u,int v,int w)
{
edge[++sumedge]=Edge(v,head[u],w);
head[u]=sumedge;
} int low[N],dfn[N],tim;
int top,Stack[N],instack[N];
int col[N],sumcol,val[N];
void DFS(int now)
{
low[now]=dfn[now]=++tim;
Stack[++top]=now; instack[now]=;
for(int i=head[now];i;i=edge[i].next)
{
int v=edge[i].v;
if(!dfn[v]) DFS(v),low[now]=min(low[now],low[v]);
else if(instack[v]) low[now]=min(low[now],dfn[v]);
}
if(low[now]==dfn[now])
{
col[now]=++sumcol;
for(;Stack[top]!=now;top--)
{
col[Stack[top]]=sumcol;
instack[Stack[top]]=;
}
instack[now]=; top--;
}
} inline void init()
{
sumedge=sumcol=tim=top=;
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(col,,sizeof(col));
memset(edge,,sizeof(edge));
memset(head,,sizeof(head));
memset(Stack,,sizeof(Stack));
memset(instack,,sizeof(instack));
} int main()
{
for(int u,v,w;~scanf("%d%d",&n,&m);init())
{
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
ins(u+,v+,w);
}
for(int i=;i<=n;i++)
if(!dfn[i]) DFS(i);
for(int i=;i<=n;i++) val[i]=INF;
for(int u=;u<=n;u++)
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].v;
if(col[u]==col[v]) continue;
val[col[v]]=min(val[col[v]],edge[i].dis);
}
long long ans=;
for(int i=;i<=sumcol;i++)
if(val[i]!=INF) ans+=(long long)val[i];
printf("%I64d\n",ans);
}
return ;
}

HDU——T 3072 Intelligence System的更多相关文章

  1. HDU 3072 Intelligence System (强连通分量)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. HDU 3072 Intelligence System(tarjan染色缩点+贪心+最小树形图)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. hdu 3072 Intelligence System(Tarjan 求连通块间最小值)

    Intelligence System Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  4. HDU——3072 Intelligence System

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. hdoj 3072 Intelligence System【求scc&&缩点】【求连通所有scc的最小花费】

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU - 3072 Intelligence System

    题意: 给出一个N个节点的有向图.图中任意两点进行通信的代价为路径上的边权和.如果两个点能互相到达那么代价为0.问从点0开始向其余所有点通信的最小代价和.保证能向所有点通信. 题解: 求出所有的强连通 ...

  7. Intelligence System (hdu 3072 强联通缩点+贪心)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. Intelligence System

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

  9. HDU 3072 SCC Intelligence System

    给出一个带权有向图,要使整个图连通.SCC中的点之间花费为0,所以就先缩点,然后缩点后两点之间的权值为最小边的权值,把这些权值累加起来就是答案. #include <iostream> # ...

随机推荐

  1. gem5中event queue执行原理机制具体分析

    搞清楚这个花了两天时间,下面内容为简略版.为了给自己赚点下载用的积分.如须要具体版本号.请点击下载点击打开链接 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  2. CF 558D(Guess Your Way Out! II-set解决区间问题)

    D. Guess Your Way Out! II time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. CodedUI自己主动化測试及脱离VS独立执行

    在VS中可创建"编码的UI測试".可录制软件操作,再回放,最后还能够脱离VS独立执行. 在VS中执行測试 创建项目codeuitest,控件布局.例如以下图: 在button单击事 ...

  4. node03--http

    form.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. rest_framework_HyperlinkedIdentityField

    #生成链接 HyperlinkedIdentityField class UserInfoSerializer(serializers.ModelSerializer): group = serial ...

  6. rest_framework 权限功能

    权限: 问题:不用视图不用权限可以访问 基本使用 写上一个权限类 创建utils 中 permission.py文件 class SvipPermisson(object): message = &q ...

  7. php函数: call_user_func()和call_user_func_array() 使用详解

    call_user_func 该函数允许直接调用自己写的函数,可以直接传入一些参数. 使用方法1:给自己写的函数传入参数,一个特别的调用函数的方法. <?php funciotn test1($ ...

  8. caffe(7) solver及其配置

    solver算是caffe的核心的核心,它协调着整个模型的运作.caffe程序运行必带的一个参数就是solver配置文件.运行代码一般为 # caffe train --solver=*_slover ...

  9. NodeJS学习笔记 (17)集群-cluster(ok)

    cluster模块概览 node实例是单线程作业的.在服务端编程中,通常会创建多个node实例来处理客户端的请求,以此提升系统的吞吐率.对这样多个node实例,我们称之为cluster(集群). 借助 ...

  10. Linux 文件系统权限

    文件权限管理 文件系统上的权限是指文件和目录的权限,权限主要针对三类对象(访问者)定义   owner   group   other  属主    属组    其它 每个文件对每类访问者都定义了三种 ...