题意:给一个有向图,问要从0号点能到达所有点所需要经过路径的最小权值和是多少,然而,若两点强联通,则这两点互相到达不需要花费。保证0号点能到达所有点

tarjan缩点以后直接取每个点入边中花费最小的即可。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<ctime>
#define LL long long int
using namespace std;
const int maxn=,maxm=; LL rd(){
LL x=;char c=getchar();int neg=;
while(c<''||c>''){if(c=='-') neg=-;c=getchar();}
while(c>=''&&c<='') x=x*+c-'',c=getchar();
return x*neg;
} struct Edge{
int a,b,l,ne;
}eg[maxm];
int egh[maxn],ect;
int N,M;
int dfn[maxn],low[maxn],bel[maxn],stk[maxn],tot,pct,sct;
bool instk[maxn];
int mi[maxn]; inline void adeg(int a,int b,int l){
eg[ect].a=a;eg[ect].b=b;eg[ect].l=l;eg[ect].ne=egh[a];egh[a]=ect++;
} void tarjan(int x){
dfn[x]=low[x]=++tot;
stk[++sct]=x;instk[x]=;
for(int i=egh[x];i!=-;i=eg[i].ne){
int j=eg[i].b;
if(instk[j]) low[x]=min(low[x],dfn[j]);
else if(!dfn[j]){
tarjan(j);low[x]=min(low[x],low[j]);
}
}
if(low[x]==dfn[x]){
++pct;
while(sct){
instk[stk[sct]]=;
bel[stk[sct]]=pct;
if(stk[sct--]==x) break;
}
}
} int main(){
int i,j,k;
while(~scanf("%d%d",&N,&M)){
memset(egh,-,sizeof(egh));
memset(dfn,,sizeof(dfn));
memset(instk,,sizeof(instk));
ect=tot=pct=sct=;
for(i=;i<=M;i++){
int a=rd(),b=rd(),c=rd();
adeg(a,b,c);
} for(i=;i<N;i++) if(!dfn[i]) tarjan(i);
memset(mi,,sizeof(mi));
for(i=;i<ect;i++){
if(bel[eg[i].a]==bel[eg[i].b]) continue;
mi[bel[eg[i].b]]=min(mi[bel[eg[i].b]],eg[i].l);
}int ans=;
for(i=;i<=pct;i++){
if(i!=bel[]) ans+=mi[i];
}printf("%d\n",ans);
}
}

hdu3072 Intelligence System (最小树形图?)的更多相关文章

  1. HDU3072 Intelligence System

    题目传送门 有个中文版的题面...和原题稍有不同 /* Description “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短信,并由此得知了伦 ...

  2. [HDU3072]:Intelligence System(塔尖+贪心)

    题目传送门 题目描述 “这一切都是命运石之门的选择.”试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短 信,并由此得知了伦太郎制作出了电话微波炉(仮).为了掌握时间机器的技术,SE ...

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

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

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

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

  5. hdu3072 强连通+最小树形图

    题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...

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

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

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

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

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

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

  9. kuangbin带你飞 生成树专题 : 次小生成树; 最小树形图;生成树计数

    第一个部分 前4题 次小生成树 算法:首先如果生成了最小生成树,那么这些树上的所有的边都进行标记.标记为树边. 接下来进行枚举,枚举任意一条不在MST上的边,如果加入这条边,那么肯定会在这棵树上形成一 ...

随机推荐

  1. 11.10 (下午)开课二个月零六天(ajax验证用户名,ajax调数据库)

    用ajax验证用户名是否可用 testuid.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...

  2. ES6入门之let、cont

    一.前提 解决ES5中只有全局作用域和函数作用域,没有块级作用域而带来的不合理的场景. let 基本用法 用法和var 一样,只是let声明的变量只有在let命令所在的代码块有效 { let a = ...

  3. Linux安装middleBox之prads

    PRADS prads github安装 prads github 项目 prads github命令

  4. libgdx学习记录27——线段与线段相交检测

    给定p1, p2, p3, p4四个点,p1,p2为一条线段,p3,p4为一条线段,检测其是否有交点. 可分为三种情况: 1. L2与x轴平行 2. L2与y轴平行 3. L2与坐标轴不平行. (L1 ...

  5. c#通用配置文件读写类与格式转换(xml,ini,json)

    .NET下编写程序的时候经常会使用到配置文件.配置文件格式通常有xml.ini.json等几种,操作不同类型配置文件需要使用不同的方法,操作较为麻烦.特别是针对同时应用不同格式配置文件的时候,很容易引 ...

  6. beta阶段性能指标测试

    性能指标概况 安装耗时 启动耗时 CPU占用 内存占用 电池温度 网络流量 平均值 5.48s 1.04s 1.61% 18.68MB 32.44℃ 93.78B 峰值 131.74s 5.13s 5 ...

  7. ml-模型评估与选择

    1.基本概念 错误率E=分类错误的样本数a/总样本数m:精度=1-a/m 经验误差/训练误差:在训练集上产生的 泛化误差:在测试集上产生的=====>要把这个泛化误差降到最小化. 2.评估方法 ...

  8. githup地址

    githup地址:https://github.com/caowenjing/test.git

  9. Eclipse: Difference between clean, build and publish

    https://stackoverflow.com/questions/5656989/eclipse-difference-between-clean-build-and-publish http: ...

  10. 安装wamp提示You dont't have permission to accesson on this server的解决方案

    展示一下安装好的效果图 首先找到安装目录下的路径[wamp\bin\apache\Apache2.2.21\conf\] § 找到httpd.conf,用记事本打开httpd.conf,然后将 1. ...