POJ3268 Silver Cow Party(dijkstra+矩阵转置)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 15156 | Accepted: 6843 |
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
Source
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
const int maxn=+; int w[maxn][maxn];
int v[maxn], d[maxn], c[maxn];
int n, m, x; void dijkstra(int k)
{
memset(v, , sizeof(v));
for(int i = ; i <= n; i++) d[i] = (i==k ? : INF);
for(int i = ; i <= n; i++){
int x1, m = INF;
for(int y = ; y <= n; y++) if(!v[y] && d[y]<=m) m = d[x1=y];
v[x1] = ;
for(int y = ; y <= n; y++) d[y] = min(d[y], d[x1]+w[x1][y]);
}
}//dijkstra紫书模板
void tran() {
for(int i = ; i <= n; i++) {
for(int j = ; j <= i; j++)
swap(w[i][j], w[j][i]);
}
}//矩阵转置
int main()
{
while(~scanf("%d%d%d", &n, &m, &x)) {
int a, b, t;
memset(w, INF, sizeof(w));
for(int i = ; i < m; i++) {
scanf("%d%d%d", &a, &b, &t);
w[a][b] = min(w[a][b], t);
}
memset(c, , sizeof(c));
dijkstra(x);
for(int i = ; i <= n; i++) c[i] = d[i];
tran();
dijkstra(x);
int ans = -;
for(int i = ; i <= n; i++) {
c[i] += d[i];
ans = max(ans,c[i]);
}
printf("%d\n", ans);
}
}
POJ3268 Silver Cow Party(dijkstra+矩阵转置)的更多相关文章
- POJ3268 Silver Cow Party Dijkstra最短路
Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to atten ...
- poj3268 Silver Cow Party(两次SPFA || 两次Dijkstra)
题目链接 http://poj.org/problem?id=3268 题意 有向图中有n个结点,编号1~n,输入终点编号x,求其他结点到x结点来回最短路长度的最大值. 思路 最短路问题,有1000个 ...
- POJ 3268 Silver Cow Party (Dijkstra)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13982 Accepted: 6307 ...
- POJ 3268 Silver Cow Party 最短路径+矩阵转换
Silver Cow Party Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) T ...
- POJ3268 Silver Cow Party —— 最短路
题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ-3268 Silver Cow Party---正向+反向Dijkstra
题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...
- poj3268 Silver Cow Party(两次dijkstra)
https://vjudge.net/problem/POJ-3268 一开始floyd超时了.. 对正图定点求最短,对逆图定点求最短,得到任意点到定点的往返最短路. #include<iost ...
- POJ3268 Silver Cow Party【最短路】
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big co ...
- poj3268 Silver Cow Party(农场派对)
题目描述 原题来自:USACO 2007 Feb. Silver N(1≤N≤1000)N (1 \le N \le 1000)N(1≤N≤1000) 头牛要去参加一场在编号为 x(1≤x≤N)x(1 ...
随机推荐
- 第10讲- UI线程阻塞及其优化
第10讲UI线程阻塞及其优化 .UI 阻塞demo (首先在activity_main.xml中放置两个button,分别命名为button1,button2) //首先设置一个button1用来进行 ...
- Android学习总结——去除标题栏
1.继承app.Activity的Activity去除标题栏 @Override protected void onCreate(Bundle savedInstanceState) { super. ...
- 小贝_mysql建表以及列属性
mysql建表以及列属性 简要: 一.建表原则 二.具体的列属性说明 一.建表原则 建表: 事实上就是声明列的过程,数据终于是以文件的形式放在硬盘(内存) 列: 不同的列类型占的空间不一样. 选列的原 ...
- Eclipse代理设置
这段时间公司实行代理上网,不仅通过浏览器上网须要不停的输入username和password,在本地调试程序时候Eclipse居然也弹出框让输入username和password. 如图: 解决的方法 ...
- hdoj 3400 三分
两次三分 #include <iostream> #include <cstdio> #include <cstring> #include <cmath&g ...
- [HeadFirst-HTMLCSS学习笔记][第十三章表格]
表格 -table 块 tr 行 table row th 表头 table head td 表数据 table data; caption 表格标题 <table> <captio ...
- JQuery hover(over,out) 使用笔记
转载自:http://www.douban.com/note/202404884/ JQuery hover(over,out) 使用笔记 JavaScript 下.onmouseover() 和 o ...
- css基本选择器
CSS:层叠样式表 (Cascading Style Sheets) 结构层:HTML表现层: CSS行为层: DOM,JavaScript CSS语法结构:div{background:#f00;} ...
- CSS减肥的工具–Firefox插件 CSS Usage
首先,我们需要安装Firefox(猛击此处下载),或者确定你已经安装的版本已经高于3.1; 第二步,安装前端开发人员最普及的开发工具 Firebug: 第三步,安装CSS Usage 0.3.4.1: ...
- DBHelper 类(网上收集)
这个是我网上找的,觉得不错的一个DBHelper类,下面是作者话: // 微软的企业库中有一个非常不错的数据操作类了.但是,不少公司(起码我遇到的几个...),对一些"封装"了些什 ...