POJ 3268 最短路应用
题意很简单 正向图跑一遍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 最短路应用的更多相关文章
- poj 3268 最短路dijkstra *
题目大意:给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x,除了牛x之外的牛,他们都有一个参加聚会并且回来的最 ...
- POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
- POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- Heavy Transportation POJ 1797 最短路变形
Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...
- POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- poj - 3268 Silver Cow Party (求给定两点之间的最短路)
http://poj.org/problem?id=3268 每头牛都要去标号为X的农场参加一个party,农场总共有N个(标号为1-n),总共有M单向路联通,每头牛参加完party之后需要返回自己的 ...
- poj 3268 Silver Cow Party(最短路,正反两次,这个模版好)
题目 Dijkstra,正反两次最短路,求两次和最大的. #define _CRT_SECURE_NO_WARNINGS //这是找出最短路加最短路中最长的来回程 //也就是正反两次最短路相加找最大的 ...
随机推荐
- Unity中播放带有alpha通道格式为Mp4的视频
问题: Unity中实现播放透明的MP4视频时出现黑点 解决办法: 使用Unity自带的shader去除黑点 1:shader代码如下所示 Shader "Unlit/NewUnlit ...
- enote笔记语言(5)——其他(ver0.2)
章节:其他 ((主:单词)) 用来醒目地强调这个句子中哪个词语作主语 sentence: ...
- Gym - 101670B Pond Cascade(CTU Open Contest 2017 贪心,二分)
题目: The cascade of water slides has been installed in the park recently and it has to be tested. The ...
- mysql运维常用
一.用户授权 用户授权主要指: 1.可以限制用户访问那些库.表 2.可以限制用户对库.表执行select.create.delete.alter.drop等操作 3.可以限制用户登陆的IP.IP段.或 ...
- pyinstaller打包问题总结
1.pyinstaller常见用法 -w:禁止cmd窗口 -F:打包为单文件 比如:pyinstaller -w -F test.py 2.QT中UI转py文件 pyuic5 test.ui -o t ...
- extract a page from a multiple pages pdf on Ubuntu OS
extract a page from a multiple pages pdf 1 extract a page from a multiple pages pdf use pdftk packag ...
- Linux 复习二
第二章 一.Linux文件系统 1.基本概念 Linux文件系统为单根的树状结构,根为“/”,文件名大小写敏感,除了“/”都是可用字符,文件名以“.”开始的为隐藏文件. 2.常用文件夹 bin:可执行 ...
- CodeForcesGym 100753F Divisions
Divisions Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. Or ...
- spring boot & JsonParser
spring boot https://stackoverflow.com/questions/29313687/trying-to-use-spring-boot-rest-to-read-json ...
- [bzoj1607][Usaco2008 Dec]Patting Heads 轻拍牛头_筛法_数学
Patting Heads 轻拍牛头 bzoj-1607 Usaco-2008 Dec 题目大意:题目链接. 注释:略. 想法:我们发现,位置是没有关系的. 故,我们考虑将权值一样的牛放在一起考虑,c ...