当前位置:网站首页>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;
}
边栏推荐
- R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置add参数在小提琴内部添加抖动数据点以及均值标准差竖线(jitter and mean_sd)
- Eureka registration center opens password authentication - record
- Visualize the training process using tensorboard
- aaaaaaaaaaA heH heH nuN
- 【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
- R语言使用wilcox.test函数执行wilcox符号秩检验获取总体中位数(median)的置信区间(默认输出结果包括95%置信水平的置信区间)
- 防范SYN洪泛攻击的方法 -- SYN cookie
- A method to prevent SYN flooding attacks -- syn cookies
- Heterogeneous graph neural network for recommendation system problems (ackrec, hfgn)
- R language uses the ggarrange function of ggpubr package to combine multiple images, and uses the ggexport function to save the visual images in JPEG format (width parameter specifies width, height pa
猜你喜欢

利用wireshark对TCP抓包分析

客户端开放下载, 欢迎尝鲜

Multi label image classification

Unexpected rollback exception analysis and transaction propagation strategy for nested transactions

容错机制记录

【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020

防范SYN洪泛攻击的方法 -- SYN cookie

【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)

Introduction to the scratch crawler framework

Go garbage collector Guide
随机推荐
防范SYN洪泛攻击的方法 -- SYN cookie
Zero shot image retrieval (zero sample cross modal retrieval)
R语言ggplot2可视化:可视化散点图并为散点图中的部分数据点添加文本标签、使用ggrepel包的geom_text_repel函数避免数据点之间的标签互相重叠(为数据点标签添加线段、指定线段的角度
Unexpected rollback exception analysis and transaction propagation strategy for nested transactions
Numpy first acquaintance
【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021
【八】取色器的巧用
logstash
[micro service ~sentinel] sentinel degradation, current limiting, fusing
Multi label image classification
Intelligent information retrieval (overview of intelligent information retrieval)
MySQL exercise 2
【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)
Technical management essay
Mirror Grid
Hystrix使用
水博士2
MySQL练习二
Script set random user_ agent
WPF项目入门1-简单登录页面的设计和开发