poj 3268 Silver Cow Party(最短路)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 17017 | Accepted: 7767 |
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.
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
Sample Output
10
Hint
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 110000
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int head[MAX],ans;
int n,m,j,i,t,k,x;
int a,b,c;
int vis[MAX],dis[MAX];
struct node
{
int u,v,w;
int next;
}edge[MAX];
void add(int u,int v,int w)
{
edge[ans].u=u;
edge[ans].v=v;
edge[ans].w=w;
edge[ans].next=head[u];
head[u]=ans++;
}
void getmap()
{
memset(head,-1,sizeof(head));
ans=0;
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
}
int spfa(int sx,int sy)
{
int i,j;
queue<int>q;
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++)
dis[i]=INF;
vis[sx]=1;
dis[sx]=0;
q.push(sx);
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=0;
for(i=head[u];i!=-1;i=edge[i].next)
{
int top=edge[i].v;
if(dis[top]>dis[u]+edge[i].w)
{
dis[top]=dis[u]+edge[i].w;
if(!vis[top])
{
vis[top]=1;
q.push(top);
}
}
}
}
return dis[sy];
} void solve()
{
int Max=-INF;
int Min=INF;
int ant;
for(i=1;i<=n;i++)
{
ant=spfa(i,x)+spfa(x,i);
Max=max(Max,ant);
}
printf("%d\n",Max);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&x)!=EOF)
{
getmap();
solve();
}
return 0;
}
poj 3268 Silver Cow Party(最短路)的更多相关文章
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- poj 3268 Silver Cow Party (最短路算法的变换使用 【有向图的最短路应用】 )
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13611 Accepted: 6138 ...
- poj 3268 Silver Cow Party(最短路dijkstra)
描述: One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the bi ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- POJ 3268 Silver Cow Party (双向dijkstra)
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- POJ - 3268 Silver Cow Party SPFA+SLF优化 单源起点终点最短路
Silver Cow Party One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to ...
- POJ 3268 Silver Cow Party 单向最短路
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22864 Accepted: 1044 ...
随机推荐
- JPA和Hibernate的区别
JPA Java Persistence API,是Java EE 5的标准ORM接口,也是ejb3规范的一部分. Hibernate,当今很流行的ORM框架,是JPA的一个实现,但是其功能是JPA的 ...
- Go Deeper(2010成都现场赛题)(2-sat)
G - Go Deeper Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description ...
- 基于XMPP的即时通信系统的建立(五)— openfire
现决定使用Openfire作为服务端,Openfire采用Java开发,基于XMPP的实时开源协作服务器.单台可支持上万并发用户. Openfire体系结构 Openfire体系由其提供的服务器端.客 ...
- BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...
- OK335xS psplash Screen 移植
/*********************************************************************** * OK335xS psplash Screen 移植 ...
- (转)Linux: su sudo sudoer
http://zebralinux.blog.51cto.com/8627088/1369301 日常操作中为了避免一些误操作,更加安全的管理系统,通常使用的用户身份都为普通用户,而非root.当需要 ...
- mybatis+spring+struts2框架整合
近期公司要开发新的项目,要用struts2+mybatis+spring框架,所以学习了下,来自己的博客发表下,希望能给大家带来帮助!下边我把我的myschool开发的源代码以及数据库贴出来! 开 ...
- Grep 命令 用法大全
查找x文件 find / -name "x*" -ls 查找文件中x所在的行数 grep -n "x" -r *find . -name "*.jav ...
- Android欢迎界面的创建方法
1.制作一张启动图片splash.png,放置在res->drawable-hdpi文件夹中.2.新建布局文件splash.xml <?xml version="1.0" ...
- codeforces 687D Dividing Kingdom II 带权并查集(dsu)
题意:给你m条边,每条边有一个权值,每次询问只保留编号l到r的边,让你把这个图分成两部分 一个方案的耗费是当前符合条件的边的最大权值(符合条件的边指两段点都在一个部分),问你如何分,可以让耗费最小 分 ...