POJ 3268 (dijkstra变形)
题目链接 :http://poj.org/problem?id=3268
Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?
Input
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse.
Output
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
Hint
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4+10;
int e[N][N],dis[N],book[N],ans[N];
int inf = 99999999;
int n,m,x,i,j,t1,t2,t3;
void disk(){
memset(dis,0,sizeof(dis));
for(i = 1; i <= n; i++){
dis[i] = e[x][i];
}
memset(book,0,sizeof(book));
book[x] = 1;
int min = inf,h;
for(i = 1; i <= n; i++){
min = inf;
for(j = 1; j <= n; j++){
if(book[j] == 0 && dis[j] < min){
min = dis[j];
h = j;
}
}
book[h] = 1;
for(int v = 1; v <= n; v++){
if(dis[v] > dis[h] + e[h][v]){
dis[v] = dis[h] + e[h][v];
}
}
}
}
void change(){ //倒置所有的边
for(i = 1; i <= n; i++){
for(j = 1; j <= i; j++){
swap(e[i][j],e[j][i]);
}
}
}
int main()
{
scanf("%d%d%d",&n,&m,&x);
memset(ans,0,sizeof(ans));
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
if(i == j){
e[i][j] = 0;
}
else{
e[i][j] = inf;
}
}
}
for(i = 1; i <= m; i++){
scanf("%d%d%d",&t1,&t2,&t3);
e[t1][t2] = t3;
}
disk();
for(i = 1; i <= n; i++){
ans[i] += dis[i];
}
change();
disk();
for(i = 1; i <= n; i++){
ans[i] += dis[i];
}
int max = 0;
for(i = 1; i <= n; i++){
if(max < ans[i] && ans[i] < inf){
max = ans[i];
}
}
printf("%d\n",max);
return 0;
}
POJ 3268 (dijkstra变形)的更多相关文章
- POJ 3268 Dijkstra+priority_queue或SPFA
		
思路:正向建边,一遍Dijkstra,反向建边,再一遍Dijkstra.ans加在一起输出最大值. (SPFA也行--) // by SiriusRen #include <queue> ...
 - DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
		
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
 - POJ.1797 Heavy Transportation (Dijkstra变形)
		
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
 - POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。
		
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
 - POJ 3268——Silver Cow Party——————【最短路、Dijkstra、反向建图】
		
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
 - NYOJ 1248 海岛争霸(Dijkstra变形——最短路径最大权值)
		
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=1248 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比 ...
 - POJ 3268 Silver Cow Party (最短路径)
		
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
 - 【lightoj-1002】Country Roads(dijkstra变形)
		
light1002:传送门 [题目大意] n个点m条边,给一个源点,找出源点到其他点的‘最短路’ 定义:找出每条通路中最大的cost,这些最大的cost中找出一个最小的即为‘最短路’,dijkstra ...
 - POJ 3268 Silver Cow Party (双向dijkstra)
		
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
 
随机推荐
- Mac平台Clion配置GLFW+GLAD的项目
			
前期的准备工作详见LearnOpenGL CN 看这篇教程的前提是假设你已经编译好了GLFW文件夹以及下载好了GLAD,不会的话可以看我的另一篇 文章的前部分: 配置 Clion新建一个项目,CMak ...
 - python接收axios的post请求,并处理后返回数据
			
公司的python工程师不会js和python数据交互,所以我就去试了一下. 首先安装python,django框架和django-cors-headers. python官网下载,按提示操作,记住最 ...
 - 第31月第15天  -fembed-bitcode
			
1. 确保打包的时候使用的是fembed-bitcode, 而不是fembed-bitcode-maker fembed-bitcode-maker:只是简单的标记一下在archive出来的二进制中b ...
 - I\O操作
			
作用:读写设备上数据.硬盘文件.内存.键盘.网络等. 分类: 数据走向:输入流.输出流 数据类型:字符流(文本数据Reader或者Writer结尾) 字节流(所有类型Stream结尾) 1个字节 = ...
 - PHP程序运行性能分析
			
php在使用了xdebug后,可以配置xdebug相关的配置,生成运行的日志. 在php.ini中配置: xdebug.profiler_enable = 1 xdebug.profiler_enab ...
 - C#    Dictionary 泛型
			
Dictionary<string, string>是一个泛型,什么是泛型? 使用泛型下面是用泛型来重写上面的栈,用一个通用的数据类型T来作为一个占位符,等待在实例化时用一个实际的类型来代 ...
 - 机器学习用Pandas实现数据库的读取
			
#读取数据库数据#import pandas as pd 导入模块#import pymysql 导入数据库模块#con = pymysql.connect(host='localhost',po ...
 - about:firefox set
			
about:config new:browser.cache.disk.parent_directory (disk.cache) new:browser.cache.offline.parent_ ...
 - SpringBoot文件的上传与下载
			
⒈文件实体类 package cn.coreqi.security.entities; public class FileInfo { private String path; public File ...
 - Grunt 实战
			
专题截图:(注:这个截图没啥意义) 项目截图: 目录讲解: app/ //开发目录; c/ //开发编译完成css文件夹; i/ //开发img文件夹; j/ / ...