四川第七届 I Travel(bfs)
Travel
The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n1,2,…,n.
Among n(n−1)2n(n−1)2 pairs of towns, mm of them are connected by bidirectional highway, which needs aa minutes to travel. The other pairs are connected by railway, which needs bb minutes to travel.
Find the minimum time to travel from town 11 to town nn.
Input
The input consists of multiple tests. For each test:
The first line contains 44 integers n,m,a,bn,m,a,b (2≤n≤105,0≤m≤5⋅105,1≤a,b≤1092≤n≤105,0≤m≤5⋅105,1≤a,b≤109). Each of the following mmlines contains 22 integers ui,viui,vi, which denotes cities uiui and vivi are connected by highway. (1≤ui,vi≤n,ui≠vi1≤ui,vi≤n,ui≠vi).
Output
For each test, write 11 integer which denotes the minimum time.
Sample Input
3 2 1 3
1 2
2 3
3 2 2 3
1 2
2 3
Sample Output
2
3
题意:有n个城市,编号为1~n,每个城市都相互连通,其中有m对城市通过公路连通,其他的城市通过铁路连通,经过公路的时间为a,
经过铁路的时间为b,问从1到达n的时间最短为多少.
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
int n,m;
ll a,b;
vector<int>v[];
struct node
{
int v;
ll t;
};
queue<node>q;
bool bo[];
ll min1(ll a,ll b)
{
if(a>b)return b;
return a;
}
int main()
{
while(~scanf("%d %d %lld %lld",&n,&m,&a,&b))
{
while(!q.empty()) q.pop();
for(ll i=;i<;i++) v[i].clear();
memset(bo,,sizeof(bo));
bool bb=;
for(ll i=;i<=m;i++)
{
int x,y;
scanf("%d %d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
if((x==&&y==n)||(x==n&&y==))bb=;//可能高速比公路慢
}
if(a>=b)
{//挑出与n没有高速公路的点中存不存在与1也没有高速公路的点
if(bb==)printf("%d\n",b);
else
{
for(int i=;i<n;i++)
{
bool is=;
for(int j=;j<v[i].size();j++)
{
if(v[i][j]==||v[i][j]==n)is=;
}
if(is==)
{
bb=;break;
}
}
if(bb==)printf("%d\n",min(a,*b));
else printf("%d\n",a);
}
continue;
}
node s;
s.v=;
s.t=;
q.push(s);
ll mx=b;
bo[]=;
bool f=;
while(!q.empty())
{
node s;
s=q.front();
q.pop();
for(int i=;i<v[s.v].size();i++)
{
int y=v[s.v].at(i);
if(bo[y]) continue;
if(y==n)
{
mx=min1(mx,(s.t+)*a);
f=;
break;
}
node ss;
ss.t=s.t+;
ss.v=y;
q.push(ss);
}
if(f)break;
}
printf("%lld\n",mx);
}
return ;
}
四川第七届 I Travel(bfs)的更多相关文章
- 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)
Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...
- 四川第七届 E Rectangle
Rectangle frog has a piece of paper divided into nn rows and mm columns. Today, she would like to dr ...
- 四川第七届 C Censor (字符串哈希)
Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...
- 哈尔滨理工大学第七届程序设计竞赛初赛(BFS多队列顺序)
哈尔滨理工大学第七届程序设计竞赛初赛https://www.nowcoder.com/acm/contest/28#question D题wa了半天....(真真正正的半天) 其实D题本来就是一个简单 ...
- 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告
2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...
- 山东省第七届ACM省赛------Memory Leak
Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...
- 山东省第七届ACM省赛------Reversed Words
Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- 山东省第七届ACM省赛------The Binding of Isaac
The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...
随机推荐
- MIPI DSI协议学习【转】
本文转载自:http://www.voidcn.com/blog/LoongEmbedded/article/p-6109759.html 1. MIPI DSI DSI:displayser ...
- 关于Kinect音频开发的探究
1.笔者在<Kinect体感程序设计入门>(王森著)的这本书中看到可以使用powershell和COM对象无缝整合,轻松的使用windows系统自带的语音合成功能. 步骤:•打开进入pow ...
- codeforces707A:Brain's Photos
Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. ...
- hdu 1695 GCD 莫比乌斯
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- Functions should do one thing一个函数应该只做一件事
if you take nothing else away from this guide other than this, you'll be ahead of many developers. 如 ...
- Python运行的17个时新手常见错误小结
1)忘记在if , elif , else , for , while , class ,def 声明末尾添加 :(导致“SyntaxError :invalid syntax”) 该错误将发生在类似 ...
- [转]理解Object.assign
本节内容我们继续探讨关于ES2015的一些新的内容,Object.assign函数的使用,使用该函数我们可以快速的复制一个或者多个对象到目标对象中,本文内容涉及es6,es7相关的对象复制的内容,以及 ...
- thinkphp中如何使用phpspreadsheet插件
thinkphp中如何使用phpspreadsheet插件 一.总结 一句话总结:多百度,百度什么都有 1.thinkphp中用composer安装的插件的命名空间是什么? use PhpOffice ...
- Jedis分片连接池
[http://blog.csdn.net/lang_man_xing/article/details/38405269] 一下内容来自网络,但是很多细节没有写出来,所以我经过自己琢磨,终于找到原 ...
- Rainmeter如何打开控制面板的小程序
控制面板功能都是通过访问cpl文件来关联它们的,假设你的系统盘在C盘,那么它们的本地在C:\Windows\System32\ Rainmeter通过使用这个应用程序C:\Windows\System ...