zoukankan      html  css  js  c++  java
  • 【POJ3159】Candies 裸的pqspfa模版题

    不多说了。就是裸的模版题。

    贴代码:

    <span style="font-family:KaiTi_GB2312;font-size:18px;">#include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define N 30500
    #define M 200000
    #define inf 0x3f3f3f3f
    using namespace std;
    struct KSD
    {
    	int v,len,next;
    }e[M];
    int head[N],cnt;
    void add(int u,int v,int len)
    {
    	cnt++;
    	e[cnt].v=v;
    	e[cnt].len=len;
    	e[cnt].next=head[u];
    	head[u]=cnt;
    }
    struct Lux
    {
    	int f,v;
    	bool operator < (const Lux &a)const
    	{return f>a.f;}
    	Lux(){}
    	Lux(int _f,int _v):f(_f),v(_v){}
    };
    int dist[N];
    bool in[N];
    int pqspfa(int s,int t)
    {
    	priority_queue<Lux>pq;
    	int i,u,v;
    	memset(dist,0x3f,sizeof(dist));
    	dist[s]=0;
    	in[s]=1;
    	pq.push(Lux(0,s));
    	while(!pq.empty())
    	{
    		Lux U=pq.top();pq.pop();
    		u=U.v;
    		in[u]=0;
    		for(i=head[u];i;i=e[i].next)
    		{
    			v=e[i].v;
    			if(dist[v]>dist[u]+e[i].len)
    			{
    				dist[v]=dist[u]+e[i].len;
    				if(!in[v])
    				{
    					in[v]=1;
    					pq.push(Lux(dist[v],v));
    				}
    			}
    		}
    	}
    	return dist[t];
    }
    int n,m;
    int main()
    {
    //	freopen("test.in","r",stdin);
    	int i,j,k;
    	int a,b,c;
    	scanf("%d%d",&n,&m);
    	for(i=1;i<=m;i++)
    	{
    		scanf("%d%d%d",&a,&b,&c);
    		add(a,b,c);
    	}
    	printf("%d
    ",pqspfa(1,n));
    	return 0;
    }
    </span>


  • 相关阅读:
    JAVA软件开发职责
    Redis主从复制配置
    VirtualBox安装Ubuntu教程
    分段锁——ConcurrentHashMap
    阻塞队列BlockingQueue用法
    阻塞队列--LinkedBlockingQueue
    MySQL百万级数据库优化方案
    获取主机的对外ip
    联通沃云开启80端口
    Nginx 正则匹配
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5086826.html
Copyright © 2011-2022 走看看