• <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)  編輯 收藏 引用
            看全色黄大色大片免费久久久| 亚洲综合久久久| 久久精品国产福利国产琪琪| 久久久久国产一区二区三区| 亚洲午夜福利精品久久| 69久久夜色精品国产69| 久久亚洲欧洲国产综合| 国产人久久人人人人爽| 久久成人国产精品一区二区| 久久免费的精品国产V∧| 2021国产精品久久精品| 国产91久久综合| 国内精品久久久久久野外| 久久99久国产麻精品66 | 久久久久免费精品国产| 久久精品国产半推半就| 伊人久久精品无码av一区| 欧洲性大片xxxxx久久久| 91久久精品91久久性色| 久久精品一本到99热免费| 亚洲va久久久噜噜噜久久| 伊人久久国产免费观看视频 | 久久伊人精品一区二区三区| 久久se精品一区精品二区| 国产精品18久久久久久vr| 久久久久亚洲精品无码蜜桃| 伊人久久无码中文字幕| 狠狠色婷婷久久一区二区| 久久国语露脸国产精品电影| 香蕉久久夜色精品国产尤物| 久久久这里有精品| 国产69精品久久久久观看软件| 久久91这里精品国产2020| 国产精品美女久久久网AV| 一本大道加勒比久久综合| 99久久免费国产精品| 国内精品欧美久久精品| 亚洲国产精品狼友中文久久久| 国产精品成人久久久| 久久精品亚洲AV久久久无码| 久久国产亚洲精品无码|