uva11374 - Airport Express 最短路

我的GIT练习ONE Git 是一个分布式版本控制及源代码管理工具;Git 可以为你的项目保存若干快照,以此来对整个项目进行版本管理每一次的练习,都是对自身知识的巩固,以及对自身知识的一个测试。 阅读详情

In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airport-Express, theEconomy-Xpress and the Commercial-Xpress. They travel at different speeds, take different routes and have different costs.

Jason is going to the airport to meet his friend. He wants to take the Commercial-Xpress which is supposed to be faster, but he doesn't have enough money. Luckily he has a ticket for the Commercial-Xpress which can take him one station forward. If he used the ticket wisely, he might end up saving a lot of time. However, choosing the best time to use the ticket is not easy for him.

Jason now seeks your help. The routes of the two types of trains are given. Please write a program to find the best route to the destination. The program should also tell when the ticket should be used.

Input

The input consists of several test cases. Consecutive cases are separated by a blank line.

The first line of each case contains 3 integers, namely N,S and E (2 ≤ N ≤ 500, 1 ≤S, E ≤ N), which represent the number of stations, the starting point and where the airport is located respectively.

There is an integer M (1 ≤ M ≤ 1000) representing the number of connections between the stations of the Economy-Xpress. The nextM lines give the information of the routes of the Economy-Xpress. Each consists of three integersX, Y and Z (X,Y ≤ N, 1 ≤ Z ≤ 100). This meansX and Y are connected and it takesZ minutes to travel between these two stations.

The next line is another integer K (1 ≤ K ≤ 1000) representing the number of connections between the stations of the Commercial-Xpress. The nextK lines contain the information of the Commercial-Xpress in the same format as that of the Economy-Xpress.

All connections are bi-directional. You may assume that there is exactly one optimal route to the airport. There might be cases where you MUST use your ticket in order to reach the airport.

Output

For each case, you should first list the number of stations which Jason would visit in order. On the next line, output "TicketNot Used" if you decided NOT to use the ticket; otherwise, state the station where Jason should get on the train of Commercial-Xpress. Finally, print thetotal time for the journey on the last line. Consecutive sets of output must be separated by a blank line.

Sample Input

4 1 4
4
1 2 2
1 3 3
2 4 4
3 4 5
1
2 4 3

Sample Output

1 2 4
2
5

  M条经济线路,K条商业线路,从S到E最多选择一条商业线路,最短路是多少。

  很无语这个题其实算简单的,但是却写了挺久的。。一直WA,最后终于找到错了。。。

  求两遍最短路,一次到起点,一次到终点。f和g数组分别表示到起点和终点的最短路。对K条商业线路找f[u]+dist(u到v商业线路长度)+g[v]最小值就行了,dijkstra用优先队列和vector的话,复杂度是O(MlogN+K)。

  主要被坑在打印路径上。。注意前半段根据f倒着递归,后半段根据g正着递归。。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXN 510
#define MAXM 2000010
#define MAXNODE 105
#define MOD 100000
#define SIGMA_SIZE 4
typedef long long LL;
using namespace std;
int N,S,E,M,K,f[MAXN],g[MAXN];
struct Edge{
    int u,v,dist;
};
struct HeapNode{
    int u,d;
    bool operator < (const HeapNode& rhs) const{
        return d>rhs.d;
    }
};
struct Dijkstra{
    int n,m;
    vector<Edge> edges;
    vector<int> G[MAXN];
    bool done[MAXN];

    void init(int n){
        this->n=n;
        for(int i=0;i<n;i++) G[i].clear();
        edges.clear();
    }
    void add_edge(int u,int v,int dist){
        edges.push_back((Edge){u,v,dist});
        m=edges.size();
        G[u].push_back(m-1);
    }
    void dijkstra(int s,int* d){
        priority_queue<HeapNode> q;
        for(int i=0;i<n;i++) d[i]=INF;
        d[s]=0;
        memset(done,0,sizeof(done));
        q.push((HeapNode){s,0});
        while(!q.empty()){
            HeapNode x=q.top();
            q.pop();
            int u=x.u;
            if(done[u]) continue;
            done[u]=true;
            int L=G[u].size();
            for(int i=0;i<G[u].size();i++){
                Edge& e=edges[G[u][i]];
                if(d[e.v]>d[u]+e.dist){
                    d[e.v]=d[u]+e.dist;
                    q.push((HeapNode){e.v,d[e.v]});
                }
            }
        }
    }
}solver;
void print_road1(int u,int e){
    if(u==e){
        printf("%d",u);
        return;
    }
    else{
        int L=solver.G[u].size();
        for(int i=0;i<L;i++){
            Edge& edge=solver.edges[solver.G[u][i]];
            if(f[u]-edge.dist==f[edge.v]){
                print_road1(edge.v,e);
                printf(" %d",u);
                break;
            }
        }
    }
}
void print_road2(int u,int e){
    printf(" %d",u);
    if(u==e) return;
    else{
        int L=solver.G[u].size();
        for(int i=0;i<L;i++){
            Edge& edge=solver.edges[solver.G[u][i]];
            if(g[u]-edge.dist==g[edge.v]){
                print_road2(edge.v,e);
                break;
            }
        }
    }
}
int main(){
    freopen("in.txt","r",stdin);
    int cas=0;
    while(scanf("%d%d%d",&N,&S,&E)!=EOF){
        if(cas++) puts("");
        solver.init(N+1);
        scanf("%d",&M);
        int u,v,dist;
        while(M--){
            scanf("%d%d%d",&u,&v,&dist);
            solver.add_edge(u,v,dist);
            solver.add_edge(v,u,dist);
        }
        solver.dijkstra(S,f);
        solver.dijkstra(E,g);
        int ans=f[E],s=-1,e=-1;
        scanf("%d",&K);
        while(K--){
            scanf("%d%d%d",&u,&v,&dist);
            if(f[u]==INF||g[v]==INF) continue;
            if(f[u]+g[v]+dist<ans){
                ans=f[u]+g[v]+dist;
                s=u;
                e=v;
            }
            if(f[v]==INF||g[u]==INF) continue;
            if(f[v]+g[u]+dist<ans){
                ans=f[v]+g[u]+dist;
                s=v;
                e=u;
            }
        }
        if(s==-1) print_road1(E,S);
        else{
            print_road1(s,S);
            print_road2(e,E);
        }
        puts("");
        if(s==-1) printf("Ticket Not Used\n");
        else printf("%d\n",s);
        printf("%d\n",ans);
    }
    return 0;
}



YOLOv11的对比学习预训练改进-(通过SimCLR预训练增强特征提取) 本文介绍了将SimCLR对比学习预训练与YOLOv11目标检测模型相结合的创新方法。文章首先概述了目标检测领域的发展现状和YOLOv11的架构优化,包括主干网络、特征金字塔和检测头的改进设计。其次详细解析了SimCLR对比学习的核心原理,涵盖数据增强、投影头设计和NT-Xent损失函数。最后探讨了如何将对比学习与目标检测有效结合,通过特征空间对齐和渐进式微调策略提升模型性能。该方法显著增强了特征提取能力,提高了检测精度和训练效率,特别是在小目标和遮挡目标的检测上表现突出。 阅读详情

相关推荐

如何选择StandardScaler、MinMaxScaler和RobustScaler做标准化的对比解释和示例代码

选择合适的标准化方法取决于数据的特点和需求。如果数据分布接近正态分布且无异常值,可以使用。如果需要将数据映射到特定范围内并保持相对关系,可以使用。如果数据中存在异常值或离群点,可以使用进行鲁棒标准化。在分类、聚类算法中,需要使用距离来度量相似性的时候、或者使用PCA技术进行降维的时候,StandardScaler表现更好(避免不同量纲对方差、协方差计算的影响);在不涉及距离度量、协方差、数据不符合正态分布、异常值较少的时候,可使用MinMaxScaler。

qq_36001281的博客 4950

uva 11374 Airport Express (Dijkstra)

 题意:在Iokh市中,机场快线是市民从市内去机场的首选交通工具。机场快线分为经济线和商业线两种,线路,速度和价钱都不同。你有一张商业线车票,可以做一站商业线,而其他时候只能乘坐经济线。假设换乘时间忽略不计,你的任务是找一条去机场最快的路线。。 分析:枚举商业线T(a,b),则总时间为f(a)+T(a,b)+g(b);f和g用两次dijkstra来计算,以S为起点的dijkstra和以E为

GODSPEED 846

FPGA远程升级必备:STARTUPE2原语控制Flash的避坑指南

本文深入解析了FPGA远程升级中STARTUPE2原语的核心价值与配置策略,详细介绍了其在QSPI Flash接口设计中的应用。通过Vivado工具和原语控制,开发者可以高效实现安全可靠的远程固件升级,提升系统稳定性和升级效率。

k8l9m0n的博客 410

uva 11374 Airport Express(最短路)

uva 11374 Airport ExpressIn a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airport-Expre

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 2225

23.网工入门篇--------介绍一下园区网典型组网架构及案例实践

园区网典型组网架构主要分为小型、中型、大型三种类型,以下是详细介绍及相关案例实践:

qq_31450765的博客 970

OJ(while+cin.get()判断结束)

今天要记录一道看起来十分简单的OJ题目,但开始对于cin的一些操作忘得差不多了,没做出来,故记下来给自己提个醒。 描述 给出包含N个单词的一行输入,输出N行。第一行和输入一样。每次输出过一行后,这一行的第一个单词在下一行被放到最后。 输入 包含N个单词的字符串,单词以一个空格分开。N不在输入中给出,你需要计算单词的数量来获得。字符串包含的字符数小于100。 输出 输出N行。...

Stark_JC的博客 2366

Uva 11374 - Airport Express 最短路

Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains

Azarath Metrion Zinthos 1052

从零搭建一个虚拟ECU:手把手用Autosar CP模块模拟汽车灯控系统(基于Vector工具链)

本文详细介绍了如何使用Vector工具链从零搭建一个基于Autosar CP架构的虚拟ECU系统,模拟汽车灯光控制功能。通过环境搭建、模块配置、通信栈设置到灯光控制逻辑实现的全流程指导,帮助开发者掌握Autosar CP模块术语的实际应用,并提供了系统集成与测试的实用方案。

weixin_42628688的博客 320

生产级机器学习服务构建:从模型API到可观测、可熔断的数字工人

机器学习模型部署不是简单封装为HTTP接口,而是构建具备可靠性、可观测性、弹性扩缩与安全防护能力的生产级服务。其核心在于将模型转化为可监控、可诊断、可自愈的服务实体,关键技术包括服务网格化治理(如Istio)、GPU推理优化(如NVIDIA Triton)、动态批处理与指标驱动的自动扩缩容(HPA)。尤其在高并发、低延迟场景下,熔断机制与健康检查协同可防止雪崩,而特征漂移(PSI)等前置指标比准确率下降更早预警模型退化。本文聚焦于Kubernetes环境下,以Triton+Istio+Sidecar为技术栈

weixin_30691871的博客 410

Shopee 虾皮API接口:商品详情采集的实践

随着电商行业的蓬勃发展,数据采集和分析在商业决策中扮演着越来越重要的角色。Shopee作为东南亚领先的电商平台,拥有大量的商品数据。通过Shopee的API接口,我们可以方便地获取商品详情,为数据分析和市场研究提供有力支持。本文将介绍如何使用Shopee API接口采集商品详情,并分享一些实践技巧。提供了丰富的数据接口,包括商品详情、店铺信息、订单数据等。通过API接口,开发者可以轻松地获取Shopee平台上的数据,进行进一步的处理和分析。Shopee API接口:商品详情采集的实践与技巧。

An4480的博客 1902

最新Python爬虫实战(入门爬虫篇)——案例3:爬取二次元cos图片批量下载到本地(附上完整爬虫代码)

本次案例通过Python爬虫技术实现了二次元图片的批量下载。代码采用模块化设计,函数实现cookies的自动解析,简化了配置流程,涵盖“请求列表页→提取详情页URL→请求详情页→提取图片链接→保存图片”的完整流程,与豆瓣案例的核心逻辑和格式完全对齐。学习重点包括:抓包工具定位多层级数据源、正则表达式匹配复杂链接、模拟请求头绕过反爬机制、文件名安全处理及自动化文件管理。需要注意控制请求频率并遵守网站使用规范,适用于入门爬虫实践,帮助学习者掌握多层级页面爬取的核心逻辑。

努力让自己发光,对的人才能迎着光而来 14万+

uva 11374 - Airport Express(Dijkstra预处理+枚举)

Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of tra

勿忘初衷 3446

嵌入式STM32F407CET6移植OpenHarmony系统方法

文件末尾添加:export PATH=~/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH。编译完成文件输出在LiteOs源码目录下out/STM32F407_ATK_Explorer文件夹中。②点击connect to the target,下方会自动显示识别出来的芯片型号以及flash大小。⑤点击program verify并点击start,等待烧写并校验完成,你就能看到程序正在运行了。,在选择刚才我们说的Huawei_LiteOS.hex文件。

嵌入式技术开发 551

uva 11374 - Airport Express(最短路)

题目链接:uva 11374 - Airport Express #include #include #include #include #include using namespace std; typedef pair pii; const int maxn = 505; const int inf = 0x3f3f3f3f; struct Edge { int v

不慌不忙、不急不躁 702

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

UVA 11374 - Airport Express(最短路)

题目链接:点击打开链接 题意:某个人要从起点到终点, 有m个经济站和k个商业站, 只能乘坐一次商业站, 求最短时间。 思路:因为多了商业站, 所以不能直接套用最短路, 但是注意到只有一次乘坐商业站的机会, 所以直接枚举坐哪个商业站就行了, 这样,其他部分就是最短路了, 假设商业站是从a到b,花费c,那么答案就是d1[a] + d2[b] + c, d1是从起点的最短路,d2是从终点出发的最短路

AC_Arthur的专栏 2557

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

UVA - 11374——Airport Express (最短路)

题目链接:https://cn.vjudge.net/problem/UVA-11374 思路:找出起点到每个点的距离,再找出每个点到终点的距离,枚举商业线的两个点。 wa点:枚举商业线的时候不能只把前一个点当起点,后一个点当终点,路是双向的,两个点都有可以当作与起点相连的点。 #include<algorithm> #include<string.h> #incl...

creator平 221

UVA 11374 Airport Express(最短路)

最短路。 把题目抽象一下:已知一张图,边上的权值表示长度。现在又有一些边,只能从其中选一条加入原图,使起点->终点的距离最小。 当加上一条边a->b,如果这条边更新了最短路,那么起点st->终点ed的最小距离=st->a + a->b +b->ed 三个值的最短距离之和。于是正反求两次单元最短路。再将k条边遍历一遍就好了。 最近在改代码风格...

aizhengcuo9261的博客 198

UVA11374 Airport Express(SPFA求最短路)

城市里面有n个站点,一些站点之间通过双向边相连。现在在一些站点之间可能有快速路,可以减少通行的时间,但是你只能经过一次快速路。问到终点的最少时间,并输出方案。 思路还是很好想,输出就有点蛋疼了。设d1[i]表示起点到i的最短距离,d2[i]表示终点到i的最短距离。枚举每一条可能使用的快速路(a,b),用d1[a]+w(a,b)+d2[b]或d1[b]+w(a,b)+d2[a]去更新答案,最小的那

ACMer_quack&cheer 543

【uva11374】Airport Express 最短路

题意:   在Iokh市中,机场快线是市民从市内去机场的首选交通工具。机场快线分为经济线和商业线两种,线路,速度和价钱都不同。你有一张商业线车票,可以坐一站商业线,而其他时候只能乘坐经济线。假设换乘时间忽略不计,你的任务是找一条去机场最快的路线。 分析:   因为商业线只能走一次,我们就枚举走哪条商业线(或不走),用2次单源最短路分别求从起点和终点出发到所有路的最短路,最后比...

weixin_30417487的博客 161

UVA - 11374 Airport Express (最短路)

题目连接:https://vjudge.net/problem/UVA-11374 思路:最短路+记录路径 #include &lt;bits/stdc++.h&gt; using namespace std; const int MAXN = 550; const int MAXM = 550; const int INF = 0x3f3f3f3f; struct Edge{ int f...

GYH0730的博客 329

UVA-11374-Airport Express (最短路)

题目链接:UVA-11374-Airport Express题意是给定一个图。然后给定一些快速路径,你最多通过一次快速路径。求从起点到终点的最短距离。首先求出f[i]和g[i],即i点到起点和终点的最短路。 然后枚举所有的快速路径 (u,v)(u,v) ans=min(ans,min(f[u]+g[v]+cost,f[v]+g[u]+cost))ans=min(ans,min(f[u]+g[v

On the way 469

【UVa】11374 Airport Express 最短路

ProblemD: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airpor

poursoul 792

UVA 11374 Airport Express(最短路+枚举)

题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2369 题目大意:现在你要去机场,知道起点和终点,两种路线,商业型和经济型,商业型你只能乘一站,其他做经济型。给你m条经济型的边和k条商业型的边,并且最优解唯一。让你求出最优解的路线,打印出来,然后给

沉溺的专栏 1119

uva_11374_Airport Express(最短路+枚举)

题意:机场分为经济线和商业线两种。假设你现在有一张商业线的火车票,可以坐一站商业线,其他的时候只能坐经济线,现在你的任务是找一条去机场的最快的路线。

一点也不二 1453

Uva 11374 - Airport Express(枚举+最短路)

题目链接 https://vjudge.net/problem/UVA-11374 【题意】 市民从市区去机场要走机场快线,机场快线分为经济线和商业线两种,你只有一张商业线车票,只能坐一站商业线,其它时候只能坐经济线,忽略换乘时间,找到一条去机场最快的线路。 【思路】 大白书329页例题,可以先按照经济线建立无向图,用dijkstra算法分别求出以起点和以终点为源点的最短路,然后依次枚举...

Change the world by program. 501

UVA 11374 Airport Express (最短路)

  uva 11374 Airport Express   In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. There are two types of trains in Airp...

知与谁i的博客 470
上一篇: uva1391 - Astronauts 2-SAT
下一篇: hdu5033 Building 北京网络赛B题 单调栈
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值