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

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

#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. hdu1507最大匹配

    题意:给出n*m的矩阵方块,某些方块是ponds,这些方块不能出售,然后能出售的是1*2的方块 要求求出有多少块1*2的方块能够出售,并输出这些方块的坐标(specia judge) 关键是怎么建出二 ...

  2. Android4.0设置接口变更摘要(四)

    为了与你之前,你已经设置了共享Tab风格和Item实现圆角.希望能给有须要的朋友一点点帮助,今天再和大家分享一下用ViewPager实现设置分页,小米和OPPO就是这种设置,先来看看效果图: wate ...

  3. 使用python写appium用例

    安装Python依赖 pip3.4 install nose pip3.4 install selenium pip3.4 install Appium-Python-Client 执行測试用例and ...

  4. 重新想象 Windows 8 Store Apps (27) - 选取器: 联系人选取窗口, 自定义联系人选取窗口

    原文:重新想象 Windows 8 Store Apps (27) - 选取器: 联系人选取窗口, 自定义联系人选取窗口 [源码下载] 重新想象 Windows 8 Store Apps (27) - ...

  5. Unreal Engine 4 C++ 能够创建角色Zoom摄像头(资源)

    游戏摄像头可以观察到的距离越近,作用和拉远是一个比较普遍的要求,UE4它也实现比较简单. 在这篇文章中TopDown模板案例,解释如何,分步实施能Zoom摄像头. 创建TopDown模板C++项目达产 ...

  6. Maven学习笔记(三) :Maven使用入门

    编写POM:      Maven项目的核心是pom.xml.POM(Project Object Model,项目对象模型)定义了项目的基本信息,用于描写叙述项目怎样构建,声明项目依赖,等等.   ...

  7. 如何解决vector 析构函数的异常 opencv Assert _CrtIsValidHeapPointer

    一气呵成代码,但是,当发生执行_CrtIsValidHeapPointer例外,去搭调了一上午Bug.最终获得 跟踪定位到 _CrtIsValidHeapPointer ,注意到 g 8h&quo ...

  8. 【C语言探索之旅】 第一部分第八课:第一个C语言小游戏

    ​ 内容简介 1.课程大纲 2.第一部分第八课:第一个C语言小游戏 3.第一部分第九课预告: 函数 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言编写 ...

  9. 说说PHP的autoLoad自动加载机制

    __autoload的使用方法1: 最经常使用的就是这种方法,根据类名,找出类文件,然后require_one 复制代码 代码如下:function __autoload($class_name) { ...

  10. Red Hat Enterprise Linux Server(RHEL) yum安装软件时This system is not registered with RHN. RHN support will be disabled. 的解决方法(转)

    新安装了redhat6.5.安装后,登录系统,使用yum update 更新系统.提示: This system is not registered to Red Hat Subscription M ...