题目描述

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条边的无向图,求从s到t权值最小的路径(可飞跃一次,直接到t点不算权值)
解题思路:
最短路问题,因为可条跳跃一次(不算权值),并且可以有多个跳跃点,但只允许跳跃一次,所以在结构体重加一个变量(ope)来判断当前路径有没有跳跃过。
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
const int maxn = 50000+2;
typedef long long ll;
using namespace std;struct Cnode{int k;ll w;bool op;
};
bool operator<(const Cnode &d1,const Cnode &d2){return d1.w>d2.w;
}
priority_queue<Cnode> pq;
bool visit[maxn];
vector<vector<Cnode> >v;
int a,b,c;
Cnode p;int main()
{int n,m,f,s,t;cin>>n>>m>>f>>s>>t;v.clear();v.resize(n+1);memset(visit,0,sizeof(visit));for(int i = 1;i<=m;i++){cin>>a>>b>>c;p.k = b;p.w  = c;p.op = 0;v[a].push_back(p);p.k = a;p.w = c;p.op = 0;v[b].push_back(p);}for(int i = 1;i<=f;i++){cin>>a>>b;p.k = b;p.w = 0;p.op = 0;v[a].push_back(p);}p.k = s;p.w = 0;p.op = 0;pq.push(p);while(!pq.empty()){p = pq.top();pq.pop();if(visit[p.k])continue;visit[p.k] = true;if(p.k == t)break;for(int i = 0; i< v[p.k].size();i++){Cnode q;if(p.op == 1&&v[p.k][i].w == 0) //当前为跳跃点并且该路径已经跳跃过continue;q.k = v[p.k][i].k;if(visit[q.k])continue;if(v[p.k][i].w == 0||p.op == 1)//在此次操作前已经跳跃过,或者此次进行跳跃操作则更新为1q.op = 1;elseq.op = 0;q.w = p.w+v[p.k][i].w; pq.push(q);}}printf("%lld",p.w);return 0;
}
 

Bumped!(dijskra)相关推荐

  1. Dijskra迪杰斯特拉算法

    图 输出最短的路径,这里以源点0=>6进行说明,dist[6]=16,即该路最短路径长度为16.path[6]=4,path[4]=5,path[5]=2,path[2]=1,path[1]=0 ...

  2. 【算法设计与分析】Dijskra算法代码:Java版

    import java.util.Arrays;public class DijkstraAlgorithm {public static void main(String[] args) {char ...

  3. 真好用-dijskra最短路

    #include<cstdio> #include<cstring> #include<vector> #include<queue> using na ...

  4. 题目 1708: 数据结构-Dijskra(迪杰斯特拉)最短路径算法

    参考<大话数据结构> 题目描述 在带权有向图G中,给定一个源点v,求从v到G中的其余各顶点的最短路径问题,叫做单源点的最短路径问题. 在常用的单源点最短路径算法中,迪杰斯特拉算法是最为常用 ...

  5. P4568 [JLOI2011]飞行路线

    P4568 [JLOI2011]飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1 ...

  6. html中引入ifrim视频,Making Of Rallypoint - Outer Rim

    269762fc6c25c4d01d7292abffc3360a.jpg (326.74 KB, 下载次数: 28) 2012-9-30 15:37 上传 Fig.02 Whilst creating ...

  7. SOJ 4543 4542

    http://acm.scu.edu.cn/soj/problem.action?id=4542 递归用数组保存中间值 #include <cstdio> #include <cma ...

  8. 原理解释|直觉与实现:Batch Normalization

    https://www.toutiao.com/a6707566287964340747/ 作者:Harrison Jansma编译:ronghuaiyang 在本文中,我会回顾一下batch nor ...

  9. Object C语法学习

    1.OC关键字 synthesize关键字: 根据@property设置,自动生成成员变量相应的存取方法,从而可以使用点操作符来方便的存取该成员变量 . @implementation 关键字: 表明 ...

  10. copy, retain, assign , readonly , readwrite,strong,weak,nonatomic整理

    copy:建立一个索引计数为1的对象,然后释放旧对象 对NSString 对NSString 它指出,在赋值时使用传入值的一份拷贝.拷贝工作由copy方法执行,此属性只对那些实行了NSCopying协 ...

最新文章

  1. 深入理解CSS计数器
  2. VC++ 下使用QT初步入门学习
  3. mysql 5.5 替换字符_Mysql 5.7替换表中某些字段的字符串
  4. 从SpringBootApplication注解入手
  5. ICEM(1)—边界结构网格绘制
  6. linux多进程 段错误,关于段错误
  7. 论文浅尝 - ACL2020 | 用于回答知识库中的多跳复杂问题的查询图生成方法
  8. qt自定义窗口添加父窗口后,显示不出来
  9. memcache入门
  10. python 类命名空间,关于python:命名空间和类
  11. Clojure 学习入门(16)- 正则表达式
  12. linux网络子系统分析(三)—— 设备无关层
  13. PC串行接口串口定义
  14. Snort IPS入侵防御系统模式
  15. Redis数据结构之字符串对象
  16. GoPro内存卡里的THM、LRV文件
  17. c语言考试题型分数,强校-2018年计算机等级考试各科考试题型和分值
  18. MySQL入门笔记整理
  19. 2022山东省安全员C证复训题库模拟考试平台操作
  20. 3、管理员添加内容的实现

热门文章

  1. C++高并发服务器设计--共享内存封装(六)
  2. 精密测量仪器的气源维护知识
  3. c 循序结构程序设计
  4. DNS解析常见问题:如何清理DNS缓存?
  5. python画图网格线设置_python – Matplotlib:更改单个网格线的颜色
  6. 计算机思维培训心得,计算机教师培训心得体会
  7. 迅捷pdf转换器如何转换成word文档
  8. 软件测试好学吗?发展前景如何?
  9. Android push到/system/app下,导致找不到so文件,抛出java.lang.UnsatisfiedLinkError的原因分析和解决方案
  10. javaFX学习笔记之 管理Web弹出式窗口