# [BZOJ4152][AMPPZ2014]The Captain（堆优化dijkstra）

## 代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define LL long long
#define N 1000005

int n;
struct data{LL x,y;int id;}p[N];
int tot,point[N],nxt[N],v[N];LL c[N];
LL dis[N];bool vis[N];
priority_queue < pair<LL,int> > q;

int cmpx(data a,data b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
int cmpy(data a,data b){return a.y<b.y||(a.y==b.y&&a.x<b.x);}
LL Abs(LL x){return (x>0)?x:-x;}
LL calc(data a,data b){return min(Abs(a.x-b.x),Abs(a.y-b.y));}
{
//  printf("%d %d %lld\n",x,y,z);
++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; c[tot]=-z;
++tot; nxt[tot]=point[y]; point[y]=tot; v[tot]=x; c[tot]=-z;
}
void dijkstra(int s,int t)
{
memset(dis,128,sizeof(dis));
dis[s]=0;q.push(make_pair(0,s));
while (!q.empty())
{
pair<LL,int> now=q.top();q.pop();
int x=now.second;
if (vis[x]) continue;vis[x]=1;
for (int i=point[x];i;i=nxt[i])
if (dis[v[i]]<dis[x]+c[i])
{
dis[v[i]]=dis[x]+c[i];
q.push(make_pair(dis[v[i]],v[i]));
}
}
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;++i) scanf("%lld%lld",&p[i].x,&p[i].y),p[i].id=i;
sort(p+1,p+n+1,cmpx);
}