图论 - Travel

图论 - Travel

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<iostream>
#include<algorithm>
#include<cstring> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<vector> #include<cctype> #include<set> #include<map> #include<sstream> 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<int,int> #define check(x) cout<<"["<<x<<"]"<<endl; const int MAXN = 5555555; int head[MAXN]; bool vis[MAXN]; int dis[MAXN]; struct Node { int v; int w; int nxt; } edge[MAXN]; long long a, b; int n, m; int edgecnt; void Add_Edge(int u, int v) { edge[edgecnt].v = v; edge[edgecnt].w = a; edge[edgecnt].nxt = head[u]; head[u] = edgecnt++; } long long Spfa() { memset(vis, false, sizeof(vis)); memset(dis, 0x3f, sizeof(dis));//记得是初始化为无穷大= = dis[1] = 0; queue<int>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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的小工具;种子转磁力链接的

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值