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 ...
随机推荐
- jmeter 多个sql写在一个jdbc请求中注意事项
在url里面加上?allowMultiQueries=true 类型选callableStatement
- DirectX11 With Windows SDK--26 计算着色器:入门
前言 现在开始迎来所谓的高级篇了,目前计划是计算着色器部分的内容视项目情况,大概会分3-5章来讲述. DirectX11 With Windows SDK完整目录 Github项目源码 欢迎加入QQ群 ...
- Redis集群管理
1.简介 Redis在生产环境中一般是通过集群的方式进行运行,Redis集群包括主从复制集群和数据分片集群两种类型. *主从复制集群提供高可用性,而数据分片集群提供负载均衡. *数据分片集群中能实现主 ...
- es6常用语法学习笔记
1.let和const的常规使用 let声明的变量不存在预解析 let声明的变量不允许重复使用(在同一个作用域内) ES6引入了块级作用域{},块内部定义的变量,在外部是不可以访问到的 使用let在f ...
- EL表达式 - 日常使用表达式记录
表达式 说明 ${field} 查找域,page ->request -> session -> application 中的值. ${field == null ? field1: ...
- 2018-2019-2 20165237《网络攻防技术》Exp1 PC平台逆向破解
2018-2019-2 20165237<网络攻防技术>Exp1 PC平台逆向破解 一.实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调 ...
- Pytorch划分数据集的方法
之前用过sklearn提供的划分数据集的函数,觉得超级方便.但是在使用TensorFlow和Pytorch的时候一直找不到类似的功能,之前搜索的关键字都是"pytorch split dat ...
- Mac安装SecureCRT
8.3.1版本 链接:https://pan.baidu.com/s/1ohHunH_OVewF4QuRUzmChQ 密码:mc77 下载解压后直接是.app 直接打开会提示文件损害 打开终端,输入如 ...
- DotNet 资源大全(转)
awesome-dotnet 是由 quozd 发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. https://github.com/jo ...
- sed 修改文本
修改文本是指将所匹配的文本行利用新文本替代,sed编辑命令的修改文本符号为 c\, [ sed]$ more input [ sed]$ more aa.sed #!/bin/sed -f //c\ ...