意甲冠军:一群奶牛去的地方。去回,然后回去寻找最伟大值。

题解:两遍最短路,结束。邻接矩阵存边能够避免建反图。

#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 最短的更多相关文章

  1. POJ3268 Silver Cow Party(dijkstra+矩阵转置)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15156   Accepted: 6843 ...

  2. POJ3268 Silver Cow Party —— 最短路

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  3. POJ3268 Silver Cow Party Dijkstra最短路

    Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to atten ...

  4. POJ-3268 Silver Cow Party---正向+反向Dijkstra

    题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...

  5. poj3268 Silver Cow Party(两次dijkstra)

    https://vjudge.net/problem/POJ-3268 一开始floyd超时了.. 对正图定点求最短,对逆图定点求最短,得到任意点到定点的往返最短路. #include<iost ...

  6. 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 ...

  7. 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 ...

  8. poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)

    题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...

  9. 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 ...

随机推荐

  1. IAR FOR ARM 各版本号,须要的大家能够收藏了

    首先感谢大家的支持与关注,如今应该又一次编辑这篇文章了,这篇文章是非常久曾经不知在什么地方Copy过来的, 非常多问题不知怎么解决,如今我用的是KEIL for arm. 用过Keil和IAR,个人感 ...

  2. C语言程序代写(qq:928900200)

    1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...

  3. Django操作model时刻,一个错误:AttributeError:’ProgrammingError’ object has no attribute ‘__traceback__’

    原因:在Django项目下对应的应用以下的models.py配置的model(也就是class)没有创建成对应的表. 这是怎么回事呢? 首先,将models.py里面的model创建成相应的数据库表的 ...

  4. 4pdf

    http://www.cnblogs.com/haocool/archive/2013/03/16/2962547.html

  5. lunix shell 基础经常使用整理

     1   ps  -ef    显示正在执行的进程,pid 等信息  UID PID PPID C STIME TTY TIME CMD root 1 0 0 03:45 ? 00:00:02 ini ...

  6. 使用2DToolkit报错“ OverflowException: Value is too large”

    今天使用2DToolkit做图集和动画时报错“ OverflowException: Value is too large”,大侠们说是字符串转整型时超过了Int的大小范围,所以报错.后来我一位同事高 ...

  7. T-SQL基础(4) - 子查询

    简单子查询select * from (select custid, companyname from Sales.Customers where country = N'USA') as USACu ...

  8. StringUtils.isNumeric(String str) 的一个坑(转)

    在项目中遇到一处bug,调试的结果竟然是StringUtils.isNumeric(String str) 在捣鬼(采用的是org.apache.commons.lang.StringUtils),下 ...

  9. [小结][N种方法]实现WPF不规则窗体

    原文:[小结][N种方法]实现WPF不规则窗体 WPF实现不规则窗体,方法很多很多多.... 本文总结DebugLZQ认为简洁高效的几种方法 实现WPF不规则窗体的几种常用的方法如下: 1.使用Ble ...

  10. uboot的relocation原理具体分析

    近期在一直在做uboot的移植工作,uboot中有非常多值得学习的东西.之前总结过uboot的启动流程,但uboot一个非常核心的功能没有细致研究.就是uboot的relocation功能. 这几天研 ...