对偶图模板
灰鹤在此
·
·
个人记录
#include<bits/stdc++.h>
using namespace std;
using type=int;
const type inf=(1<<30);
const int MaxN=3e5+5,MaxM=2e7+5;
struct edge{
int next,to;
type val;
}e[MaxM<<1];
int head[MaxN],cnt;
inline void add(int x,int y,type val){
e[++cnt]={head[x],y,val};
head[x]=cnt;
}
type dis[MaxN];
struct Node{
int x;
type dis;
inline bool friend operator < (Node x,Node y){
return x.dis>y.dis;
}
};
priority_queue<Node>q;
inline int dijsktra(int s,int t){
q.push({s,0});
fill(dis,dis+MaxN,inf);
dis[s]=0;
while(!q.empty()){
auto [x,val]=q.top();
q.pop();
if(dis[x]<val){
continue;
}
for(int i=head[x];i;i=e[i].next){
int y=e[i].to;
if(dis[y]>dis[x]+e[i].val){
dis[y]=dis[x]+e[i].val;
q.push({y,dis[y]});
}
}
}
return dis[t];
}
int n,m,s,t;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
t=MaxN-1;
cout<<dijsktra(s,t)<<endl;
return 0;
}