• <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ǎ崽 閱讀(469) 評論(0)  編輯 收藏 引用
            亚洲AV无码久久精品成人| 久久人做人爽一区二区三区| 国内精品久久久久影院优 | 久久精品不卡| 久久久久久国产a免费观看黄色大片| 久久人与动人物a级毛片| 亚洲国产另类久久久精品| 久久精品国产亚洲沈樵| 国产香蕉久久精品综合网| 国内精品久久国产大陆| 一本色道久久88综合日韩精品 | 久久精品无码一区二区无码| 国产精品久久影院| 久久精品青青草原伊人| 久久综合久久综合久久| 伊人久久综合成人网| 久久精品国产第一区二区| 精品国产一区二区三区久久久狼 | 久久久久久久97| 国内高清久久久久久| 日韩电影久久久被窝网| 国产欧美一区二区久久| 久久久久人妻一区二区三区vr | 色婷婷久久综合中文久久蜜桃av| 狠狠精品干练久久久无码中文字幕 | 欧美激情精品久久久久| 亚洲av成人无码久久精品| 久久久WWW成人| 精品无码久久久久久久久久| 久久精品国产久精国产思思| 亚洲中文字幕无码久久精品1| 日日狠狠久久偷偷色综合0| 久久精品国产一区二区三区不卡| 99久久精品九九亚洲精品| 99久久国产主播综合精品| 久久九九青青国产精品| 欧美黑人又粗又大久久久| 久久久久久无码Av成人影院 | 久久久久久久久久免免费精品| 久久精品国产影库免费看| 91久久香蕉国产熟女线看|