hdu3072 Intelligence System
来源:互联网 发布:企业注销 淘宝企业店铺 编辑:程序博客网 时间:2024/05/22 15:43
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>#define N 50005#define inf 999999999using namespace std;int dfn[N],low[N],head[N],sk[N],scc[N],cnt,sccnum,index,tp;//scc[]值相同的,梭点后属于同一个点,sccnum表示缩点后有几个点//dfn[x]表示x这个点dfs到的时间(深浅)//low[x]此点及其后代指出去的边能返回的最浅的点的时间戳(dfn)int incnt,outcnt;int in[N],out[N];struct edge{int next,to,w;}ed[N*2];void add(int u,int v,int w){ed[cnt].w = w; ed[cnt].to = v; ed[cnt].next = head[u]; head[u] = cnt++;}void tarjan(int root)//head初始值为-1时,用~i; head 初始值为0时用i{dfn[root]=low[root]=++index;sk[++tp]=root;int i;for(i=head[root];~i;i=ed[i].next){int v=ed[i].to;if(!dfn[v]){tarjan(v);low[root]=min(low[root],low[v]);}else if(!scc[v]){low[root]=min(low[root],dfn[v]);}}if(low[root]==dfn[root]){sccnum++;for(;;){int x=sk[tp--];scc[x]=sccnum;if(x==root)break; }}}int main(){int n,m;while(~scanf("%d%d",&n,&m)){memset(dfn,0,sizeof(dfn));memset(low,0,sizeof(low));memset(scc,0,sizeof(scc));memset(head,-1,sizeof(head));memset(in,0,sizeof(in));memset(out,0,sizeof(out));sccnum=0;index=0;tp=0;cnt=0;incnt=0;outcnt=0;for(int i=1;i<=m;i++){int u,v,w;scanf("%d%d%d",&u,&v,&w);u++;v++;add(u,v,w);}for(int i=1;i<=n;i++){if(!dfn[i])tarjan(i);} for(int i=1;i<=n;i++){ for(int j=head[i];j!=-1;j=ed[j].next) { int v=ed[j].to; if(scc[v]!=scc[i]){ in[scc[v]]++; } } } int c[N]; for(int i=1;i<=sccnum;i++)c[i]=inf; for(int i=1;i<=n;i++) { for(int j=head[i];~j;j=ed[j].next){int v=ed[j].to; if(scc[i]!=scc[v]){ c[scc[v]]=min(c[scc[v]],ed[j].w); } } } int sum=0; for(int i=1;i<sccnum;i++)sum+=c[i];//取到sccnum就错了,不知道为什么 printf("%d\n",sum);}return 0; }
阅读全文
0 0
- hdu3072 Intelligence System (Tarjan)
- hdu3072 Intelligence System
- HDU3072 Intelligence System
- hdu3072 Intelligence System
- hdu3072——Intelligence System
- [JZOJ4686] 通讯 [HDU3072] Intelligence System
- hdu3072 Intelligence System【强连通】
- HDU3072 Intelligence System【最小树形图】
- HDU3072 Intelligence System(强连通+最小传递费用+边权)
- hdu3072 Intelligence System(tarjan缩点+最小树形图)
- hdu3072 Intelligence System(Tarjan缩点+最小生成树)
- hdu3072
- HDU 3072 Intelligence System
- HDOJ 3072 Intelligence System
- HDOJ 3072 Intelligence System
- HDU 3072 Intelligence System(强连通分量)
- hdu 3072 Intelligence System(强连通分量)
- hdu 1827 Summer Holiday && 3072 Intelligence System
- java打印正方形
- 【NOJ】[1007] 第几天
- Mysql性能优化实战:数据库锁的介绍与索引查找原理
- 坚持#第209天~了解Linux操作系统和负载均衡
- 使用Adaboost训练车牌定位——(3)
- hdu3072 Intelligence System
- Java学习前准备(1)
- 几款常用的在线API管理工具(是时候抛弃office编写接口文档了)
- 跨域请求:查询天气
- MySQL半同步复制--handle_slave_io--4
- AUTOCAD学习笔记4:常用电器元件的绘制
- 观察者模式
- Nginx是一款面向性能设计的HTTP服务器,相较于Apache、lighttpd具有占有内存少,稳定性高等优势。
- AJAX工作原理及其优缺点