Intelligence System
Intelligence System |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
| Total Submission(s): 57 Accepted Submission(s): 27 |
|
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 |
|
Sample Output
150 |
|
Source
2009 Multi-University Training Contest 17 - Host by NUDT
|
|
Recommend
lcy
|
/*
题意:给出n个人能联系的关系,和相应的电话费,让你求出最少的电话费 初步思路:强连通,缩点
*/
#include<bits/stdc++.h>
using namespace std;
const int InF=1e9+;
const int maxn=;
const int maxm=;
int n,m,cnt,id;
/**************************强连通模板******************************/
int dfn[maxn],low[maxn],cost[maxn],in[maxn];
vector<int> G[maxn];
stack<int> s;
bool inq[maxn];
struct edge{
int u,v,w;
edge(int u=,int v=,int w=):u(u),v(v),w(w){}
}E[maxm];
void init(){
cnt=id=;
while(!s.empty()) s.pop();
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
memset(in,,sizeof in);
for(int i=;i<=n;i++){
cost[i]=InF;
G[i].clear();
inq[i]=false;
}
}
void Tarjan(int x){
dfn[x]=low[x]=++id;
inq[x]=true;
s.push(x);
int t,Size=G[x].size();
for(int i=;i<Size;i++){
t=G[x][i];
if(!dfn[t]){
Tarjan(t);
low[x]=min(low[x],low[t]);
}
else if(inq[t]) low[x]=min(low[x],dfn[t]);
} //前面都差不多
if(dfn[x]==low[x]) {
cnt++;
do{
t=s.top(); s.pop();
inq[t]=false;
in[t]=cnt;
}while(t!=x);
}
}
/**************************强连通模板******************************/
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
init();
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
E[i]=edge(u,v,w);
G[u].push_back(v);
}
for(int i=;i<n;i++)
if(!dfn[i]) Tarjan(i);
for(int i=;i<=m;i++){//将连通块连起来:缩点
edge& e=E[i];
int u=e.u,v=e.v,w=e.w;
int x=in[u],y=in[v];
if(x!=y)
cost[y]=min(cost[y],w);
}
int sum=;
for(int i=;i<=cnt;i++){
if(i==in[]||cost[i]==InF) continue;
sum+=cost[i];
}
printf("%d\n",sum);
}
return ;
}
Intelligence System的更多相关文章
- HDU 3072 Intelligence System (强连通分量)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdoj 3072 Intelligence System【求scc&&缩点】【求连通所有scc的最小花费】
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 3072 Intelligence System(tarjan染色缩点+贪心+最小树形图)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 3072 Intelligence System(Tarjan 求连通块间最小值)
Intelligence System Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- Intelligence System (hdu 3072 强联通缩点+贪心)
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU——3072 Intelligence System
Intelligence System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU——T 3072 Intelligence System
http://acm.hdu.edu.cn/showproblem.php?pid=3072 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- HDU3072 Intelligence System
题目传送门 有个中文版的题面...和原题稍有不同 /* Description “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短信,并由此得知了伦 ...
- hdu3072 Intelligence System (最小树形图?)
题意:给一个有向图,问要从0号点能到达所有点所需要经过路径的最小权值和是多少,然而,若两点强联通,则这两点互相到达不需要花费.保证0号点能到达所有点 tarjan缩点以后直接取每个点入边中花费最小的即 ...
随机推荐
- angular directive知识
一般来讲 directive名字遵循一下规则: 1.忽略以x-和data-为元素/属性的前缀 2.转化“:”,“-”,“_”命名为驼峰命名 如下所示 <div ng-controller=&qu ...
- java编程基础复习-------第二章
一.标识符 java中标识符的命名规则: 以数字.字母.下划线和$符号组成:不能用数字开头:不能是java的关键字. 注意:不要用$命名标识符.习惯上,$只用在机器自动产生的源代码中. 二.关键字 1 ...
- Linux学习——shell编程之正则表达式和字符处理命令
shell编程之正则表达式 一 正则表达式 1 什么是正则表达式 正则表达式用于描述字符排列和匹配模式的一种语法规则.它主要用于字符串的模式分隔.匹配.查找及替换操作. 2 shell编程之正则表达式 ...
- Django内置的用户认证
认证登陆 在进行用户登陆验证的时候,如果是自己写代码,就必须要先查询数据库,看用户输入的用户名是否存在于数据库中: 如果用户存在于数据库中,然后再验证用户输入的密码,这样一来就要自己编写大量的代码. ...
- SpringBoot初体验
1.elipse中创建Springboot项目并启动 具体创建步骤请参考:Eclipse中创建新的Spring Boot项目 2.项目的属性配置 a.首先我们在项目的resources目录下appli ...
- Java公开课-01.类和对象
一,类和对象的含义 1.类:类是具有相同属性(静态特征)和行为(功能 )的一系列事物的集合. eg:以下俩者是不是类 1)汽车 √ 2)小胖桌子上那个红色的杯子 × 2.对象:被精确限定到一个特殊 ...
- REST架构概述
REST概述 REST(英文:Representational State Transfer,简称REST)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy F ...
- zoj 2022
分析: 组合数学类型的题目. 正常的话可能会去分解1~N数里面有几个5和2,但是这样的复杂度为O(nlogn). 其实有更巧妙的办法,可以把问题分解成子问题. 可以发现N!末尾的0与1~N中有几个5的 ...
- ZOJ 1489 HDU1395 2^x mod n = 1 数学
2^x mod n = 1 Time Limit: 2 Seconds Memory Limit:65536 KB Give a number n, find the minimum x t ...
- python重试(指数退避算法)
本文实现了一个重试的装饰器,并且使用了指数退避算法.指数退避算法实现还是很简单的.先上代码再详细解释. 1.指数退避算法 欠奉.http://hugnew.com/?p=814 2.重试装饰器retr ...