# BZOJ 4152: [AMPPZ2014]The Captain(最短路)

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 1550  Solved: 619
[Submit][Status][Discuss]

5
2 2
1 1
4 5
7 1
6 7

2

## Source

#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#define Pair pair<int,int>
#define F first
#define S second
#define int long long
const int MAXN=1e6+10;
using namespace std;
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int N;
struct node
{
int id,x,y;
}Point[MAXN];
int comp(const node &a,const node &b){return a.x<b.x;}
int comp2(const node &a,const node &b){return a.y<b.y;}
int dis[MAXN],vis[MAXN];
struct E
{
int u,v,w,nxt;
}edge[MAXN];
inline void AddEdge(int x,int y,int z)
{
}
void Dijstra()
{
memset(dis,0xf,sizeof(dis));dis[1]=0;
priority_queue<Pair>q;
q.push(make_pair(0,1));
while(q.size()!=0)
{
while(vis[q.top().S]&&q.size()>0) q.pop();
Pair p=q.top();
vis[p.S]=1;
if(dis[edge[i].v]>dis[p.S]+edge[i].w)
dis[edge[i].v]=dis[p.S]+edge[i].w,
q.push(make_pair(-dis[edge[i].v],edge[i].v));
}
printf("%lld",dis[N]);
}
main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
for(int i=1;i<=N;i++)
sort(Point+1,Point+N+1,comp);
for(int i=1;i<=N-1;i++)
sort(Point+1,Point+N+1,comp2);
for(int i=1;i<=N-1;i++)
Dijstra();
return 0;
}

posted @ 2018-02-26 16:55  自为风月马前卒  阅读(310)  评论(0编辑  收藏  举报