POJ 3268 Silver Cow Party 单向最短路
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 22864 | Accepted: 10449 |
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 <iostream> #include <deque> #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <algorithm> #define maxn 100010 using namespace std; vector<pair<int,int> > E[maxn]; int d1[maxn],d2[maxn]; int n,m,t,x[maxn],y[maxn],z[maxn]; int max(int a,int b){if(a>=b){return a;}return b; } void init1(){for(int i=0;i<maxn;i++){E[i].clear();d1[i] = 1e9;} } void init2(){for(int i=0;i<maxn;i++){E[i].clear();d2[i] = 1e9;} } void dijkstra(int t,int d[]){d[t] = 0;priority_queue<pair<int,int> > q;q.push(make_pair(-d[t],t));while(!q.empty()){int now = q.top().second;q.pop();for(int i=0;i<E[now].size();i++){int v = E[now][i].first;if(d[v] > d[now] + E[now][i].second){d[v] = d[now] + E[now][i].second;q.push(make_pair(-d[v],v));}}} } int main() {while(cin >> n >> m >> t){init1();for(int i=0;i<m;i++){cin >> x[i] >> y[i] >> z[i];E[x[i]].push_back(make_pair(y[i],z[i]));}dijkstra(t,d1);//正求一次 init2();for(int i=0;i<m;i++){E[y[i]].push_back(make_pair(x[i],z[i]));} //记得在这里要把所有的路反过来dijkstra(t,d2);//反求一次 int num = -1;for(int i=1;i<=n;i++){num = max(num,d1[i]+d2[i]);}cout << num << endl;}return 0; }
转载于:https://www.cnblogs.com/l609929321/p/7240806.html
POJ 3268 Silver Cow Party 单向最短路相关推荐
- POJ 3268 Silver Cow Party (最短路径)
POJ 3268 Silver Cow Party (最短路径) Description One cow from each of N farms (1 ≤ N ≤ 1000) convenientl ...
- [POJ](3268)Silver Cow Party ---最短路径(图)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 23762 Accepted: 1085 ...
- POJ - 3268 Silver Cow Party(最短路)
题目链接:点击查看 题目大意:给出n个点以及m条单项路径和一个点x,设从x点到i的距离及从i回到x点的距离分别为d1和d2,求d1+d2的最大值(1<=i<=n) 题目分析:看到这个题的第 ...
- POJ 3268 Silver Cow Party
题目链接 题意 单向图,N - 1个牛去聚会,求所有牛去聚会和回家路径和的最大值 AC 很骚的操作 首先从派对的地方跑Dijkstra求出回家的最短路,然后将所有边翻转再次从聚会跑Dijkstra就是 ...
- POJ 3268 Silver Cow Party--正反Dijkstra
- 【POJ】3268 Silver Cow Party (将有向图的边反转)
问题链接:http://poj.org/problem?id=3268 [问题描述] One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- 【POJ】3268 Silver Cow Party
题目链接:http://poj.org/problem?id=3268 题意 :有N头奶牛,M条单向路.X奶牛开party,其他奶牛要去它那里.每头奶牛去完X那里还要返回.去回都是走的最短路.现在问这 ...
- POJ 3268 D-Silver Cow Party
http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...
- Silver Cow Party (POJ - 3268 )
Silver Cow Party (POJ - 3268 ) 这道题是我做的最短路专题里的一道题,但我还没做这个,结果比赛就出了,真是.......... 题目: One cow from each ...
- D - Silver Cow Party POJ - 3268
D - Silver Cow Party POJ - 3268 dijkstra 是 O(n2),堆优化一下, O(nlogn) 对每个点跑一次 dj, 取 max(dis(x->i)+dis( ...
最新文章
- 528. 按权重随机选择
- html支持的语音文件格式,html5中如何设置audio支持音频格式
- 【每周CV论文推荐】 深度学习人脸检测入门必读文章
- Java笔记:与系统交互、系统相关的类,Object类
- wordpress archive.php,哪个网址将导致wordpress使用archive.php?
- 创文html5作品,【《创文故事》纪录短片入围作品展播之七】引路人
- 数据结构——基于字符串模式匹配算法的病毒感染检测
- CentOS 7 Linux 的初始化系统(系统服务管理和控制程序/Init System) -- systemd 详解
- shiro学习(18):使用注解实现权限认证和后台管理三
- 网络流入门题目 - bzoj 1001
- [NOIP2006] 能量项链
- c++ 课程设计之车票管理系统
- css基础知识汇总8
- 如何在手机上编码python_如何在Python中进行热编码?
- windows搭建FTP
- React脚手架开发
- 严重: The web application [] appears to have started a thread named [Thread-
- DataHub调研数据血缘
- R统计笔记(二):投影运算与转换
- 【JavaScript 逆向】极验三代无感验证码逆向分析
热门文章
- 1020. Tree Traversals
- webpack创建页面的过程
- finedb(内置的HSQL数据库)迁移数据到MySQL
- PHP三元运算符 isset($_GET['id']) ? $_GET['id'] : ”
- C# 将已有程序封装为DLL文件,供其他程序调用
- 无法完成验证,可能QQ文件已损坏,您需要重新安装QQ
- python_numpy的基础
- 关于电脑桌面图标消失并且右键无法点击的情况
- 【python】list,dict赋值不要用等号,要用extend,update
- wordpress主题安装教程及错误处理