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 ...
随机推荐
- 背包问题(01背包,完全背包,多重背包(朴素算法&&二进制优化))
写在前面:我是一只蒟蒻~~~ 今天我们要讲讲动态规划中~~最最最最最~~~~简单~~的背包问题 1. 首先,我们先介绍一下 01背包 大家先看一下这道01背包的问题 题目 有m件物品和一个容量为 ...
- 微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误
如题,英文中文表述的是一个意思 退款测试在我本机测试一切都是正常的,但是发布到了服务器就报这样的一个错啦 但是无论百度或者google或者bing,你能够搜索到的结果都很类似,综合起来就是加这样一些代 ...
- 浅谈 JSP & Servlet
body { text-align: center; } div.develon { background-color: #cccccc; font-size: 20px; } 背景 相信大家都见过这 ...
- shell 生成任意大小文件
$ dd if=/dev/zero of=junk.data bs=1M count=1 参数: if (input file) of (output file) bs(block size) co ...
- Storage 002 电商数据库设计
[用户模块] 账户登录:邮箱/用户名/已验证手机 密码 如果将所有字段都放到一张表里存储? 数据插入异常 只想插入一个值的 由于需要主键信息,插入的一行变成新的一行,和原来的记录无关. ...
- Ubuntu18.04应用程序安装集锦
整理网上的资源: Python Web开发工具箱 ubuntu美化及超NB的zsh配置 api文档查询工具:zeal,dash(收费)
- 423 重温Java Script and jQuery 葵花宝典 Bootstrap
Bootstrap需要引的三个文件 <link rel="stylesheet" href="css/bootstrap.css"> 表格元素 ...
- opencv基础教程 之 图像基础和绘图
1,教程:感谢小强 2,用argparse传参数来显示一张图片 #!/usr/bin/python #linux系统 #coding=utf-8 import cv2 import argparse ...
- jmeter和jdk的安装教程
jmeter和jdk的安装教程 1:先下载安装jdk并且配置环境变量,配置环境变量的步骤如下: 右击计算机图标--点击属性--点击高级系统设置--点击环境变量后添加jdk的环境变量 a.系统变量→新建 ...
- MemCache详细解读(转)
参考:https://www.cnblogs.com/xrq730/p/4948707.html MemCache是什么 MemCache是一个自由.源码开放.高性能.分布式的分布式内存对象缓存系统, ...