CF938D Buy a Ticket[建图+最短路]

这是一道关于计算从每个城市出发,考虑到音乐会门票价格,以最小费用参加音乐会并返回原城市的题目。通过构建图并应用最短路算法解决,如Dijkstra或Bellman-Ford,计算每个城市的最小花费总和。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D Buy a Ticket
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Musicians of a popular band “Flayer” have announced that they are going to “make their exit” with a world tour. Of course, they will visit Berland as well.

There are n cities in Berland. People can travel between cities using two-directional train routes; there are exactly m routes, i-th route can be used to go from city vi to city ui (and from ui to vi), and it costs wi coins to use this route.

Each city will be visited by “Flayer”, and the cost of the concert ticket in i-th city is ai coins.

You have friends in every city of Berland, and they, knowing about your programming skills, asked you to calculate the minimum possible number of coins they have to pay to visit the concert. For every city i you have to compute the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

Formally, for every you have to calculate , where d(i, j) is the minimum number of coins you have to spend to travel from city i to city j. If there is no way to reach city j from city i, then we consider d(i, j) to be infinitely large.

Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105).

Then m lines follow, i-th contains three integers vi, ui and wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 1 ≤ wi ≤ 1012) denoting i-th train route. There are no multiple train routes connecting the same pair of cities, that is, for each (v, u) neither extra (v, u) nor (u, v) present in input.

The next line contains n integers a1, a2, … ak (1 ≤ ai ≤ 1012) — price to attend the concert in i-th city.

Output
Print n integers. i-th of them must be equal to the minimum number of coins a person from city i has to spend to travel to some city j (or possibly stay in city i), attend a concert there, and return to city i (if j ≠ i).

Examples
inputCopy
4 2
1 2 4
2 3 7
6 20 1 25
outputCopy
6 14 1 25
inputCopy
3 3
1 2 1
2 3 1
1 3 1
30 10 20
outputCopy
12 10 12

题意:给一个有n个顶点m条无向边的图,顶点有权值ai,边也有权值wi,求每个顶点i的min(2d(i,j)+aj),其中d(i,j)为最短路径长度,其中i可以和j相同。

题解:好久没写过图相关的题了,先来个水题做康复训练。
定义ans[i]为i点的答案,那么ans[i]=min(ans[j]+2*w(i,j)),这种形式的图上dp显然可以用最短路转移。因为i和j可以相同,所以可以初始化答案数组ans[i]=a[i],将所有的点都丢进优先队列里(因为是多源嘛,也可以建立超级源点s,连向所有点,边权为ai),直接跑dij即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout<<#x<<" is "<<x<<endl;
const int maxn&
印刷电路板(PCB)作为电子元件的关键支撑体,在电子设备中扮演着不可或缺的角色,其市场发展态势备受关注。QYResearch 的调研数据为我们揭示了该市场的全景:2024 年,全球印刷电路板市场规模约达 782.9 亿美元,而展望 2031 年,这一数字有望攀升至 1012.7 亿美元,在 2025 - 2031 期间,年复合增长率(CAGR)预计保持在 3.8%。然而,当前美国 2025 年关税框架的潜在变动,已然在全球市场掀起波澜,对印刷电路板市场的竞争格局、区域经济协同以及供应链体系产生着深远影响。 一、印刷电路板基础概述 印刷电路板,又被称作印制电路板或印刷线路板,常见英文缩写为 PCB(Printed circuit board)或 PWB(Printed wire board)。其内部存在金属导体,承担着连接电子元器件线路的重任。传统电路板主要运用印刷蚀刻阻剂的工艺,以此构电路的线路与面,这也是其名称的由来。在现代电子技术领域,PCB 通过电子印刷术制造而成,它成功搭起电子元器件之间的电气连接桥梁,成为各类电子设备的核心组件。无论是体积小巧的智能穿戴设备,还是大型的服务器系统,只要其中配备集成电路等电子元件,PCB 必然 “参与其中”。 二、市场规模增长引擎 (一)中国主导地位凸显 中国在全球印刷电路板市场中占据着举足轻重的地位。据预测,2025 年中国市场规模有望达到 4333.21 亿元,在全球市场的占比将超过 50%。这一卓越成绩的背后,人工智能(AI)与新能源汽车产业功不可没,二者已成为驱动中国 PCB 市场增长的核心动力。以 AI 产业为例,随着 AI 技术的迅猛发展,对算力的需求呈爆发式增长,这使得 AI 服务器的市场需求大幅提升。而每台 AI 服务器中 PCB 的价值量可达 5000 元,预计到 2025 年,全球 AI 服务器相关的 PC
资源下载链接为: https://pan.quark.cn/s/637cf229ceb0 “official_web_copy_redbook” 是一个以小红书官网首页为蓝本,运用多种前端技术搭而成的示例项目。开发者运用了 Bootstrap、jQuery、HTML5、CSS 以及 JavaScript 等一系列技术栈来完成页面制作。以下是对这些技术及其在项目中应用的详细阐述。 HTML5 作为超文本标记语言的新版本,为网页开发带来了诸多新元素和功能,其核心目标是提升网页的可读性、可访问性与互动性。在本项目中,HTML5 承担着构网页基本架构的重任,它通过定义头部、导航、主体、底部等不同内容区块,清晰地划分页面结构。新出现的 <nav>、<section>、<article> 等元素,赋予了页面更强的语义化特性,这不仅有利于搜索引擎进行优化处理,也为无障碍访问提供了有力支持。 CSS(层叠样式表)主要负责掌控网页的外观与布局。在该项目里,CSS 被充分运用于定制小红书首页的视觉风格,涵盖颜色搭配、字体选择、间距设置以及整体布局等多个方面。借助 CSS,开发者能够实现响应式设计,确保页面在不同设备和各种屏幕尺寸下都能呈现出良好的显示效果。而 CSS3 的出现,更是引入了动画和过渡效果,这些效果或许被用于增强用户体验,例如制作按钮悬停时的特效、页面滚动时的动画等。 Bootstrap 是一款广受欢迎的开源前端框架,它集成了预设的 CSS 样式、JavaScript 组件以及网格系统,极大地提高了网页开发的效率。在仿小红书首页项目中,Bootstrap 很可能被用来快速搭响应式布局,简化栅格设计流程,并提供诸如模态框、下拉菜单、按钮等交互元素。其包含的 CSS 和 JavaScript 库,能够助力开发者维持设计的一致性与专业性。 jQuery 是一个轻量级的 JavaS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值