当前位置:网站首页>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());
}
边栏推荐
- Force deduction 76 questions, minimum covering string
- [deep learning lightweight backbone] 2022 edgevits CVPR
- 57. insert interval
- Neural network and deep learning-3-simple example of machine learning pytorch
- Functions should not specify operation types through variables
- C#中如何调整图像大小
- 現在通過開戶經理發的開戶鏈接股票開戶安全嗎?
- @The difference between resource and @autowired annotation, why recommend @resource?
- C#控件刷新
- c#磁盘驱动器及文件夹还有文件类的操作
猜你喜欢

Technology blog | how to communicate using SSE

Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries

Modular programming of LCD1602 LCD controlled by single chip microcomputer

Anaconda navigator启动慢的一个解决方法

Basic use of ActiveMQ in Message Oriented Middleware

电子学:第014课——实验 15:防入侵报警器(第一部分)

Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus

The fourth floor is originally the fourth floor. Let's have a look

c#磁盘驱动器及文件夹还有文件类的操作

Ubuntu18下登录mysql 5.7设置root密码
随机推荐
Opencv daily function structure analysis and shape descriptor (8) Fitline function fitting line
Can transparent cloud gateway caniot and candtu record can messages and send and receive can data remotely
时钟刻度盘的绘制
C examples of using colordialog to change text color and fontdialog to change text font
基于RBAC 的SAAS系统权限设计
Debugging mipi-dsi screen based on stm32mp157
Share the process requirements for single-layer flexible circuit board
C#控件刷新
Anaconda based module installation and precautions
环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用
Functions should not specify operation types through variables
50. pow (x, n) - fast power
@Resource和@Autowired注解的不同,为什么推荐@Resource?
Analysis and utilization of Microsoft Office Word remote command execution vulnerability (cve-2022-30190)
将数据导入到MATLAB
2021ICPC网络赛第一场
Buckle 78: subset
50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
bat启动.NET Core
MySQL interview - the response of executing SQL is relatively slow, and the troubleshooting ideas.