uva11374 - Airport Express 最短路

基于TF-IDF+KMeans聚类算法构建中文文本分类模型(附案例实战) TF-IDF(Term Frequency-Inverse Document Frequency, 词频-逆文件频率)是一种用于资讯检索与资讯探勘的常用加权技术。TF-IDF是一种统计方法,用以评估一字词对于一个文件集或一个语料库中的其中一份文件的重要程度。字词的重要性随着它在文件中出现的次数成正比增加,但同时会随着它在语料库中出现的频率成反比下降。简单来说就是:一个词语在一篇文章中出现次数越多, 同时在所有文档中出现次数越少, 越能够代表该文章。这也就是TF-IDF的含义。 阅读详情

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;
}



YOLOv5/v7/v8/v9/v10/v11/v12/13目标检测结果解析,超w字精读,IoU、GIoU、DIoU、CIoU、EIoU详细解释,精确率、召回率、AP、mAP与P-R 曲线图深度解析 阅读详情

相关推荐

ANSYS Workbench接触分析实战:从算法选择到收敛难题破解

本文深入解析ANSYS Workbench接触分析的核心技术与实战技巧,涵盖四大接触算法选择、收敛难题破解秘籍及典型场景参数设置。通过实际案例演示如何优化接触刚度、pinball区域和非对称行为等关键参数,帮助工程师有效解决结构非线性问题,提升仿真效率和精度。

weixin_28705087的博客 358

uva 11374 Airport Express (Dijkstra)

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

GODSPEED 846

内网环境下 OpenSSL 与 OpenSSH 安全升级实战指南:从 9.9p2 离线部署到回滚方案

本文详细介绍了内网环境下OpenSSL与OpenSSH的安全升级实战指南,重点涵盖从9.9p2版本离线部署到回滚方案的全流程。通过备份策略、动态库处理、权限修复等关键步骤,确保升级过程安全可靠,特别适合金融、政务等敏感行业的内网服务器安全加固。

weixin_30566063的博客 511

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

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

从零开始:ENSP与VirtualBox的兼容性迷宫与突围指南

本文深入解析eNSP与VirtualBox的兼容性问题,特别是报错40的解决方案。从诊断根源、彻底卸载残留到推荐黄金版本组合,提供了一套完整的实战指南,帮助网络工程师和技术学习者快速解决AR_Base等设备的启动故障,优化虚拟化环境性能。

weixin_29284885的博客 476

RH850从0搭建Autosar开发环境【3X】- Davinci Configurator之BswM模块配置详解(上)

RH850从0搭建Autosar开发环境【3X】- Davinci Configurator之BswM模块配置详解(上)

weixin_42412049的博客 736

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

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

weixin_30691871的博客 408

元学习与Transformer的结合:Meta-Transformer架构解析

我们生活在一个信息爆炸的时代,每天都会产生海量的数据。在深度学习领域,如何让模型更高效地学习、更快地适应新的任务,一直是科学家们努力的方向。元学习和Transformer都是深度学习中的重要概念,它们各自有着独特的优势。本文的目的就是深入剖析将元学习和Transformer结合起来的Meta - Transformer架构,探讨它的原理、应用以及未来发展。我们会从基础概念讲起,逐步深入到架构的各个方面,让大家对Meta - Transformer有一个全面的了解。

AI智能探索者的博客 1052

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 1051

【系统架构设计师】2026年上半年真题论文:论高并发系统的设计与实践

本文围绕高并发系统架构设计展开,重点论述了电商秒杀系统的实战经验。文章采用"痛点-解决方案-效果"的逻辑结构,从缓存设计、异步处理、限流降级、数据库优化等6个维度详细阐述了应对高并发的技术策略。其中,重点介绍了多级缓存体系、基于消息队列的异步处理机制和微服务拆分实践,并辅以实际案例说明如何解决超卖、缓存雪崩等典型问题。全文强调高并发设计需要系统性思维,通过空间换时间、异步换吞吐、横向换能力等原则,最终实现系统吞吐量从500TPS提升至20000TPS的性能突破。

数据知道的博客 1156

硬件工程师笔试面试高频考点汇总——(2025版)

《硬件工程师笔试面试知识汇总》一文系统梳理了硬件领域的核心知识体系,涵盖电子器件、模拟电路、数字电路等模块。文章详细解析了电阻、电容、电感等基础元件的选型与应用,深入探讨了三极管、MOS管等半导体器件的工作原理,并对比分析了DCDC与LDO等电源方案。在电路设计方面,提供了滤波器、放大器等实用电路的设计方法与仿真案例,同时包含UART、I2C等通信协议的实现要点。文章还整合了戴维宁定理等电路分析理论,并附有美团、联想等名企真题解析。通过器件特性、电路设计、企业真题三维度内容,为硬件工程师构建了完整的知识框架

XU157303764的博客 1万+

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

勿忘初衷 3445

国科大学习资料--图像处理(彭思龙、杨戈)--2020年期末考试题解析(学长整理分析)

在对20年卷子分析前,先看看19年卷子的解析(后面有20年的变化,由于从核心课调整到了普及课,20年的卷子相对简单,但是还是有很多细节) 解析:(字写的不好别嫌弃!!!!) 20年的卷子 第一题:和19年基本一致,但是加了高斯核计算费用,要算一个节省计算成本比率,所以去多看看PPT 第二题:和19年基本一致,加了证明两个高斯卷积仍然是高斯卷积,相当于19年题2和3结合 第三题:采样定理,和19年基本一致,但要注意加了证明 第四题:考了形态学提取图像边界 第五题:直方图,和19年一

无名何许人的博客 4364

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

不慌不忙、不急不躁 700

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

UVA 11374 - Airport Express(最短路)

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

AC_Arthur的专栏 2555

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

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

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

creator平 221

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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 791

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

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

沉溺的专栏 1118

uva_11374_Airport Express(最短路+枚举)

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

一点也不二 1452

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、付费专栏及课程。

余额充值