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 ;
}

最新文章

  1. awk神器
  2. Java:静态导入
  3. html5 API
  4. WARNING OGG-01223 TCP/IP error 111 (Connection refused)
  5. Ubuntu 13.10 Mono安装历程
  6. android Json解析详解(详细代码)
  7. 淘淘商城_day11_课堂笔记
  8. js的this作用域
  9. 【知识整理】惊现RecyclerView内部Bug???别急,我们慢慢解决它~
  10. Web.config 自动替换值
  11. cmake 递归依赖
  12. activiti 涉及的内容
  13. JD-GUI反编译出现ERROR
  14. gitlab 存储仓库目录设置及数据迁移
  15. AngularJs在ng-click函数中获取代表当前元素的DOM对象
  16. tomcat配置去掉项目名称
  17. lnmp更改网站文件和MySQL数据库的存放目录
  18. python3.x 读写文件要使用UTF8编码的话需要。。
  19. 查找xml中的接口名及涉及表名并输出
  20. 微软牛津项目人脸识别API初探

热门文章

  1. 用html语言写一个功课表
  2. delphi网络函数大全
  3. 日志文件支持unicode字符的做法
  4. 利用第三方类 phpmailer 发邮件
  5. vue-cli生成的模板各个文件详解(转)
  6. opencv——图像的灰度处理(线性变换/拉伸/直方图/均衡化)
  7. caioj 1077 动态规划入门(非常规DP1:筷子)
  8. Java Web学习总结(20)——基于ZooKeeper的分布式session实现
  9. centos的终端字体杂乱的问题
  10. [Python] Accessing Array Elements