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 ...
随机推荐
- 提高VS2010/VS2012编译速度
除了合理的划分模块,减少link的时间外,充分利用多核编译也很重要. VS2010/2012都可以用多核编译,需要同时设置如下两个参数: Enable Minimal Rebuild Propert ...
- c++ map与 qt QMap insert 区别
当插入相同key的字段时, c++ map 会保留原来的字段, QMap 则会取代原来的字段.
- Hadoop32位和64位的查询
1.查看自己的hadoop版本是32位还是64位 进入: hadoop-2.6.4/lib/native 使用file命令 file libhadoop.so.1.0.0
- tortoisegit 保存用户名密码
方法一当你配置好git后,在C:\Documents and Settings\Administrator\ 目录下有一个 .gitconfig 的文件,里面会有你先前配好的name 和email,只 ...
- ListActivity ListView 使用 介绍 用法
ListActivity简单的说就是ListView和Activity的结合,跟ListView和Activity组合实现的没有什么很大的差别,主要是比较方便. 在实现时,要注意: 1.一般情况,Li ...
- css09浮动属性
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 设为首页 收藏(IE可用)
function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vr ...
- 使用DML语句【weber出品必属精品】
DML语句包含以下语法: INSERT:往一个表中增加新行 DELETE:从一个表中删除掉现有的行 UPDATE:更改一个表中现有的行 INSERT语句语法:INSERT INTO TABLE(COL ...
- xib添加手势后报错:-[UITapGestureRecognizer setFrame:]: unrecognized selector sent to instance xxx
主要原因如下: + (instancetype)mineHeaderView { return [[NSBundle mainBundle] loadNibNamed:@"DDMineHea ...
- js的相关验证
1 var JavaScriptCommon = { /*身份证号码校验*/ VerifyID: function (socialNo) { if (socialNo == "") ...