• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-72  評論-126  文章-0  trackbacks-0
            http://acm.hdu.edu.cn/showproblem.php?pid=2544

            #include<stdio.h>
            #define Max 1000001
            #include
            <string>
            struct Road{
                
            int dis;
                
            int to;
                
            struct Road * next;
            };
            Road map[
            1000001],*tail[1000001];
            struct Heap{
                
            int x,dis;
            }hh[
            1000001];
            bool hash[1000001];
            int n,m;
            int len;
            void PutHeap(Heap a)
            {
                
            int i;
                
            for(i=++len;hh[i>>1].dis > a.dis;i>>=1)
                    hh[i] 
            = hh[i>>1];
                hh[i] 
            = a;
            }
            Heap GetHeap()
            {
                Heap min 
            = hh[1];
                Heap last 
            = hh[len--];
                
            int i,s;
                
            for(i=1;2*i<=len;i=s)
                {
                    s 
            = i<<1;
                    
            if(s+1<=len && hh[s+1].dis < hh[s].dis)
                        s 
            ++;
                    
            if(hh[s].dis < last.dis)
                        hh[i] 
            = hh[s];
                    
            else
                        
            break;
                }
                hh[i] 
            = last;
                
            return min;
            }
            int bfs()
            {
                Heap a;
                a.x 
            = 1;
                a.dis 
            = 0;
                PutHeap(a);
                
            while(len)
                {
                    Heap min 
            = GetHeap();
                    
            if(min.x == n)
                        
            return min.dis;
                    
            int x = min.x;
                    
            if(!hash[x])
                        
            continue;
                    hash[x] 
            = false;
                    
            int dis = min.dis;

                    Road 
            *p;
                    p 
            = map[x].next;
                    
            while(p!=NULL)
                    {
                        
            int b = p->to;
                        
            if(hash[b])
                        {
                            a.x 
            = b;
                            a.dis 
            = p->dis + dis;
                            PutHeap(a);
                        }
                        p 
            = p->next;
                    }
                }
            }
            int main()
            {
                
            while(scanf("%d%d",&n,&m),n+m)
                {
                    len 
            = 0;
                    
            for(int i=1;i<=n;i++)
                    {
                        hash[i] 
            = true;
                        map[i].next 
            = NULL;
                        tail[i] 
            = &map[i];
                    }
                    
            for(i=0;i<m;i++)
                    {
                        
            int a,b,dis;
                        Road 
            *p,*q;
                        p 
            = (Road *)malloc(12);
                        q 
            = (Road *)malloc(12);

                        scanf(
            "%d%d%d",&a,&b,&dis);
                        p
            ->next = NULL;
                        p
            ->dis = dis;
                        p
            ->to = b;
                        tail[a]
            ->next = p;
                        tail[a] 
            = tail[a]->next;

                        q
            ->next = NULL;
                        q
            ->dis = dis;
                        q
            ->to = a;
                        tail[b]
            ->next = q;
                        tail[b] 
            = tail[b]->next;;
                    }
                    printf(
            "%d\n",bfs());
                }
                
            return 0;
            }
            posted on 2009-03-27 18:18 shǎ崽 閱讀(468) 評論(0)  編輯 收藏 引用
            久久精品中文字幕久久| 无码乱码观看精品久久| 久久精品中文无码资源站| 青青热久久国产久精品| 亚洲伊人久久成综合人影院| 国产精品乱码久久久久久软件| 无码人妻少妇久久中文字幕| 一本一本久久A久久综合精品| 好属妞这里只有精品久久| 精品久久久久中文字幕一区| 2020久久精品亚洲热综合一本| 日产精品久久久一区二区| 久久99热这里只有精品国产 | 51久久夜色精品国产| 色播久久人人爽人人爽人人片aV| 久久99精品久久久大学生| 国产精品久久久久久久午夜片| 7777精品久久久大香线蕉| 久久99热这里只有精品国产| 久久久一本精品99久久精品88| 久久夜色精品国产亚洲av| 精品综合久久久久久888蜜芽| 亚州日韩精品专区久久久| 一本一道久久精品综合| 久久久亚洲欧洲日产国码aⅴ| 精品国产日韩久久亚洲| 精品久久久久久国产牛牛app | 四虎影视久久久免费观看| 久久不射电影网| 久久婷婷五月综合色高清| 亚洲国产一成人久久精品| 久久久高清免费视频| 污污内射久久一区二区欧美日韩 | 精品熟女少妇AV免费久久| 久久久免费观成人影院| 国产成人精品久久| 一本大道加勒比久久综合| 久久综合综合久久97色| 亚洲成色999久久网站| 青青青青久久精品国产| 亚洲国产精品久久久久婷婷软件 |