• <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)  編輯 收藏 引用
            久久亚洲精品国产精品婷婷| 老色鬼久久亚洲AV综合| 国产一区二区精品久久岳| 久久99精品久久久久久9蜜桃 | 国产国产成人精品久久| 久久成人国产精品二三区| 精品乱码久久久久久夜夜嗨| 亚洲国产成人精品无码久久久久久综合| 精品国产婷婷久久久| 欧美伊人久久大香线蕉综合| 久久av无码专区亚洲av桃花岛| 久久中文字幕一区二区| 中文字幕无码久久精品青草| 久久国产免费观看精品3| 久久久久久亚洲精品无码| 久久久久亚洲AV无码麻豆| 亚洲国产成人精品无码久久久久久综合| 午夜久久久久久禁播电影| 国产亚洲色婷婷久久99精品91| 亚洲中文字幕久久精品无码APP | 久久人搡人人玩人妻精品首页| 久久香蕉超碰97国产精品 | 伊人久久大香线蕉无码麻豆| 久久99精品国产| 亚洲香蕉网久久综合影视| 欧美午夜A∨大片久久 | 亚州日韩精品专区久久久| 久久久精品免费国产四虎| 久久久无码人妻精品无码| 亚洲精品无码久久久久| 久久天天婷婷五月俺也去| 日本高清无卡码一区二区久久| 久久精品国产欧美日韩| 亚洲国产精品久久久久婷婷老年| 久久久久女人精品毛片| 久久精品午夜一区二区福利| 久久婷婷激情综合色综合俺也去| 久久九九久精品国产免费直播| 国内精品伊人久久久久妇| 99蜜桃臀久久久欧美精品网站| 无码任你躁久久久久久|