TZOJ 1693 Silver Cow Party(最短路+思维)
描述
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 ...
随机推荐
- MySQL5.7.32 通用版本安装
1 上传镜像,配置好yum源 2 下载MySQL相关的包 https://dev.mysql.com/downloads/mysql/ 3 解压安装: tar -zxvf mysql-5.7.23- ...
- CSVN配置自动备份策略
在浏览器中登录CSVN管理页面,登录地址就是ip:3343,版本库->backup schedule ,选择type of job(备份类型),when to run(备份频率和时间),numb ...
- liunx学习笔记(一:常用命令)
linux: 在学习linux之前我们应该多少了解windows的一些相关操作,linux也就是类似windows的另一种操作系统,用来管理软硬件的一种应用.在windows下你可以通过鼠标点击相关的 ...
- LOJ 2991 「THUSC 2016」补退选——trie+线段树合并或vector
题目:https://loj.ac/problem/2291 想了线段树合并的做法.就是用线段树维护 trie 的每个点在各种时间的操作. 然后线段树合并一番,线段树维护前缀最大值,就是维护最大子段和 ...
- C# 流总结
前言 本篇文章简单总结了在C#编程中经常会用到的一些流.比如说FileStream.MemoryStream. BufferedStream. NetWorkStream. StreamReader/ ...
- Eclipse配置Python的IDE
我第一个用来实际应用的编程语言是Java,于是对Eclipse情有独钟.但是自从上手了Notepad++后,使用Eclipse的机会越来越少. 最近开始学习Python,因为对Python不太熟悉,有 ...
- zabbix监控windows服务器
Zabbix agent 在windows上安装部署 1. 下载与解压 地址: http://www.zabbix.com/downloads/2.4.0/zabbix_agents_2.4.0.w ...
- centos 支持安装libsodium
yum install epel-release -y yum install libsodium -y 然后没了.
- python解决SyntaxError: Non-ASCII character '\xe6'
出现情况,输入如下一个函数demo: run,报错: SyntaxError: Non-ASCII character '\xe6' in file /Users/XX/PycharmProjects ...
- scrapy-实现下一页请求, scrapy.Request
# -*- coding: utf-8 -*- import scrapy class HrSpider(scrapy.Spider): name = 'hr' allowed_domains = [ ...