博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图论 - Travel
阅读量:6280 次
发布时间:2019-06-22

本文共 1686 字,大约阅读时间需要 5 分钟。

Travel

The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n.

Among n(n−1) / 2 pairs of towns, m 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 1 to town n.

Input

The input consists of multiple tests. For each test:

The first line contains 4 integers n,m,a,bn,m,a,b (2≤n≤1e5,0≤m≤5⋅1e5,1≤a,b≤1e9).

Each of the following mm lines contains 22 integers ui,viui,vi, which denotes cities uiui and vivi are connected by highway. (1≤ui,vi≤n,ui≠vi).

Output

For each test, write 1 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

-----------------------------------------我是分割线^_^--------------------------------- 这个题就是一个求补图的最短路的很好的例子,由于在这个题中补图的权值一样,所以就可以和用 BFS求普通的最短路一样的求解了,至于结构体的方式来储存邻接表还是第一次,不过感觉挺方便的 所以以后还是尽量习惯吧,对了,还要注意理解题解中set的作用,用来筛选出与当前点未连接的点。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define INF 0x3f3f3f3f #define Int __int64 #define pii pair
#define check(x) cout<<"["<
<<"]"<
q; while (!q.empty()) q.pop(); vis[1] = true; q.push(1); while (!q.empty()) { int now = q.front(); q.pop(); for (int i = head[now]; i != -1; i = edge[i].nxt) { int v = edge[i].v; int w = edge[i].w; if (dis[v] > dis[now] + w) { dis[v] = dis[now] + w; if (!vis[v]) {//标记这里还是有点疑问,因为有的人不标记也行= = vis[v] = true; q.

转载于:https://www.cnblogs.com/steamedbun/p/5786710.html

你可能感兴趣的文章
对象的继承及对象相关内容探究
查看>>
Spring: IOC容器的实现
查看>>
Serverless五大优势,成本和规模不是最重要的,这点才是
查看>>
Nginx 极简入门教程!
查看>>
iOS BLE 开发小记[4] 如何实现 CoreBluetooth 后台运行模式
查看>>
Item 23 不要在代码中使用新的原生态类型(raw type)
查看>>
为网页添加留言功能
查看>>
JavaScript—数组(17)
查看>>
Android 密钥保护和 C/S 网络传输安全理论指南
查看>>
以太坊ERC20代币合约优化版
查看>>
Why I Began
查看>>
同一台电脑上Windows 7和Ubuntu 14.04的CPU温度和GPU温度对比
查看>>
js数组的操作
查看>>
springmvc Could not write content: No serializer
查看>>
Python系语言发展综述
查看>>
新手 开博
查看>>
借助开源工具高效完成Java应用的运行分析
查看>>
163 yum
查看>>
第三章:Shiro的配置——深入浅出学Shiro细粒度权限开发框架
查看>>
80后创业的经验谈(转,朴实但实用!推荐)
查看>>