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

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

#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. RedGate 工具SQLTEST 1.0.15.1

    原文:RedGate 工具SQLTEST 1.0.15.1 RedGate 工具SQLTEST 1.0.15.1 SQL TEST1.0.15.1的破解可以参考这篇文章:http://www.cnbl ...

  2. 深入理解计算机系统之旅(四)处理器(CPU)的体系结构

    1.前言 处理器是很复杂的系统,它不是一蹴而就的,它是经过不断的升级.更新.设计之后的产物,而且如今还在保持着不断的更新. 处理器仅仅能运行一系列的指令,每条指令都仅仅是运行某个简单的操作,比方数字相 ...

  3. Grub2配置详解(转)

    grub2基础教程-修订版                                      smallapple 目录 一.grub2新特性 二.grub2安装与启动 三.grub2配置文件 ...

  4. [文学阅读] METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments

    METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments Satanje ...

  5. 玩转html5(三)---智能表单(form),使排版更加方便

    <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/h ...

  6. UVA 12103 - Leonardo&#39;s Notebook(数论置换群)

    UVA 12103 - Leonardo's Notebook 题目链接 题意:给定一个字母置换B.求是否存在A使得A^2=B 思路:随意一个长为 L 的置换的k次幂,会把自己分裂成gcd(L,k) ...

  7. CKEditor上传插件

    CKEditor上传插件 前言 CKEditor上传插件是不是免费的,与您分享在此开发.这个插件是基于ASP.NET MVC下开发的,假设是webform的用户或者其他语言的用户.能够參考把serve ...

  8. 在borland c++ builder 中使用 google test (gtest)

    google test version: 1.6 c++ builder version: xe6 1 download google test 1.6 2 unzip the zip file. T ...

  9. 如何与多个线程的操作epoll fd

    自己曾经做一个接口server时候,这样的场景下我的设计是多个线程操作同一个epoll fd.彼时,我的理由是epoll的系列函数是线程安全的. 当然有人不理解为什么会有多个线程操作同一个epoll ...

  10. Apple Watch 2.0 数据通讯

    经常会碰到Watch app和WatchKit extension需要访问同一个文件.比如,使用一个自定义的字体,播放多媒体文件.有两种方法完成这个任务. 设计的时候,每个包放一份文件.它们分别访问自 ...