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. Docker Compose yml

    Wordpress + Mysql version: '3' services: db: image: mysql:latest volumes: - db_data:/var/lib/mysql e ...

  2. MongoDB快速入门(五)- Where子句

    RDBMS Where子句等效于MongoDB 查询文档在一些条件的基础上,可以使用下面的操作 操作 语法 示例 RDBMS等效语句 Equality {<key>:<value&g ...

  3. 安装使用snmp监控命令

    1.安装snmp windows下载安装https://sourceforge.net/projects/net-snmp/ centos yum install -y net-snmp net-sn ...

  4. YARN作业提交流程剖析

    YARN(MapReduce2) Yet Another Resource Negotiator / YARN Application Resource Negotiator对于节点数超出4000的大 ...

  5. Oralce查询后修改数据,弹窗报提示these query result are not updateable,include the ROWID to get updateable

    select t.*, (select a.ANNEXNAME from base_annex a where a.id = t.closeFile) closeFileName, (select a ...

  6. makefile下$(wildcard $^),$^,$@,$?,$<,$(@D),$(@F) 含义

    makefile下$(wildcard $^),$^,$@,$?,$<,$(@D),$(@F)代表的不同含义 $(filter-out $(PHONY) $(wildcard $^),$^) 常 ...

  7. SPOJ375 QTREE - Query on a tree

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

  8. maven环境变量配置不成功的原因

    在配置java开发环境时,MAVEN_HOME配置后,再将%MAVEN_HOME%\bin加入path后,mvn -v 不成功,显示mvn不是内部命令 网上寻觅各种办法无果 于是弃用MAVEN_HOM ...

  9. python基础6 - while 循环与转义字符

    8. while 循环基本使用 8.1 while 语句基本语法 初始条件设置 —— 通常是重复执行的 计数器 while 条件(判断 计数器 是否达到 目标次数): 条件满足时,做的事情1 条件满足 ...

  10. Mac终端ls显示文件名为彩色

    原理: ls -G 可显示彩色文件名. 在终端输入: nano ~/.bash_profile 辑器.bash_profile文件,粘贴下面内容: alias cls='tput reset' ali ...