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. win10系统下载地址

    Win10正式版微软官方原版ISO系统镜像下载: Win10正式版32位简体中文版(含家庭版.专业版) 文件名: cn_windows_10_multiple_editions_x86_dvd_684 ...

  2. 《机器学习基石》第一周 —— When Can Machine Learn?

    (注:由于之前进行了吴恩达机器学习课程的学习,其中有部分内容与机器学习基石的内容重叠,所以以下该系列的笔记只记录新的知识) <机器学习基石>课程围绕着下面这四个问题而展开: 主要内容: 一 ...

  3. 使用shell统计字符串出现的次数,并从大到小进行排序显示

  4. BZOJ4311:向量

    题意:要求支持三个操作,加入删除一个向量,询问当前向量与给定向量的最大值. 题解:线段树时间分治,每个区间做一个凸包,查询的时候到对应区间的凸包上三分. (话说我这个可能有点问题,三分那一块R-L&g ...

  5. JavaWeb -- Jsp 自定义标签的使用

    Jsp中不要有一行Java代码, 需要的Java代码都要封到自定义标签中. 自定义标签的作用: a.  自定义标签除了可以移除jsp页面java代码外,它也可以实现以上功能. b.  控制jsp页面某 ...

  6. BZOJ3672/UOJ7 [Noi2014]购票

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

  7. MySql基础学习-总纲

  8. shitf+tab

    在eclipse中,shitf+tab可以使代码向左移动.

  9. java数组类Arrays:比较,填充,排序

    int i1[] = {1,2,3,4,5,6}; int i2[] = {6,5,4,3,2,1}; //排序 Arrays.sort(i2); System.out.println(i1.equa ...

  10. Sublime2 + SASS + Koala 测试

    Sublime SASS语法高亮插件下载地址:https://github.com/kuroir/SCSS.tmbundle/zipball/SublimeText2 koala_2.0.4_setu ...