描述
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?
输入
Line 1: Three space-separated integers, respectively: N, M, and X
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.
输出
Line 1: One integer: the maximum of time any one cow must walk.
样例输入
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
样例输出
10
提示
#include<bits/stdc++.h>
using namespace std; const int maxn=;
vector< pair<int,int> >G[][maxn];
int d[][maxn];
int n,m,x; void dij(int s,int k)
{
for(int i=;i<=n;i++)d[k][i]=0x3f3f3f3f;
d[k][s]=;
queue<int>q;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(auto x:G[k][u])
{
int v=x.first;
int w=x.second;
if(d[k][v]>d[k][u]+w)
{
d[k][v]=d[k][u]+w;
q.push(v);
}
}
}
}
int main()
{
int u,v,w;
scanf("%d%d%d",&n,&m,&x);
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
G[][u].push_back({v,w});
G[][v].push_back({u,w});
}
dij(x,),dij(x,);
int maxx=;
for(int i=;i<=n;i++)
maxx=max(maxx,d[][i]+d[][i]);
printf("%d\n",maxx);
return ;
}
TZOJ 1693 Silver Cow Party(最短路+思维)的更多相关文章
-
POJ 3268 Silver Cow Party 最短路
原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total ...
-
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算法的优化。
POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...
-
poj 3268 Silver Cow Party (最短路算法的变换使用 【有向图的最短路应用】 )
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13611 Accepted: 6138 ...
-
(poj)3268 Silver Cow Party 最短路
Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...
-
poj 3268 Silver Cow Party(最短路dijkstra)
描述: One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the bi ...
-
B - B Silver Cow Party (最短路+转置)
有n个农场,编号1~N,农场里奶牛将去X号农场.这N个农场之间有M条单向路(注意),通过第i条路将需要花费Ti单位时间.选择最短时间的最优路径来回一趟,花费在去的路上和返回农场的这些最优路径的最长时间 ...
-
Silver Cow Party(最短路,好题)
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Su ...
-
poj 3268 Silver Cow Party(最短路)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17017 Accepted: 7767 ...
随机推荐
-
关于NSNotificationCenter消息通信用法
NSNotificationCenter主要用于广播消息到多个监听着,其传统用法 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotification ...
-
git学习 远程仓库02
使用远程仓库: 查看当前远程库://克隆后,至少有一个名为 origin 的远程库,Git 默认使用这个名字来标识你所克隆的原始仓库 git remote -v: 并显示所有远程库的地址: 添加远程仓 ...
-
(浅谈).Net控件GridView绑定数据
前台GridView属性设置 <td> <asp:GridView ID="GridView" runat="server" AutoGene ...
-
ORACLE SQLloader详细语法
Oracle SQL Loader的详细语法 SQL*LOADER是ORACLE的数据加载工具,通常用来将操作系统文件迁移到ORACLE数据库中.SQL*LOADER是大型数据 ...
-
Hyper-V避免使用快照
虽然Hyper-V快照好处多多,但应该尽量少用,有两个原因,首先,如果你创建的是数据库服务器快照,你必须执行回滚,这样数据库往往会招到破坏,其次,创建快照会影响虚拟机的性能,实际上,创建快照就是创建第 ...
-
mysql sqlmap 注入尝试
假设注入点为 http://www.abc.com/news.php?id=12 //探测数据库信息 sqlmap -u http://www.abc.com/news.php?id=12 –dbs ...
-
java json的处理
maven依赖 <dependencies> <dependency> <groupId>com.alibaba</groupId> <artif ...
-
死磕 java集合之ConcurrentSkipListMap源码分析——发现个bug
前情提要 点击链接查看"跳表"详细介绍. 拜托,面试别再问我跳表了! 简介 跳表是一个随机化的数据结构,实质就是一种可以进行二分查找的有序链表. 跳表在原有的有序链表上面增加了多级 ...
-
explain和profiling分析查询SQL时间
mysql可以通过profiling命令查看到执行查询SQL消耗的时间. 默认情况下,mysql是关闭profiling的,命令: select @@profiling; +------------- ...
-
【Spark调优】:尽量避免使用shuffle类算子
如果有可能的话,尽量避免使用shuffle类算子.因为Spark作业运行过程中,最消耗性能的地方就是shuffle过程.shuffle过程,就是将分布在集群中多个节点上的同一个key,拉取到同一个节点 ...