当前位置: 首页 > news >正文

多维最短路

D-最短?路径_牛客小白月赛102 (nowcoder.com)

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6;
struct node {int x;int y;int z;bool operator>(const node& other) const {return x> other.x;}
};
signed main()
{ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);int t;cin>>t;while(t--){int n,m,k;cin>>n>>m>>k;vector<int> a(n+5);vector<vector<int>> g(n+5);for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=m;i++){int u,v;cin>>u>>v;g[u].push_back(v);g[v].push_back(u);}priority_queue<node,vector<node>,greater<node>>q; vector<vector<int>> vis(n+5,vector<int>(k+5));vector<vector<int>> ans(n+5,vector<int>(k+5,1e18));if(k!=0){q.push({1,1,1});ans[1][1]=1;}q.push({a[1],1,0});ans[1][0]=a[1];while(!q.empty()){node xx=q.top();int cost=xx.x;int now=xx.y;int cnt=xx.z;q.pop();if(vis[now][cnt])continue;vis[now][cnt]=1;for(auto it:g[now]){if(ans[it][0]>cost+a[it]){ans[it][0]=cost+a[it];q.push({cost+a[it],it,0});}if(cnt+1<=k&&ans[it][cnt+1]>cost+1)	{ans[it][cnt+1]=cost+1;q.push({cost+1,it,cnt+1});}}}int minans=1e18;for(int i=0;i<=k;i++)minans=min(minans,ans[n][i]);cout<<minans<<'\n';		}}

http://www.lryc.cn/news/459600.html

相关文章:

  • 设计模式03-装饰模式(Java)
  • TiDB 监控组件之 Blackbox_exporter 运行原理
  • Java之网络编程详解
  • 苍穹外卖学习笔记(二十)
  • 2024 第一次周赛
  • 【数据脱敏方案】不使用 AOP + 注解,使用 SpringBoot+YAML 实现
  • dbt doc 生成文档命令示例应用
  • 【Windows】【DevOps】Windows Server 2022 安装ansible,基于powershell实现远程自动化运维部署 入门到放弃!
  • 深入理解 Parquet 文件格式
  • 计算机挑战赛3
  • 深度学习:循环神经网络—RNN的原理
  • 蓝桥杯刷题--幸运数字
  • Node.js入门——fs、path模块、URL端口号、模块化导入导出、包、npm软件包管理器
  • 多元线性回归:机器学习中的经典模型探讨
  • 域1:安全与风险管理 第1章实现安全治理的原则和策略
  • 【大数据】学习大数据开发应该从哪些技术栈开始学习?
  • CentOS快速配置网络Docker快速部署
  • Grounded-SAM Demo部署搭建
  • C语言 | 第十六章 | 共用体 家庭收支软件-1
  • 【论文阅读】Learning a Few-shot Embedding Model with Contrastive Learning
  • OKHTTP 如何处理请求超时和重连机制
  • 基于Springboot vue的流浪狗领养管理系统设计与实现
  • 爬虫案例——网易新闻数据的爬取
  • SpringCloud 2023 Gateway的Filter配置介绍、类型、内置过滤器、自定义全局和单一内置过滤器
  • 从银幕到现实:擎天柱机器人即将改变我们的生活
  • 408算法题leetcode--第33天
  • OCR模型调研及详细安装
  • C++第六讲:STL--vector的使用及模拟实现
  • 2024年字节抖音前端面经,这次问的很基础!
  • vscode提交修改Failed to connect to github.com port 443: Timed out