BZOJ 3889: [Usaco2015 Jan]Cow Routing 双键值最短路
来源:互联网 发布:nginx 参数 编辑:程序博客网 时间:2024/05/16 08:24
3889: [Usaco2015 Jan]Cow Routing
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 236 Solved: 88
[Submit][Status][Discuss]
Description
Tired of the cold winter weather on her farm, Bessie the cow plans to fly to a warmer destination for vacation. Unfortunately, she discovers that only one airline, Air Bovinia, is willing to sell tickets to cows, and that these tickets are somewhat complicated in structure. Air Bovinia owns N planes (1 <= N <= 1000), each of which flies on a specific "route" consisting of two or more cities. For example, one plane might fly on a route that starts at city 1, then flies to city 5, then flies to city 2, and then finally flies to city 8. No city appears multiple times in a route. If Bessie chooses to utilize a route, she can board at any city along the route and then disembark at any city later along the route. She does not need to board at the first city or disembark at the last city. Each route has a certain cost, which Bessie must pay if she uses any part of the route, irrespective of the number of cities she visits along the route. If Bessie uses a route multiple times during her travel (that is, if she leaves the route and later comes back to use it from antoher city), she must pay for it each time it is used. Bessie would like to find the cheapest way to travel from her farm (in city A) to her tropical destination (city B). Please help her decide what is the minimum cost she must pay, and also the smallest number of individual flights she must use take to achieve this minimum cost.
Input
Output
Sample Input
3 5
1 2 3 4 5
2 3
3 5 4
1 2
1 5
Sample Output
裸双键值最短路
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;typedef long long ll;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(ll x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=3010,M=5001000;const ll inf=0X3f3f3f3f3f3f3f3fll;int ecnt,last[N];struct EDGE{int to,nt,val1,val2;}e[M];inline void add(int u,int v,int val1,int val2){e[++ecnt]=(EDGE){v,last[u],val1,val2};last[u]=ecnt;}ll dis1[N],dis2[N];int S,T,U[N];int q[N];bool inq[N];void spfa(){memset(dis1,0X3f,sizeof(dis1));memset(dis2,0X3f,sizeof(dis2));register int i,u,head=0,tail=1;q[0]=S;inq[S]=1;dis1[S]=dis2[S]=0;while(head^tail){u=q[head++];inq[u]=0;tail%=N;for(i=last[u];i;i=e[i].nt)if(dis1[e[i].to]>dis1[u]+e[i].val1||(dis1[e[i].to]==dis1[u]+e[i].val1&&dis2[e[i].to]>dis2[u]+e[i].val2)){dis1[e[i].to]=dis1[u]+e[i].val1;dis2[e[i].to]=dis2[u]+e[i].val2;if(!inq[e[i].to])inq[e[i].to]=1,q[tail++]=e[i].to,tail%=N;}}}int main(){S=read();T=read();int m=read();register int i,j,k,v,num;for(i=1;i<=m;++i){v=read();num=read();for(j=1;j<=num;++j){U[j]=read();for(k=1;k<j;++k)add(U[k],U[j],v,j-k);}}spfa();if(dis1[T]>=inf){puts("-1 -1");return 0;}print(dis1[T]);putchar(' ');print(dis2[T]);puts("");return 0;}/*3 4 33 51 2 3 4 52 33 5 41 21 52 2*/
- BZOJ 3889: [Usaco2015 Jan]Cow Routing 双键值最短路
- 【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路
- 图例练习题:【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路
- 【bzoj3889】[Usaco2015 Jan]Cow Routing 最短路
- bzoj 3889: [Usaco2015 Jan]Cow Routing SPFA
- [BZOJ3889]USACO2015 Jan-Cow|最短路
- bzoj3889【Usaco2015 Jan】Cow Routing
- 【Usaco2015 JAN】Cow Rectangles
- BZOJ 3885 Usaco2015 Jan Cow Rectangles 单调队列+二分
- BZOJ 3888: [Usaco2015 Jan]Stampede
- BZOJ3885: [Usaco2015 Jan]Cow Rectangles(悬线法)
- bzoj 3887: [Usaco2015 Jan]Grass Cownoisseur
- BZOJ 3887 [Usaco2015 Jan]Grass Cownoisseur
- BZOJ 【BZOJ3887】【Usaco2015 Jan】Grass Cownoisseur
- bzoj 3890: [Usaco2015 Jan]Meeting Time bfs
- BZOJ 3939 [Usaco2015 Feb] Cow Hopscotch
- BZOJ3890 [Usaco2015 Jan]Meeting Time K短路 Astar || 拓扑DP
- BZOJ 3890 Usaco2015 Jan Meeting Time 拓扑图DP
- hdu 1150 二分匹配
- java实现杨辉三角
- Hibernate学习笔记—Hibernate对象的三种状态
- Message深入解析
- Lucene学习笔记(一)-------Lucene基础
- BZOJ 3889: [Usaco2015 Jan]Cow Routing 双键值最短路
- Java的三种代理模式
- 线性代数背景知识
- 100款机器学习数据集
- Sqlnet.ora限制IP登录
- jqueryday02(jQuery基本使用特性 一些设置方法 基本样式设置)
- Lucene学习笔记(二)--------构建索引
- ImageLoader 图片异步加载
- navicat连接oracle 12c