# bzoj4152-[AMPPZ2014]The_Captain

5

2 2

1 1

4 5

7 1

6 7

2

## Solution

$x_i <= x_j <= x_k$, 发现 $d_{i,k} >= d_{i,j} + d_{j,k}$. $y$ 同理.

## Code

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define rep(i,l,r) for(register int i=(l);i<=(r);++i)
#define repdo(i,l,r) for(register int i=(l);i>=(r);--i)
#define il inline
typedef double db;
typedef long long ll;

//---------------------------------------
const int nsz=2e5+50;
const ll ninf=1e17;

int n;
struct tp{int p,x,y;}line[nsz];
bool cmp1(tp a,tp b){return a.x<b.x;}
bool cmp2(tp a,tp b){return a.y<b.y;}
int dis(int a,int b){return min(abs(line[a].x-line[b].x),abs(line[a].y-line[b].y));}

struct te{int t,v,pr;}edge[nsz*4];
int hd[nsz],pe=1;

ll mind[nsz],vi[nsz];
struct tnd{ll v,d;};
bool operator<(tnd a,tnd b){return a.d>b.d;}
void dij(int f){
priority_queue<tnd> pq;
rep(i,1,n)mind[i]=ninf,vi[i]=0;
mind[f]=0,pq.push((tnd){f,0});
int u,d2;
while(!pq.empty()){
u=pq.top().v;pq.pop();
if(vi[u])continue;
vi[u]=1;
for(int i=hd[u],v;i;i=edge[i].pr){
v=edge[i].t,d2=mind[u]+edge[i].v;
if(mind[v]>d2){
mind[v]=d2;
pq.push((tnd){v,mind[v]});
}
}
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>n;
rep(i,1,n)cin>>line[i].x>>line[i].y,line[i].p=i;
sort(line+1,line+n+1,cmp1);