# 【bzoj4152】【The Captain】最短路（堆优化）（浅尝ACM-B）

Description

Input

Output

Sample Input

5

2 2

1 1

4 5

7 1

6 7
Sample Output

2

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;

const int N=200000+5;

int n;
struct Node{
int num,x,y;
}a[N];
ll dist[N];bool vis[N],con[N];

hh++;
end[hh]=b;
dis[hh]=di;
}
/*struct cmp{
bool operator()(int a,int b){
return dist[a]>dist[b];
}
};*/
bool cmp1(Node a,Node b){
return a.x<b.x;
}
bool cmp2(Node a,Node b){
return a.y<b.y;
}
int abs(int a){
return a<0?-a:a;
}
/*写wa了的dijkstra
ll dijkstra(int st,int en){
priority_queue<int,vector<int>,cmp> q;
memset(dist,0x3f,sizeof(dist));
dist[st]=0;
vis[st]=1;
con[st]=1;
q.push(st);
while(!q.empty()){
int u=q.top();q.pop();
con[u]=1;
if(u==en) break;
int v=end[i],di=dis[i];//printf("%d ",v);
if(con[v]==1) continue;
if(dist[u]+(ll)di<dist[v]){
dist[v]=dist[u]+(ll)di;
if(!vis[v]){
q.push(v);
vis[v]=1;
}
}
}
}
return dist[en];
}*/
ll spfa(int st,int en){
memset(dist,0x3f,sizeof(dist));
memset(vis,0,sizeof(vis));
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > > q;//优先队列（堆）
q.push(make_pair(0,st));
vis[st]=1;
dist[st]=0;
while(!q.empty()){
int u=q.top().second;
q.pop();//q是优先队列，后pop可能就不是u了
vis[u]=0;//还可能会被更新
int v=end[i],di=dis[i];
if(dist[v]>dist[u]+di){
dist[v]=dist[u]+di;
if(!vis[v]){
q.push(make_pair(dist[v],v));
vis[v]=1;
}
}
}
}
return dist[en];
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
a[i].num=i;
}
sort(a+1,a+n+1,cmp1);
for(int i=1;i<=n;i++){
}