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. top命令的用法

    top命令的用法 2018年07月15日 09:50:04 zhuoya_ 阅读数:1858    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/z ...

  2. 浅析Oracle中的不等于号

    前几天碰到一个关于Oracle不等于的问题,最后搜索了一下,发现下面资料,拿来跟大家分享一下,需要的朋友可以参考下     关于Oracle中的不等于号: 在Oracle中, <> != ...

  3. IP地址、MAC地址、ARP地址解析协议

    互联网中一台主机要和另一台主机实现通信首先需要知道彼此在互联网中的位置,主机在互联网中的位置是通过ip地址标记的,当找到ip地址后,再通过端口号标识运行在主机中的进程从而实现通信. IP地址: IP地 ...

  4. enote笔记法的思考

    章节:enote笔记法的思考   why enote笔记法: key1)大脑喜欢颜色. 我们的大脑天生就喜欢颜色.对颜色很敏感,这是由我们人类过去的演化历程决定的. 你可以理解为,文字有了颜色,让这个 ...

  5. python3 http.server备忘

    python3英文的 打印出来应该不错: https://docs.python.org/3/library/http.server.html#module-http.server python2.7 ...

  6. Django-REST_Framework 第三方登录

    DRF第三方登录,我们将使用第三方包实现!!! 1.首先安装 pip install social-auth-app-django 文档请看 https://python-social-auth.re ...

  7. Literature Review on Tidal Turbine

    source: scopus , SCIE keywords in tilte: tidal turbine Software: Bibliometrix

  8. Balanced Numbers(数位dp)

    Description Balanced numbers have been used by mathematicians for centuries. A positive integer is c ...

  9. PAT 1129 Recommendation System

    Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...

  10. Spring常用注解总结 hibernate注解

    1.@Resource和@Autowired @Resource和@Autowired功能一样在容器查找匹配的Bean @Autowired默认按照byType方式进行bean匹配,@Resource ...