hdu3072 Intelligence System (最小树形图?)
题意:给一个有向图,问要从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 (最小树形图?)的更多相关文章
- HDU3072 Intelligence System
题目传送门 有个中文版的题面...和原题稍有不同 /* Description “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短信,并由此得知了伦 ...
- [HDU3072]:Intelligence System(塔尖+贪心)
题目传送门 题目描述 “这一切都是命运石之门的选择.”试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短 信,并由此得知了伦太郎制作出了电话微波炉(仮).为了掌握时间机器的技术,SE ...
- HDU 3072 Intelligence System(tarjan染色缩点+贪心+最小树形图)
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 ...
- hdu3072 强连通+最小树形图
题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...
- 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 3072 Intelligence System(Tarjan 求连通块间最小值)
Intelligence System Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- kuangbin带你飞 生成树专题 : 次小生成树; 最小树形图;生成树计数
第一个部分 前4题 次小生成树 算法:首先如果生成了最小生成树,那么这些树上的所有的边都进行标记.标记为树边. 接下来进行枚举,枚举任意一条不在MST上的边,如果加入这条边,那么肯定会在这棵树上形成一 ...
随机推荐
- Nginx SSL+tomcat集群,request.getScheme() 取到https正确的协议
最近在做一个项目, 架构上使用了 Nginx +tomcat 集群, 且nginx下配置了SSL,tomcat no SSL,项目使用https协议 但是,明明是https url请求,发现 log里 ...
- LInux下设置账号有效时间 以及 修改用户名(同时修改用户组名和家目录)
在linux系统中,默认创建的用户的有效期限都是永久的,但有时候,我们需要对某些用户的有效期限做个限定!比如:公司给客户开的ftp账号,用于客户下载新闻稿件的.这个账号是有时间限制的,因为是付费的.合 ...
- 【2016.3.22】作业 Word count 小程序
今天更下word count程序的设计思路及实现方法. 我的程序贴在coding里,这里就先不贴出来了, 我的coding地址:https://coding.net/u/holy_angel/p/wo ...
- 个人博客week7
IBM大型机之父佛瑞德·布鲁克斯(Frederick P. Brooks, Jr.)在1986年发表的一篇关于软件工程的经典论文,便以<没有银弹:软件工程的本质性与附属性工作>(No Si ...
- Can't find model 'en'
在使用 nlp = spacy.load("en") 报错OSError: Can't find model 'en' 应该用 python -m spacy download e ...
- css3-弹性盒模型
first <style> .box{width:1024px;height:100px; border:5px solid black; padding:10px; display:-w ...
- python格式化字符串Type Error: Format Requires Mapping 的问题
最近几天 频繁看到有这种写法 BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s" 第一次看到的pythoner看到可能会有点懵逼 ...
- Java微信二次开发(十)
生成带参数的二维码以及长链接转短链接 第一步:找到包com.wtz.vo,新建类WeixinQRCode.java package com.wtz.vo; /** * @author wangtian ...
- 用Delphi制作动态菜单 该文章《用Delphi制作动态菜单》
---恢复内容开始--- 1.首先,确定动态菜单的数据来源,即要确定动态菜单标题是来自Windows的系统注册表,还是来自一个数据库,或者是来自一个子目录,主要由程序的功能而定.这里假设主窗口名为Ma ...
- python之OrderedDict类
# OrderedDict类使用举例 # OrderedDict类的使用与字典相似,不同的是OrderedDict类会记录键值对的添加顺序 from collections import Ordere ...