URAL 2034 : Caravans
Description
Input
Output
input | output |
---|---|
7 7 |
2 |

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 1e5 + ;
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
vector<int>e[maxn];
int dp[maxn] , d[maxn] , maxv[maxn], n , m , s , f , r , used[maxn] ;
queue<int>q; void solve()
{
memset(dp , , sizeof(dp));memset(d,-,sizeof(d));memset(maxv,-,sizeof(maxv));memset(used,,sizeof(used));
d[f] = ;
q.push(f);
while(!q.empty())
{
int x = q.front();q.pop();
for(int i = ; i < e[x].size() ; ++ i)
{
int v = e[x][i];
if (d[v] == -)
{
d[v] = d[x] + ;
q.push(v);
}
}
}
maxv[r] = ;
q.push(r);
while(!q.empty())
{
int x = q.front();q.pop();
for(int i = ; i < e[x].size() ; ++ i)
{
int v = e[x][i];
if (maxv[v] == -)
{
maxv[v] = maxv[x] + ;
q.push(v);
}
}
}
dp[s] = maxv[s];used[s] = ;
q.push(s);
while(!q.empty())
{
int x = q.front();q.pop();
maxv[x] = min(maxv[x],dp[x]);
for(int i = ; i < e[x].size() ; ++ i)
{
int v = e[x][i];
if (d[x] - d[v] == )
{
dp[v] = max(dp[v],maxv[x]);
if (!used[v])
{
q.push(v);
used[v] = ;
}
}
}
}
printf("%d\n",maxv[f]);
} int main(int argc,char *argv[])
{
scanf("%d%d",&n,&m);
while(m--)
{
int u ,v ;
scanf("%d%d",&u,&v);u--,v--;
e[u].push_back(v);e[v].push_back(u);
}
scanf("%d%d%d",&s,&f,&r);s--,f--,r--;
solve();
return ;
}
URAL 2034 : Caravans的更多相关文章
- URAL 2034 Caravans(变态最短路)
Caravans Time limit: 1.0 secondMemory limit: 64 MB Student Ilya often skips his classes at the unive ...
- URAL
URAL 2035 输入x,y,c, 找到任意一对a,b 使得a+b==c&& 0<=a<=x && 0<=b<=y 注意后两个条件,顺序搞错 ...
- hdu 2034人见人爱A-B
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2034 解题思路:set的基本用法 #include<iostream> #include& ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
随机推荐
- COM编程入门第二部分——深入COM服务器
本文为刚刚接触COM的程序员提供编程指南,解释COM服务器内幕以及如何用C++编写自己的接口.继上一篇COM编程入门之后,本文将讨论有关 COM服务器的内容,解释编写自己的COM接口和COM服务器所需 ...
- 窥探 Swift 之 函数与闭包的应用实例
今天的博客算是比较基础的,还是那句话,基础这东西在什么时候 都是最重要的.说到函数,只要是写过程序就肯定知道函数是怎么回事,今天就来讨论一下Swift中的函数的特性以及Swift中的闭包.今天的一些小 ...
- 【C++深入探索】Copy-and-swap idiom详解和实现安全自我赋值
分类: C/C++2012-08-30 21:40 2017人阅读 评论(2) 收藏 举报 任何管理某资源的类比如智能指针需要遵循一个规则(The Rule of Three): 如果你需要显式地声明 ...
- LSI MegaCli 命令使用4
Dell服务器常用管理命令总结准备新版本的 MegaCli-1.01.24-0.i386.rpm 会把程序安装在/opt下,可以自定义安装目录,例如:rpm --relocate /opt/=/usr ...
- h5 canvas
概述 Canvas API(画布)用于在网页实时生成图像,并且可以操作图像内容,基本上它是一个可以用JavaScript操作的位图(bitmap). 使用前,首先需要新建一个canvas网页元素. & ...
- 嵌套repeater
通过外层repeater的值来进行内层repeater的数据绑定 前台代码部分: <asp:repeater runat="server" id="repeater ...
- SqlServer数据库设计,纠结的问题,有胆你就来!
最近,小菜遇到了数据库设计上的一个问题,希望各位大侠再次,直抒己见,帮忙分析一下.也可有更好的设计,请直接提出来. 要求:数据库(SQL Server 2005)存储每个学生,单个客观题答案.分数,主 ...
- Python----定义
变量的定义: 变量第一次出现不是声明类型就是赋初值,才能后续使用. 函数的定义: ''' 函数的返回值不用声明类型 函数参数值最好赋一个类型值,例如整型赋值0,列表[] 函数名后面必须跟: ''' d ...
- class类名的管理
var a=document.querySelector(".div1"); a.classList.remove("div2");//减掉一个 a.class ...
- DBA优化SQL采用的WITH AS 用法简介
一.WITH AS简介 WITH AS的用法从oracle 9i新增的,官方文档也称之为:subquery factoring;在进行复杂的查询.统计等操作时使用with as 子句可以大大提高性能! ...