# bzoj4152[AMPPZ2014]The Captain 最短路

## 4152: [AMPPZ2014]The Captain

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 1517  Solved: 603
[Submit][Status][Discuss]

5
2 2
1 1
4 5
7 1
6 7

2

## Source

dijkstra可过

 1 #include<bits/stdc++.h>
2 #define ll long long
3 #define mp make_pair
4 #define N 200005
5 using namespace std;
6 typedef pair<ll,int>pii;
7 int n,tot,vis[N],hd[N],d[N];
8 struct P{int x,y,id;}a[N];
9 struct edge{int v,w,next;}e[N*10];
10 bool cmp1(P a,P b){return a.x<b.x;}
11 bool cmp2(P a,P b){return a.y<b.y;}
12 void add(int u,int v,int w){
13     e[++tot].v=v;
14     e[tot].next=hd[u];
15     e[tot].w=w;
16     hd[u]=tot;
17 }
19 priority_queue<pii,vector<pii>,greater<pii> >q;
20 void dijkstra(){
21     for(int i=1;i<=n;i++)d[i]=1<<30;
22     d[1]=0;q.push(mp(0,1));
23     while(!q.empty()){
24         pii x=q.top();q.pop();
25         int u=x.second;
26         if(vis[u])continue;vis[u]=1;
27         for(int i=hd[u];i;i=e[i].next){
28             int v=e[i].v;
29             if(vis[v])continue;
30             if(d[v]>d[u]+e[i].w){
31                 d[v]=d[u]+e[i].w;
32                 q.push(mp(d[v],v));
33             }
34         }
35     }
36 }
37
38 int main(){
39     scanf("%d",&n);
40     for(int i=1;i<=n;a[i].id=i,i++)
41     scanf("%d%d",&a[i].x,&a[i].y);
42     sort(a+1,a+1+n,cmp1);
43     for(int i=1;i<n;i++)
50 }