bzoj1827 [Sdoi2010]星际竞速
Description
Input
Output
Sample Input
1 100 100
2 1 10
1 3 1
2 3 1
Sample Output
HINT
说明:先使用能力爆发模式到行星 1,花费时间 1。
然后切换到高速航行模式,航行到行星 2,花费时间10。
之后继续航行到行星 3完成比赛,花费时间 1。
虽然看起来从行星 1到行星3再到行星 2更优,但我们却不能那样做,因为
那会导致超能电驴爆炸。
对于 30%的数据 N≤20,M≤50;
对于 70%的数据 N≤200,M≤4000;
对于100%的数据N≤800, M≤15000。输入数据中的任何数都不会超过106
。
输入数据保证任意两颗行星之间至多存在一条航道,且不会存在某颗行星到
自己的航道。
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- #include<queue>
- #include<deque>
- #include<set>
- #include<map>
- #include<ctime>
- #define LL long long
- #define inf 0x3ffffff
- #define N 2010
- #define S 0
- #define T 2*n+1
- using namespace std;
- inline LL read()
- {
- LL x=0,f=1;char ch=getchar();
- while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
- while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
- return x*f;
- }
- struct edge{int from,to,next,v,c;}e[100*N];
- int head[N],from[N],q[N],dist[N];
- bool mrk[N];
- int n,m,cnt=1,ans;
- inline void ins(int u,int v,int w,int c)
- {
- e[++cnt].to=v;
- e[cnt].v=w;
- e[cnt].c=c;
- e[cnt].from=u;
- e[cnt].next=head[u];
- head[u]=cnt;
- }
- inline void insert(int u,int v,int w,int c)
- {
- ins(u,v,w,c);
- ins(v,u,0,-c);
- }
- inline bool spfa()
- {
- for(int i=0;i<=T;i++)dist[i]=inf;
- int t=0,w=1;
- dist[S]=0;mrk[S]=1;q[0]=S;
- while (t!=w)
- {
- int now=q[t++];if(t==2005)t=0;
- for (int i=head[now];i;i=e[i].next)
- if (e[i].v&&dist[now]+e[i].c<dist[e[i].to])
- {
- dist[e[i].to]=dist[now]+e[i].c;
- from[e[i].to]=i;
- if (!mrk[e[i].to])
- {
- mrk[e[i].to]=1;
- q[w++]=e[i].to;
- if (w==2005)w=0;
- }
- }
- mrk[now]=0;
- }
- return dist[T]!=inf;
- }
- inline void mcf()
- {
- int x=inf;
- for (int i=from[T];i;i=from[e[i].from])
- x=min(x,e[i].v);
- for (int i=from[T];i;i=from[e[i].from])
- {
- e[i].v-=x;
- e[i^1].v+=x;
- ans+=x*e[i].c;
- }
- }
- int main()
- {
- n=read();m=read();
- for(int i=1;i<=n;i++)
- {
- int x=read();
- insert(S,i,1,0);
- insert(i+n,T,1,0);
- insert(S,i+n,1,x);
- }
- for (int i=1;i<=m;i++)
- {
- int x=read(),y=read(),z=read();
- if (x>y)swap(x,y);
- insert(x,n+y,1,z);
- }
- while (spfa())mcf();
- printf("%d\n",ans);
- return 0;
- }
bzoj1827 [Sdoi2010]星际竞速的更多相关文章
- BZOJ 1927: [Sdoi2010]星际竞速
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2051 Solved: 1263[Submit][Stat ...
- 1927: [Sdoi2010]星际竞速
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2040 Solved: 1257[Submit][Stat ...
- bzoj1927: [Sdoi2010]星际竞速
跟上一题几乎一样... #include<cstdio> #include<cstring> #include<iostream> #include<algo ...
- BZOJ 1927: [Sdoi2010]星际竞速 费用流
1927: [Sdoi2010]星际竞速 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- bzoj 1927 [Sdoi2010]星际竞速(最小费用最大流)
1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1576 Solved: 954[Submit][Statu ...
- BZOJ 1927: [Sdoi2010]星际竞速(最小费用最大流)
拆点,费用流... ----------------------------------------------------------------------------- #include< ...
- BZOJ 1927: [Sdoi2010]星际竞速 [上下界费用流]
1927: [Sdoi2010]星际竞速 题意:一个带权DAG,每个点恰好经过一次,每个点有曲速移动到他的代价,求最小花费 不动脑子直接上上下界费用流过了... s到点连边边权为曲速的代价,一个曲速移 ...
- Luogu 2469 [SDOI2010]星际竞速 / HYSBZ 1927 [Sdoi2010]星际竞速 (网络流,最小费用流)
Luogu 2469 [SDOI2010]星际竞速 / HYSBZ 1927 [Sdoi2010]星际竞速 (网络流,最小费用流) Description 10年一度的银河系赛车大赛又要开始了.作为全 ...
- 【bzoj】1927 [Sdoi2010]星际竞速
[算法]最小费用最大流 [题解]跟滑雪略有类似,同样因为可以重复所以不是最小路径覆盖. 连向汇的边容量为1足矣,因为一个点只会出去一次(路径结束). bzoj 1927 [Sdoi2010]星际竞速 ...
随机推荐
- 遍历INI文件和删除指定域内容
主要还是使用的INI文件操作的API,只是把参数修改下. BOOL WINAPI WritePrivateProfileString( __in LPCTSTR lpAppName, __in LPC ...
- Citrix 服务器虚拟化之十三 Xenserver虚拟机内存优化与性能监控
Citrix 服务器虚拟化之十三 Xenserver虚拟机内存优化与性能监控 XenServer的DMC通过自动调节运行的虚拟机的内存,每个VM分配给指定的最小和最大内存值之间,以保证性能并允许每 ...
- 解决git提交问题error: The requested URL returned error: 403 Forbidden while accessing
git提交代码时,出现这个错误"error: The requested URL returned error: 403 Forbidden while accessing https&qu ...
- JS日期格式化函数性能优化篇
最近开发的软件中需要用到日志功能,其中有一个重要功能是显示日期和时间.于是网上搜了一把,搜到大量的日期格式化函数,不过比较了下,感觉代码都不够优雅,而且性能都不给力.对线上一些代码进行了评测,以下是一 ...
- ANDROID内存优化(大汇总——中)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上 ...
- Java基础知识强化31:String类之String的面试题
1.先看一个图: 2.String面试题: (1)题1: package cn.itcast_02; /* * 看程序写结果 */ public class StringDemo3 { public ...
- Java数据库连接之配置ODBC数据源
java使用JDBC-ODBC桥接连接SQLServer数据库需要配置ODBC数据源,配置步骤如下: 1.进入控制面板,找到管理工具 2.看到ODBC数据源,有64位和32位的,如果你的数据库是64位 ...
- mysql limit性能问题
offset大的时候的比较 1. SELECT * FROM persons LIMIT 200000,10; 耗时0.109s 2. SELECT *FROM persons WHERE id> ...
- MS SQL Sever数据库还原
一.右键 数据库 二.点击 [还原文件和文件组(E)...],弹出下图的窗口界面 1.在 目标数据库 的输入框填写你的数据库名(注意这是新建一个数据库供还原使用,不能还原到已有的数据库) 三.点击[源 ...
- JUnit报initializationError的解决方法
在新搭建的环境上测试时,一个模块发现错误: java.lang.NoClassDefFoundError:org/hamcrest/SelfDescribing 一看就是缺少Class.多方查找,发现 ...