bzoj1631 [Usaco2007 Feb]Cow Party
来源:互联网 发布:java数据结构视频教程 编辑:程序博客网 时间:2024/06/04 18:38
Description
农场有N(1≤N≤1000)个牛棚,每个牛棚都有1只奶牛要参加在X牛棚举行的奶牛派对.共有M(1≤M≤100000)条单向路连接着牛棚,第i条踣需要Ti的时间来通过.牛们都很懒,所以不管是前去X牛棚参加派对还是返回住所,她们都采用了用时最少的路线.那么,用时最多的奶牛需要多少时间来回呢?
Input
第1行:三个用空格隔开的整数.
第2行到第M+1行,每行三个用空格隔开的整数:Ai, Bi,以及Ti.表示一条道路的起点,终点和需要花费的时间.
Output
唯一一行:一个整数: 所有参加聚会的奶牛中,需要花费总时间的最大值.
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
HINT
样例说明:
共有4只奶牛参加聚会,有8条路,聚会位于第2个农场.
第4只奶牛可以直接到聚会所在地(花费3时间),然后返程路线经过第1和第3个农场(花费7时间),总共10时间.
题意是对于每个点,求这个点到x的最短路加上x到这个点的最短路的最大值
那先正着跑一遍然后建反向边再跑一遍就好了
因为定义mod的时候2*N忘加括号而一直调不出来……毕竟我太弱了
#include<cstdio>#include<cstring>#define N 2000#define mod (2*N)#define M 210000#define inf 500000000struct bian{ int x,y,z;}b[M];struct edge{ int to,next,v;}e[M];int dis1[N],dis2[N],head[N];int q[2*N];int cnt,n,m,S,mx;bool mrk[N];inline int max(int a,int b){ if (b>inf) b=0; return a>b?a:b;}inline void ins(int u,int v,int w){ e[++cnt].to=v; e[cnt].v=w; e[cnt].next=head[u]; head[u]=cnt;}inline int read(){ int 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;}inline void spfa(int S,int *dist) { for (int i=1;i<=n;i++)mrk[i]=0; for (int i=1;i<=n;i++)dist[i]=inf; memset(q,0,sizeof(q)); q[0]=S;mrk[S]=1;dist[S]=0; int t=0,w=1; while (t!=w) { int now=q[t]; t=(t+1)%mod; for (int i=head[now];i;i=e[i].next) if (dist[e[i].to]>dist[now]+e[i].v) { dist[e[i].to]=dist[now]+e[i].v; if (!mrk[e[i].to]) { mrk[e[i].to]=1; if (dist[q[t]]>dist[e[i].to]) { t=(t-1+mod)%mod; q[t]=e[i].to; } else { q[w]=e[i].to; w=(w+1)%mod; } } } mrk[now]=0; }} int main(){ n=read();m=read();S=read(); for (int i=1;i<=m;i++) { b[i].x=read(); b[i].y=read(); b[i].z=read(); } for (int i=1;i<=m;i++) ins(b[i].x,b[i].y,b[i].z); spfa(S,dis1); memset(e,0,sizeof(e)); memset(head,0,sizeof(head)); cnt=0; for (int i=1;i<=m;i++) ins(b[i].y,b[i].x,b[i].z); spfa(S,dis2); for (int i=1;i<=n;i++) mx=max(mx,dis1[i]+dis2[i]); printf("%d",mx); return 0;}
0 0
- bzoj1631 [Usaco2007 Feb]Cow Party
- bzoj1631: [Usaco2007 Feb]Cow Party
- bzoj1631 [Usaco2007 Feb]Cow Party(Dijkstra)
- BZOJ1631: [Usaco2007 Feb]Cow Party 最短路 Spfa
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- 【BZOJ 1631】 [Usaco2007 Feb]Cow Party
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- BZOJ 1631: [Usaco2007 Feb]Cow Party spfa
- BZOJ 1631: [Usaco2007 Feb]Cow Party
- [Poj 3268][Usaco2007 Feb]Cow Party奶牛派对
- bzoj 1631: [Usaco2007 Feb]Cow Party 解题报告
- poj 3268 && bzoj 1631: [Usaco2007 Feb]Cow Party(最短路)
- [Usaco2007 Feb]Cow Sorting牛排序
- 1697: [Usaco2007 Feb]Cow Sorting牛排序
- bzoj1697[Usaco2007 Feb] Cow Sorting牛排序
- 1697: [Usaco2007 Feb]Cow Sorting牛排序
- bzoj1697 [Usaco2007 Feb]Cow Sorting牛排序
- BZOJ1697: [Usaco2007 Feb]Cow Sorting牛排序【置换群】
- Linux下配置OpenCV1.0环境
- python中的局部变量与全局变量
- ios 命名的陷阱
- IOS图像拉伸技巧
- 利用python读取文件 然后以表格的形式打印出去
- bzoj1631 [Usaco2007 Feb]Cow Party
- Servlet第四课 响应头信息
- Oracle基础知识
- linux内核中结构体struct module
- poi操作word(一)
- HDU1796-How many integers can you find
- KMP算法 KMP模式匹配 一(串)
- cocos2d-x 3.0 Json 用法
- HDU 1495——非常可乐( BFS )