TZOJ 1693 Silver Cow Party(最短路+思维)

时间:2021-09-05 00:42:26

描述

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: NM, and X 
Lines 2..M+1: Line i+1 describes road i with three space-separated integers: AiBi, 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

提示

Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units.
题意
给你一个有向图,有N头牛在1-N的位置,问牛i到X再回到i的最大值
题解
X到i的最短路很好求,从X点做一次dij
如何求每个i到X的最短路呢,可以反向建图,然后从X点做一次dij,那么从X到i的最短路就是i到X的最短路
代码
 #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(最短路+思维)的更多相关文章

  1. POJ 3268 Silver Cow Party 最短路

    原题链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  2. POJ3268 Silver Cow Party —— 最短路

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...

  3. POJ 3268 Silver Cow Party 最短路—dijkstra算法的优化。

    POJ 3268 Silver Cow Party Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbe ...

  4. poj 3268 Silver Cow Party &lpar;最短路算法的变换使用 【有向图的最短路应用】 &rpar;

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13611   Accepted: 6138 ...

  5. (poj)3268 Silver Cow Party 最短路

    Description One cow ≤ N ≤ ) conveniently numbered ..N ≤ X ≤ N). A total of M ( ≤ M ≤ ,) unidirection ...

  6. poj 3268 Silver Cow Party&lpar;最短路dijkstra)

    描述: One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the bi ...

  7. B - B Silver Cow Party &lpar;最短路&plus;转置&rpar;

    有n个农场,编号1~N,农场里奶牛将去X号农场.这N个农场之间有M条单向路(注意),通过第i条路将需要花费Ti单位时间.选择最短时间的最优路径来回一趟,花费在去的路上和返回农场的这些最优路径的最长时间 ...

  8. Silver Cow Party(最短路,好题)

    Silver Cow Party Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Su ...

  9. poj 3268 Silver Cow Party(最短路)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17017   Accepted: 7767 ...

随机推荐

  1. 关于NSNotificationCenter消息通信用法

    NSNotificationCenter主要用于广播消息到多个监听着,其传统用法 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotification ...

  2. git学习 远程仓库02

    使用远程仓库: 查看当前远程库://克隆后,至少有一个名为 origin 的远程库,Git 默认使用这个名字来标识你所克隆的原始仓库 git remote -v: 并显示所有远程库的地址: 添加远程仓 ...

  3. (浅谈)&period;Net控件GridView绑定数据

    前台GridView属性设置 <td> <asp:GridView ID="GridView" runat="server" AutoGene ...

  4. ORACLE SQLloader详细语法

    Oracle   SQL   Loader的详细语法     SQL*LOADER是ORACLE的数据加载工具,通常用来将操作系统文件迁移到ORACLE数据库中.SQL*LOADER是大型数据     ...

  5. Hyper-V避免使用快照

    虽然Hyper-V快照好处多多,但应该尽量少用,有两个原因,首先,如果你创建的是数据库服务器快照,你必须执行回滚,这样数据库往往会招到破坏,其次,创建快照会影响虚拟机的性能,实际上,创建快照就是创建第 ...

  6. mysql sqlmap 注入尝试

    假设注入点为 http://www.abc.com/news.php?id=12 //探测数据库信息 sqlmap -u http://www.abc.com/news.php?id=12 –dbs ...

  7. java json的处理

    maven依赖 <dependencies> <dependency> <groupId>com.alibaba</groupId> <artif ...

  8. 死磕 java集合之ConcurrentSkipListMap源码分析——发现个bug

    前情提要 点击链接查看"跳表"详细介绍. 拜托,面试别再问我跳表了! 简介 跳表是一个随机化的数据结构,实质就是一种可以进行二分查找的有序链表. 跳表在原有的有序链表上面增加了多级 ...

  9. explain和profiling分析查询SQL时间

    mysql可以通过profiling命令查看到执行查询SQL消耗的时间. 默认情况下,mysql是关闭profiling的,命令: select @@profiling; +------------- ...

  10. 【Spark调优】:尽量避免使用shuffle类算子

    如果有可能的话,尽量避免使用shuffle类算子.因为Spark作业运行过程中,最消耗性能的地方就是shuffle过程.shuffle过程,就是将分布在集群中多个节点上的同一个key,拉取到同一个节点 ...