日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

四川第七届 I Travel(bfs)

發布時間:2023/11/27 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 四川第七届 I Travel(bfs) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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?(2n105,0m5?105,1a,b1092≤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. (1ui,vin,uivi1≤ui,vi≤n,ui≠vi).

Output

For each test, write?11?integer which denotes the minimum time.

Sample Input

    3 2 1 31 22 33 2 2 31 22 3

Sample Output

    23

題意:有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[100005];
struct node
{int v;ll t;
};
queue<node>q;
bool bo[100005];
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=0;i<100005;i++) v[i].clear();memset(bo,0,sizeof(bo));bool bb=0;for(ll i=1;i<=m;i++){int x,y;scanf("%d %d",&x,&y);v[x].push_back(y);v[y].push_back(x);if((x==1&&y==n)||(x==n&&y==1))bb=1;//可能高速比公路慢}if(a>=b){//挑出與n沒有高速公路的點中存不存在與1也沒有高速公路的點if(bb==0)printf("%d\n",b);else{for(int i=2;i<n;i++){bool is=0;for(int j=0;j<v[i].size();j++){if(v[i][j]==1||v[i][j]==n)is=1;}if(is==0){bb=0;break;}}if(bb==0)printf("%d\n",min(a,2*b));else printf("%d\n",a);}continue;}node s;s.v=1;s.t=0;q.push(s);ll mx=b;bo[1]=1;bool f=0;while(!q.empty()){node s;s=q.front();q.pop();for(int i=0;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+1)*a);f=1;break;}node ss;ss.t=s.t+1;ss.v=y;q.push(ss);}if(f)break;}printf("%lld\n",mx);}return 0;
}

?



轉載于:https://www.cnblogs.com/caiyishuai/p/8955140.html

總結

以上是生活随笔為你收集整理的四川第七届 I Travel(bfs)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。