【POJ3268】Silver Cow Party 最短
意甲冠军:一群奶牛去的地方。去回,然后回去寻找最伟大值。
题解:两遍最短路,结束。邻接矩阵存边能够避免建反图。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 1005
#define inf 0x3f3f3f3f
using namespace std; int map[N][N],n,m,s;
int dist1[N],dist2[N];
bool visit[N];
void dij1()
{
memset(dist1,0x3f,sizeof(dist1));
memset(visit,0,sizeof(visit));
int i,u,v,temp,round;
dist1[s]=0;
for(round=1;round<n;round++)
{
temp=inf;
for(i=1;i<=n;i++)
{
if(!visit[i]&&temp>dist1[i])
{
temp=dist1[i];
u=i;
}
}
visit[u]=1;
for(v=1;v<=n;v++)
{
dist1[v]=min(dist1[v],dist1[u]+map[u][v]);
}
}
return ;
}
void dij2()
{
memset(dist2,0x3f,sizeof(dist2));
memset(visit,0,sizeof(visit));
int i,u,v,temp,round;
dist2[s]=0;
for(round=1;round<n;round++)
{
temp=inf;
for(i=1;i<=n;i++)
{
if(!visit[i]&&temp>dist2[i])
{
temp=dist2[i];
u=i;
}
}
visit[u]=1;
for(v=1;v<=n;v++)
{
dist2[v]=min(dist2[v],dist2[u]+map[v][u]);
}
}
return ;
} int main()
{
// freopen("test.in","r",stdin);
int i,a,b,c;
scanf("%d%d%d",&n,&m,&s);
memset(map,0x3f,sizeof(map));
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
map[a][b]=c;
}
dij1();
dij2();
int ans=0;
for(i=1;i<=n;i++)ans=max(ans,dist1[i]+dist2[i]);
printf("%d\n",ans);
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
【POJ3268】Silver Cow Party 最短的更多相关文章
- POJ3268 Silver Cow Party(dijkstra+矩阵转置)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15156 Accepted: 6843 ...
- POJ3268 Silver Cow Party —— 最短路
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ3268 Silver Cow Party Dijkstra最短路
Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to atten ...
- POJ-3268 Silver Cow Party---正向+反向Dijkstra
题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...
- poj3268 Silver Cow Party(两次dijkstra)
https://vjudge.net/problem/POJ-3268 一开始floyd超时了.. 对正图定点求最短,对逆图定点求最短,得到任意点到定点的往返最短路. #include<iost ...
- POJ3268 Silver Cow Party (建反图跑两遍Dij)
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big co ...
- POJ3268 Silver Cow Party【最短路】
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big co ...
- poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)
题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...
- poj3268 Silver Cow Party(农场派对)
题目描述 原题来自:USACO 2007 Feb. Silver N(1≤N≤1000)N (1 \le N \le 1000)N(1≤N≤1000) 头牛要去参加一场在编号为 x(1≤x≤N)x(1 ...
随机推荐
- 【ThinkingInC++】61、非成员运算符
非成员运算符 当操作者的左侧是不同的类时.运算符重载不可能是正确的类中. IostreamOperatorOverloading.cpp /** * 书本:[ThinkingInC++] * 功能:非 ...
- JPA @PersistenceContext和@Transactional Annotation
JPA(Java Persistence API )也就是说,java存储数据API,它提供的接口更方便的存储数据,当然,经过一些复杂的,并需要使用查询操作Java Persistence query ...
- Test SRM Level One: TemperatureScales
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=6038 因为TopCoder SRM比赛使用的编译器进行了升级, ...
- [置顶] ios 一个不错的图片浏览分享框架demo
demo功能:一个不错的图片浏览分享框架demo.iphone6.1 测试通过.可以浏览图片,保存,微博分享到新浪,腾讯,网易,人人等. 注:(由于各个微博的接口有时候会有调整,不一定能分享成功.只看 ...
- zoj 2874 & poj 3308 Paratroopers (最小割)
意甲冠军: 一m*n该网络的规模格.详细地点称为伞兵着陆(行和列). 现在,在一排(或列) 安装激光枪,激光枪可以杀死线(或塔)所有伞兵.在第一i安装一排 费用是Ri.在第i列安装的费用是Ci. 要安 ...
- ASP.NET执行循序
首先第一次运行一个应用程序(WebSite或者WebApplication都是Web应用程序)第一次请求 -> 1,IIS -> 2,aspnet_isapi(非托管dll) -> ...
- Linux 常用命令解析和Bash Shell使用示例脚本演示
摘要 Linux命令是基于文本格式输入输出的一种程序,依照Unix哲学中强调的程序功能简单,输入宽松,输出严谨,各种程序组合能够具有更强大的功能,而具有这样的灵活性的主要原因是Linux规定程序 ...
- 开源备份软件bacula安装记录--包括备份-恢复演练
该公司原先使用的备用机oracle-linux 5.7 不是很稳定执行.经常死机,新安装centos6.5, 即用bacula要备份的数据.在这里,有关安装故障记录,MEMO. 操作系统:centos ...
- [LeetCode328]Odd Even Linked List
题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note ...
- OpenCV+MFC显示图像
1.首先下载openCV. 2.安装OpenCV.现在的版本号2.4.9,你并不需要配置环境变量. 3.设置包括文件夹,设定project库文件夹. 4.配置链接库.注意,链接库包含了文件名中包含一个 ...