• <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)  編輯 收藏 引用
            99久久精品日本一区二区免费| 久久中文字幕人妻丝袜| 国产精品一久久香蕉国产线看观看 | 久久精品国产精品青草app| 久久久国产精品亚洲一区| 亚洲国产精品久久电影欧美| 中文精品久久久久人妻不卡| 久久中文骚妇内射| 久久精品国产秦先生| 九九热久久免费视频| 色综合久久天天综线观看| 久久亚洲sm情趣捆绑调教| 久久久亚洲AV波多野结衣| 久久夜色精品国产网站| 久久免费精品视频| 九九久久精品无码专区| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 精品无码久久久久久午夜| 国产精品久久国产精品99盘 | 久久精品人人做人人爽97 | 久久精品国产亚洲7777| 婷婷久久综合九色综合九七| av色综合久久天堂av色综合在| 久久99久久99精品免视看动漫| 色综合久久综精品| 久久中文字幕人妻熟av女| 久久综合久久综合九色| 欧美亚洲国产精品久久高清| 久久国产亚洲精品无码| 久久久久久毛片免费看| 久久w5ww成w人免费| 午夜精品久久久久久影视riav| 亚洲va国产va天堂va久久| 久久e热在这里只有国产中文精品99 | 伊人情人综合成人久久网小说| 99国产精品久久| 欧美黑人激情性久久| 久久精品国产亚洲一区二区三区| 亚洲AV无码久久精品蜜桃| 久久综合亚洲色HEZYO国产 | 欧美黑人又粗又大久久久|