zoukankan      html  css  js  c++  java
  • 巨水的题目

    //  今天翻了翻以前收藏的东西,居然发现

    :  spfa  用map  写的 ,好吧,stl  我一无所知。

    题目:hdu  2544   太熟悉了吧

    #include<stdio.h>
    #include <map>
    #include <queue>
    #define N 101
    using namespace std;
    
    map<int,int>  head[N];// head[u][v]=w
    int  spfa(int st,int n)  //start
    {
        int i,u,v,w;
        int vis[N],d[N];
        for (i=1;i<=n;i++)
        {vis[i]=0;d[i]=0x7ffffff;}
        vis[st]=1; d[st]=0;
    
        queue<int> q; q.push(st);
        while(!q.empty())
        {
            u=q.front();
            vis[u]=0; q.pop();
            for (map<int,int>::iterator it=head[u].begin();it!=head[u].end();it++)
            {
                v=it->first;  w=it->second;
                if (d[u]+w<d[v])
                {
                    d[v]=d[u]+w;
                    q.push(v);vis[v]=1;
                }
            }
        }
        return d[n];
    }
    int main()
    {
        int n,m;
    
    
        while(scanf("%d%d",&n,&m),n+m)
        {
            int i,u,v,w;
            for (i=0;i<m;i++)
            {
                scanf("%d%d%d",&u,&v,&w);
                head[u][v]=head[v][u]=w;
            }
            printf("%d\n", spfa(1,n));
            for (i=0;i<n;i++)  head[i].clear();
        }
        return 0;
    }
    Just a little, maybe change the world
  • 相关阅读:
    chrome webkitappearance
    图片占用内存
    javascript性能优化repaint和reflow
    vim 系统剪切板
    CSS选择符的命名(转载)
    relative 内部 margin
    中国软件企业
    dom元素排序
    shell
    tips for asm
  • 原文地址:https://www.cnblogs.com/skyming/p/2479608.html
Copyright © 2011-2022 走看看