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)的更多相关文章

  1. 四川第七届 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), ...

  2. 四川第七届 E Rectangle

    Rectangle frog has a piece of paper divided into nn rows and mm columns. Today, she would like to dr ...

  3. 四川第七届 C Censor (字符串哈希)

    Censor frog is now a editor to censor so-called sensitive words (敏感词). She has a long text pp. Her j ...

  4. 哈尔滨理工大学第七届程序设计竞赛初赛(BFS多队列顺序)

    哈尔滨理工大学第七届程序设计竞赛初赛https://www.nowcoder.com/acm/contest/28#question D题wa了半天....(真真正正的半天) 其实D题本来就是一个简单 ...

  5. 2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

    2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh ...

  6. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  7. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  8. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  9. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

随机推荐

  1. centos_mysql5.6.35_rpm安装

    1.查看操作系统相关信息.[root@linuxidc ~]# cat /etc/issue CentOS release 6.5 (Final) Kernel \r on an \m [root@l ...

  2. 【P1379】八数码难题(搜索+暴力)

    这个题真是... 不想说什么了,及其复杂和烦人的一道题.基础思路就是bfs,用两个队列分别进行0的位置的计算和每一步的状态..然而这个题最重要的一点在于判重,实际上可以康托展开用全排列的个数进行判重, ...

  3. BZOJ3668/UOJ2 [NOI2014]起床困难综合症

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  4. Eclipse导出apk

    http://jingyan.baidu.com/article/7908e85c8dea30af491ad24f.html

  5. Qt5 窗口内的控件随窗口大小自动变化

    http://www.bubuko.com/infodetail-827151.html 讲的很详细

  6. 抓包tcpdump

      tcpdump是基于Unix系统的命令行式的数据包嗅探工具 tcpdump  可以监测真机或者模拟器 2g/3g/wifi下数据流动,前提手机必须root过. fillder也可以检测客户端数据包 ...

  7. JAVA动态代理的全面深层理解

    Java 动态代理机制的出现,使得 Java 开发人员不用手工编写代理类,只要简单地指定一组接口及委托类对象,便能动态地获得代理类.代理类会负责将所有的方法调用分派到委托对象上反射执行,在分派执行的过 ...

  8. 关于设置UITableView的背景图片

    在UITableViewController中,要设置UITableView的背景图片,以前常用的方法是使用backgroundcolor属性,这个属性可以通过UIImage来获取,但最近发现这个方法 ...

  9. MySql按周/月/日分组统计数据的方法

    知识关键词:DATE_FORMAT select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case grou ...

  10. dga-5.29~6.4

    ahzoyr.codtuqb.netvzugk.bizyfewr.bizbgqjyk.bizcdychl.comcjgfuk.comcnncfc.cometypsc.comfaouli.comffjj ...