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

- #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 ...
随机推荐
- test_wifi
#!/system/bin/sh #Load driver echo "ASD WIFI TESTING..." AP_NAME="default" num=0 ...
- monkeyrunner 详细介绍
MonkeyRunner: monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器.通过monkeyrunner,您可以写出一个 ...
- 怎样将关系型数据表转换至hbase数据表
首先须要把关系型数据库的数据表的数据添加由 "纵向延伸",转变为HBase数据表的"横向延伸" 一.Hbase的存储结构 a) HBase以表(HTa ...
- php parse_url 函数使用方法解析
此函数返回一个关联数组,包含现有 URL 的各种组成部分.如果缺少了其中的某一个,则不会为这个组成部分创建数组项.组成部分为: scheme – 如 http host port pass path ...
- 再探Java基础——String.format(String format, Object… args)的使用
最近看到类似这样的一些代码:String.format("参数%s不能为空", "birthday"); 以前还没用过这功能不知咐意思,后研究了一下,详细讲解如 ...
- IPython notebook 使用介绍
参考资料: http://mindonmind.github.io/2013/02/08/ipython-notebook-interactive-computing-new-era/ http:// ...
- NYOJ-1070诡异的电梯【Ⅰ】
这道题是个dp,主要考虑两种情况,刚开始我把状态转移方程写成了dp[i] = min(dp[i-1] + a, dp[i + 1] +b); 后来想想当推到dp[i]的时候,那个dp[i + 1]还没 ...
- LINQ Enumerable 续 II
Enumerable.TakeWhile和Enumerable.SkpWhile Enumerable.TakeWhile和Enumerable.SkpWhile将通过判断条件,来获取和跳过序列. T ...
- telnet与tnsping
在cmd 下面 tnsping ZCGL ZCGL这个是在oracle做好的数据库连接. telnet IP地址 加上端口号. 查看视图的编写语句 select dbms_metadata.get_d ...
- 'Invalid update: invalid number of rows in section xx. The number of rows contained in an existing section after the update (xxx)...
'Invalid update: invalid number of rows in section 5. The number of rows contained in an existing s ...