当前位置:网站首页>Luogu p6822 [pa2012]tax (shortest circuit + edge change point)
Luogu p6822 [pa2012]tax (shortest circuit + edge change point)
2022-06-25 08:02:00 【Mfy's little brother 1】
Luogu P6822 [PA2012]Tax( shortest path + Edge change point )
The question :
Give a n A little bit m Undirected graph of strip and edge , The cost of passing through a point is the larger value of the edge weight of the two sides entering and leaving the point , Seek the starting point 1 point-to-point n The minimum cost of . The cost of starting point is the edge weight of the edge leaving the starting point , The cost of the destination is the edge weight of the edge entering the destination .
Ideas :
Violence works wonders , Think of all the edges as points , if a->b,b>c, This connects the two sides as points , Finally, create a super source S, With 1 Connected points are connected , A weight of 0, Set up a super junction T, With n Connected points are connected . common m^2 side .
Consider optimizing :
1. For a point , We sort the edges from small to large
2. Enumerate every edge , If this side is connected 1 perhaps N, So we're from S To or from this side T, The weight is the weight of the edge
3. Connect an edge from the corresponding incoming edge to the edge , Edge weights are their weights
4. Enumerate each outgoing edge , From the side with the smaller weight to the side with the larger weight to the side with the difference between the two sides , The connecting weight from the one with larger weight to the one with smaller weight is 0 The edge of
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e6+5;
const int INF=0x3f3f3f;
typedef pair<ll,int>pii;
int n,m,k=1,k1=1,nex[maxn*2],head[maxn],to[maxn*2],ne[maxn*2];
int h[maxn],t[maxn*2],vis[maxn],p[maxn];
ll w[maxn*2],ww[maxn*2],dis[maxn];
void add(int x,int y,int z){
nex[++k]=head[x];
to[k]=y;
head[x]=k;
w[k]=z;
}
void pdd(int x,int y,int z){
ne[++k1]=h[x];
t[k1]=y;
h[x]=k1;
ww[k1]=z;
}
ll dij(){
priority_queue<pii,vector<pii>,greater<pii>>q;
for(int i=1;i<=maxn;i++)dis[i]=1e18;
dis[0]=0;
q.push({
0,0});
while(!q.empty()){
int x=q.top().second;
q.pop();
if(vis[x])continue;
vis[x]=1;
for(int i=h[x];i;i=ne[i]){
int y=t[i];
if(dis[y]>dis[x]+ww[i]){
dis[y]=dis[x]+ww[i];
q.push({
dis[y],y});
}
}
}
return dis[1];
}
bool cmp(int x,int y){
return w[x]<w[y];
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,x,y,z;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,z);
pdd(k,k^1,z),pdd(k^1,k,z);
}
for(int i=1;i<=n;i++){
int d=0;
for(int j=head[i];j;j=nex[j])p[++d]=j;
sort(p+1,p+d+1,cmp);
for(int j=1;j<=d;j++){
if(j!=1){
pdd(p[j-1],p[j],w[p[j]]-w[p[j-1]]);
pdd(p[j],p[j-1],0);
}
if(i==1)pdd(0,p[j],w[p[j]]);
else if(i==n)pdd(p[j]^1,1,w[p[j]]);
}
}
printf("%lld\n",dij());
}
边栏推荐
猜你喜欢
The fourth floor is originally the fourth floor. Let's have a look
基于STM32MP157调试MIPI-DSI屏幕
剑指offer刷题(简单等级)
CAN透传云网关CANIOT,CANDTU记录CAN报文远程收发CAN数据
一文了解 | 革兰氏阳性和阴性菌区别,致病差异,针对用药
Dietary intervention reduces cancer treatment-related symptoms and toxicity
Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
电子学:第014课——实验 15:防入侵报警器(第一部分)
Looking for b-end product manager after years? I almost ruined myself
Electronics: Lesson 011 - experiment 10: transistor switches
随机推荐
What are the problems with traditional IO? Why is zero copy introduced?
Atlas conference vulnerability analysis collection
【莫比乌斯反演】
新版USBCAN卡CAN分析仪的CAN&CANFD综合测试分析软件LKMaster主要功能介绍
Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
【论文学习】《VQMIVC》
年后求职找B端产品经理?差点把自己坑惨了......
静态网页服务器
PCB board design - automatic layout 2021-10-15
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity
电子学:第009课——实验 7:研究继电器
FM信号、调制信号和载波
唐老师讲运算放大器(第七讲)——运放的应用
使用Adobe Acrobat Pro调整PDF页面为统一大小
57. insert interval
【视频】ffplay 使用mjpeg格式播放usb摄像头
將數據導入到MATLAB
C#中如何调整图像大小
Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely