当前位置:网站首页>2022河南萌新联赛第(三)场:河南大学 I - 旅行
2022河南萌新联赛第(三)场:河南大学 I - 旅行
2022-07-25 11:39:00 【WA_自动机】
I - 旅行
题意:从城市 1 到城市 n, 每隔一天多花费 w。
解法:将每个城市看成两个城市, 缴费的, 未缴费的, 然后让缴费于未缴费的城市建边, 跑最短路即可。
- 时间复杂度 O ( n × l o g ( n ) ) O(n × log(n)) O(n×log(n))
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,PII> PLII;
const int N = 100010;
vector<PII> g[N];
bool st[N][2];
LL d[N][2];
int n,m,x;
void dijkstra()
{
memset(d,0x3f,sizeof d);
priority_queue<PLII,vector<PLII>,greater<PLII> > Q;//Q.first -> d, Q.second.first -> didian, Q.second.second -> hesuan
d[1][0]=0;
Q.push({
0,{
1,0}});
while(!Q.empty())
{
auto t=Q.top();Q.pop();
int u=t.second.first,ok=t.second.second;
if(st[u][ok]) continue;
st[u][ok]=true;
for(auto &p:g[u])
{
int j=p.first,w=p.second;
if(ok==1 && d[j][0]>d[u][1]+w) // 0 -> 1
{
d[j][0]=d[u][1]+w;
Q.push({
d[j][0],{
j,0}});
}
if(ok==0 && d[j][1]>d[u][0]+w+x)// 1 -> 0, + x;
{
d[j][1]=d[u][0]+w+x;
Q.push({
d[j][1],{
j,1}});
}
}
}
}
int main()
{
cin>>n>>m>>x;
for(int i=1;i<=m;i++)
{
int u,v,w;cin>>u>>v>>w;
g[u].push_back({
v,w});
g[v].push_back({
u,w});
}
dijkstra();
cout<<min(d[n][0],d[n][1])<<endl;
return 0;
}
边栏推荐
猜你喜欢

Application of comparative learning (lcgnn, videomoco, graphcl, XMC GaN)

PyTorch可视化

Eureka registration center opens password authentication - record

Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor

WPF project introduction 1 - Design and development of simple login page

Learning to pre train graph neural networks

3.2.1 what is machine learning?

scrapy爬虫爬取动态网站
![[micro service ~sentinel] sentinel degradation, current limiting, fusing](/img/60/448c5f40af4c0937814c243bd7cb04.png)
[micro service ~sentinel] sentinel degradation, current limiting, fusing

技术管理杂谈
随机推荐
R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、使用step函数构建前向逐步回归模型筛选预测变量的最佳子集、scope参数指定候选预测变量
numpy初识
技术管理杂谈
投屏收费背后:爱奇艺季度盈利,优酷急了?
利用wireshark对TCP抓包分析
Word中的空白页,怎么也删不掉?如何操作?
Unexpected rollback exception analysis and transaction propagation strategy for nested transactions
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure function adds annotation, annotation and annotation information for the combined image, adds image labels fo
协程
Script set random user_ agent
Zuul网关使用
Those young people who left Netease
水博士2
WPF项目入门1-简单登录页面的设计和开发
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip chart, set the palette parameter to configure the color of data points at different levels,
PyTorch的生态简介
Pytorch project practice - fashionmnist fashion classification
【十】比例尺添加以及调整
Transformer variants (routing transformer, linformer, big bird)
pytorch环境配置及基础知识