upc组队赛6 Bumped!【最短路】
Bumped!
题目描述
Peter returned from the recently held ACM ICPC World finals only to find that his return flight was overbooked and he was bumped from the flight! Well, at least he wasn’t beat up by the
airline and he’s received a voucher for one free flight between any two destinations he wishes.
He is already planning next year’s trip. He plans to travel by car where necessary, but he may be using his free flight ticket for one leg of the trip. He asked for your help in his planning.
He can provide you a network of cities connected by roads, the amount it costs to buy gas for traveling between pairs of cities, and a list of available flights between some of those cities. Help Peter by finding the minimum amount of money he needs to spend to get from his hometown to next year’s destination!
输入
The input consists of a single test case. The first line lists five space-separated integers n, m, f, s, and t, denoting the number of cities n (0 < n ≤ 50 000), the number of roads m (0 ≤ m ≤ 150 000), the number of flights f (0 ≤ f ≤ 1 000), the number s (0 ≤ s < n) of the city in which Peter’s trip starts, and the number t (0 ≤ t < n) of the city Peter is trying to travel to. (Cities are numbered from 0 to n − 1.)
The first line is followed by m lines, each describing one road. A road description contains three space-separated integers i, j, and c (0 ≤ i, j < n, i 6= j and 0 < c ≤ 50 000), indicating there is a road connecting cities i and j that costs c cents to travel. Roads can be used in either direction for the same cost. All road descriptions are unique.
Each of the following f lines contains a description of an available flight, which consists of two space-separated integers u and v (0 ≤ u, v < n, u 6= v) denoting that a flight from city u to city v is available (though not from v to u unless listed elsewhere). All flight descriptions are unique.
输出
Output the minimum number of cents Peter needs to spend to get from his home town to the competition,using at most one flight. You may assume that there is a route on which Peter can reach his destination.
样例输入
8 11 1 0 5
0 1 10
0 2 10
1 2 10
2 6 40
6 7 10
5 6 10
3 5 15
3 6 40
3 4 20
1 4 20
1 3 20
4 7
样例输出
45
题意
n个点,m条边,f条飞行路线,s起始点,t终点
其中f条飞行路线可以使一条边的距离为0;
题解
这题很坑,相当坑,有如下几点
不管f有多少条 ,只能选一条 ,所以我们枚举每一条f边为0,去求最短路;
如果f=0,别直接不跑了
数据范围是long long ,如果初始化为INF 就会WA!! 太坑了! 改成9999999999或更多(在此WA了几百发,留下惨痛教训)
可以用map或者set来存
代码
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn =1000010;
using namespace std;
struct node{
ll to;
ll cost;
bool operator < (node b)const{
return cost > b.cost;
}
};
struct edge{
ll to;
ll cost;
};
vector<edge> E[maxn];
int vis[maxn];
ll dis[maxn];
priority_queue<node>q;
ll x,y,z;
ll n,m,f,st,ed;
void Dijkstra(ll s){
memset(vis,0,sizeof vis);
for(int i = 0; i < n; i++)
dis[i] = 9999999999;
while(!q.empty())
q.pop();
dis[s] = 0;
q.push(node{s,0});
node tmp;
while(!q.empty()){
tmp = q.top();
q.pop();
ll u = tmp.to;
if(vis[u])
continue;
vis[u] = 1;
for(int i = 0; i < E[u].size(); i++){
ll v = E[u][i].to;
ll w = E[u][i].cost;
if(!vis[v] && dis[v] > dis[u] + w){
dis[v] = dis[u] + w;
q.push(node{v,dis[v]});
}
}
}
}
int main(){
scanf("%lld%lld%lld%lld%lld",&n,&m,&f,&st,&ed);
while(m--){
scanf("%lld%lld%lld",&x,&y,&z);
E[x].pb(edge{y,z});
E[y].pb(edge{x,z});
}
ll ans = 9999999999;
Dijkstra(st);
ans = dis[ed];
while(f--){
scanf("%lld%lld",&x,&y);
E[x].pb(edge{y,0});
Dijkstra(st);
ans = min(ans,dis[ed]) ;
E[x].erase(E[x].end() - 1);
}
printf("%lld\n",ans);
return 0;
}
/*
6 7 2 0 5
0 1 10
0 3 5
1 4 10
2 3 5
0 5 100
4 5 5
2 5 5
0 2
1 3
*/
upc组队赛6 Bumped!【最短路】的更多相关文章
- upc组队赛15 Made In Heaven【第K短路 A*】
Made In Heaven 题目描述 One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- upc组队赛1 过分的谜题【找规律】
过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...
- upc组队赛1 不存在的泳池【GCD】
不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...
- upc组队赛1 黑暗意志【stl-map】
黑暗意志 题目描述 在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现.迷雾同样遮蔽着这片大陆古老邪恶的要塞--雷神的雷电王座.在雷神统治时期,他的要塞就是雷电之王力 ...
- upc组队赛1 闪闪发光 【优先队列】
闪闪发光 题目描述 一所位于云南昆明的中医药本科院校--云南中医学院. 因为报考某专业的人数骤减,正面临着停招的危机. 其中有九名少女想到一条妙计--成为偶像, 只要她们成为偶像,学校的名气便会增加, ...
- upc组队赛1 流连人间的苏苏
流连人间的苏苏 题目描述 苏苏在做红尘仙的任务时,发现坐落于风景秀丽.四季如春的昆明市的云南中医学院. 没过多久,苏苏就喜欢上了这个学校.以致于苏苏忘了回涂山的时间,现在她只剩下d天的时间待在云南中医 ...
- upc组队赛18 THE WORLD【时间模拟】
THE WORLD 题目链接 题目描述 The World can indicate world travel, particularly on a large scale. You mau be l ...
- upc 组队赛18 STRENGTH【贪心模拟】
STRENGTH 题目链接 题目描述 Strength gives you the confidence within yourself to overcome any fears, challeng ...
随机推荐
- 提高redis cluster集群的安全性,增加密码验证
节点设置密码 1.修改配置文件 在配置文件里面增加密码选项,一定要加上masterauth,不然Redirected的时候会失败. masterauth redispassword requirepa ...
- Linux查看文件大小5个常用命令
1. 前言 Linux 系统有非常好用的命令,功能也非常丰富,如果你对命令行工具熟悉,可以非常高效率完成维护工具.本文主要介绍Linux系统中,用于查看文件大小的命令. Linux 查看文件大小5个常 ...
- 面试题:Nginx负载均衡的算法怎么实现的?为什么要做动静分离?
面试题 Nginx负载均衡的算法怎么实现的?Nginx 有哪些负载均衡策略?Nginx为什么要做动静分离? 面试官心理剖析 主要是看应聘人员对Nginx的基本原理是否熟悉,需要应聘人员能够根据实际业务 ...
- Linux操作系统(四)_部署MySQL
一.部署过程 1.当前服务器的内核版本和发行版本 cat /etc/issue uname -a 2.检查系统有没有自带mysql,并卸载自带版本 yum list installed | grep ...
- Hibernate入门教程(二):Hibernate核心API
1.Configuraction onfiguration configuration = new Configuration(); configuration.configure(); 到src下面 ...
- Linux GNU GAS introduction
Linux汇编语法简介(GNU GAS) 声明:本教程不是介绍汇编语言和CPU指令的书籍,只是对gas的用法做一简单介绍.市面上所有讲汇编的书都是在微软的环境下,使用的是Intel的语法格式, ...
- Java7中的try-with-resources
首先,我们看下面的代码. BufferedReader br = null; try { br = new BufferedReader(new FileReader("test.txt&q ...
- ORM:Chloe
ORM的一种:Chloe注意实体类模板特色:多表连接 利用chloe实现对各表的增删查改的管理,判断现有物料是否能够支持生产规模. 一开始报错: IQuery<ProductionPlans&g ...
- System.Net.Mail.SmtpException:不允许使用邮箱名称.
使用SmtpClient发送邮件的时候,出现了如题错误. 解决方案: 将 SmtpClient.UseDefaultCredentials 属性设置为 true . 官方文档说明: Some SM ...
- Redis 设置权限密码,以及如何开启关闭设置
linux redis 设置密码: 在服务器上,这里以linux服务器为例,为redis配置密码. 1.第一种方式 (当前这种linux配置redis密码的方法是一种临时的,如果redis重启之后 ...