当前位置:网站首页>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;
}
边栏推荐
- GPT plus money (OpenAI CLIP,DALL-E)
- 【三】DEM山体阴影效果
- Analysis of TCP packet capturing using Wireshark
- Fiddler抓包APP
- R语言组间均值是否相同的成对比较:使用pairwise.t.test函数执行多个分组数据均值的两两成对假设检验
- 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
- aaaaaaaaaaA heH heH nuN
- 氢能创业大赛 | 国家能源局科技司副司长刘亚芳:构建高质量创新体系是我国氢能产业发展的核心
- 防范SYN洪泛攻击的方法 -- SYN cookie
- Pytorch visualization
猜你喜欢

MySQL exercise 2

3.2.1 what is machine learning?

那些离开网易的年轻人

Unexpected rollback exception analysis and transaction propagation strategy for nested transactions

【黑马早报】运营23年,易趣网宣布关停;蔚来对大众CEO抛出橄榄枝;华为天才少年曾放弃360万年薪;尹烨回应饶毅炮轰其伪科学...

3.2.1 什么是机器学习?

After having a meal with trump, I wrote this article

【AI4Code】《CoSQA: 20,000+ Web Queries for Code Search and Question Answering》 ACL 2021

Transformer variants (spark transformer, longformer, switch transformer)

PyTorch可视化
随机推荐
R language ggplot2 visualization: visualize the scatter diagram, add text labels to some data points in the scatter diagram, and use geom of ggrep package_ text_ The repl function avoids overlapping l
那些离开网易的年轻人
【九】坐标格网添加以及调整
第一个scrapy爬虫
Ansible
Go garbage collector Guide
【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
Eureka注册中心开启密码认证-记录
R language uses LM function to build multiple linear regression model, step function to build forward stepwise regression model to screen the best subset of prediction variables, and scope parameter t
Scott+scott law firm plans to file a class action against Yuga labs, or will confirm whether NFT is a securities product
Script set random user_ agent
pytorch环境配置及基础知识
aaaaaaaaaaA heH heH nuN
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
【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
Analysis of TCP packet capturing using Wireshark
[micro service ~sentinel] sentinel degradation, current limiting, fusing
技术管理杂谈
Video caption (cross modal video summary / subtitle generation)