# BZOJ-4152-最短路

## 4152: [AMPPZ2014]The Captain

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 704  Solved: 269
[Submit][Status][Discuss]

5
2 2
1 1
4 5
7 1
6 7

## Sample Output

2

AC代码：

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;

const int maxn = 2e5+100;
const int Inf = 0x7fffffff;
int n,e;

int hed[maxn<<1],dis[maxn];

struct P{
int x,y,id;
}Poin[maxn];

struct L{
int u,v,w,nex;
}Lin[maxn<<2];

struct Nod{
int x,dis;
bool operator < (const Nod &a)const{
return a.dis<dis;
}
};

bool cmp1(P a,P b){return a.x<b.x;}

bool cmp2(P a, P b){return a.y<b.y;}

Lin[e].u=u,Lin[e].v=v,Lin[e].w=w,Lin[e].nex =hed[u],hed[u]=e++;
Lin[e].u=v,Lin[e].v=u,Lin[e].w=w,Lin[e].nex =hed[v],hed[v]=e++;
}

void Dij(){
for(int i=1;i<=n;i++)
dis[i]=Inf;
dis[1]=0;
Nod a={1,0};
priority_queue<Nod>q;
q.push(a);
while(!q.empty()){
a=q.top();
q.pop();
int now = a.x;
for(int i=hed[now];~i;i=Lin[i].nex){
Nod b;
int v=Lin[i].v;
if(dis[v]>dis[now]+Lin[i].w){
dis[v]=dis[now]+Lin[i].w;
b.x=v;
b.dis=dis[v];
q.push(b);
}
}
}
}
int main()
{
cin>>n;
e=0;
memset(hed,-1,sizeof(hed));
for(int i=0;i<n;i++){
scanf("%d%d",&Poin[i].x,&Poin[i].y);
Poin[i].id=i+1;
}
sort(Poin,Poin+n,cmp1);
for(int i=0;i<n-1;i++)
}