POJ3268

题意很简单 正向图跑一遍SPFA 反向图再跑一边SPFA 找最大值即可。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
const int maxn=1000+1,maxm=100000+1,INF=1e+8;
int len[maxn][maxn],len1[maxn][maxn],dist[maxn],dist1[maxn];
vector<int> path[maxn],path1[maxn];
int n,m,source;
void SPFA(int dist[],int d[][maxn],vector<int>son[],int source)
{
bool inq[maxn];
int times[maxn];
memset(inq,0,sizeof(inq));
memset(times,0,sizeof(times));
for(int i=1;i<=n;i++)
dist[i]=INF;
dist[source]=0;
queue<int>q;
q.push(source);
times[source]++;
inq[source]=true;
while(!q.empty())
{
int now=q.front();
q.pop();
inq[now]=false;
for(int i=0;i<son[now].size();i++)
{
int np=son[now][i];
if(dist[np]>dist[now]+d[now][np])
{
dist[np]=dist[now]+d[now][np]; if(times[np]>n)return;
if(!inq[np]){times[np]++;q.push(np);}
}
}
}
} int main()
{freopen("t.txt","r",stdin);
scanf("%d%d%d",&n,&m,&source);
for(int i=0;i<m;i++)
{
int a,b,l;
scanf("%d%d%d",&a,&b,&l);
path[a].push_back(b);len[a][b]=l;
path1[b].push_back(a);len1[b][a]=l;
}
SPFA(dist,len,path,source);
SPFA(dist1,len1,path1,source);
int ans=0;
for(int i=1;i<=n;i++)
{
if((dist[i]+dist1[i])>ans)ans=dist[i]+dist1[i];
}
printf("%d\n",ans);
return 0;
}

  

POJ 3268 最短路应用的更多相关文章

  1. poj 3268 最短路dijkstra *

    题目大意:给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x,除了牛x之外的牛,他们都有一个参加聚会并且回来的最 ...

  2. POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】

    Silver Cow Party Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  3. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  4. DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards

    题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...

  5. POJ 3268 Silver Cow Party (最短路径)

    POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...

  6. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  7. POJ 3268 Silver Cow Party 最短路

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

  8. poj - 3268 Silver Cow Party (求给定两点之间的最短路)

    http://poj.org/problem?id=3268 每头牛都要去标号为X的农场参加一个party,农场总共有N个(标号为1-n),总共有M单向路联通,每头牛参加完party之后需要返回自己的 ...

  9. poj 3268 Silver Cow Party(最短路,正反两次,这个模版好)

    题目 Dijkstra,正反两次最短路,求两次和最大的. #define _CRT_SECURE_NO_WARNINGS //这是找出最短路加最短路中最长的来回程 //也就是正反两次最短路相加找最大的 ...

随机推荐

  1. 使用TransactionTemplate

    通过TransactionCallback接口中的方法后(这里用来做业务),将返回值传递到TransactionTemplate的execute()中.通过调用TransactionStatus 的s ...

  2. [Algorithm] 10. Reverse Integer

    Description Given a 32-bit signed integer, reverse digits of an integer. Example Example 1: Input: 1 ...

  3. Cyclic Nacklace HDU - 3746 (kmp next数组应用)

    题目大意 给出字符串,寻找最小要补全的字符个数,使得字符串是两次的循环 解法 通过寻找规律,我们又发现了len-next[len]又派上了用场 ①如果next[len]是0,说明最大前缀后缀和为0,那 ...

  4. python 爬取微信好友列表和个性签名,绘制个性签名云图

    python爬取微信好友列表和个性签名,绘制个性签名云图 1. 简要介绍 本次实验主要用到下面几个库 : 1)itchat---用于微信接口,实现生成QR码,用于微信扫描登陆 2)re(正则化)--- ...

  5. TestNG安装及配置

    1. 在idea中新建一个maven项目 2. 在pom.xml中添加testng和reportng依赖 <dependencies> <!-- 添加testNG依赖 --> ...

  6. linux od-输出文件的八进制、十六进制等格式编码的字节

    博主推荐:获取更多 linux文件内容查看命令 收藏:linux命令大全 od命令用于输出文件的八进制.十六进制或其它格式编码的字节,通常用于显示或查看文件中不能直接显示在终端的字符. 常见的文件为文 ...

  7. Django DTL模板语法中的url反转

    """template_url_demo URL Configuration The `urlpatterns` list routes URLs to views. F ...

  8. Django-Rest framework中文翻译-Request

    REST framework的Request类扩展自标准的HttpRequest,增加了REST framework灵活的请求解析和请求验证支持. 请求解析 REST framework的Reques ...

  9. 转一篇GCC相关的文章

    http://blog.csdn.net/dadoneo/article/details/8201403 Glibc辅助运行库 (C RunTime Library): crt0.o,crt1.o,c ...

  10. [ural1057][Amount of Degrees] (数位dp+进制模型)

    Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...