• <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久久| 久久九九免费高清视频 | 青春久久| 狠狠色婷婷久久一区二区| 国产成人精品久久免费动漫| 高清免费久久午夜精品| 99久久国产主播综合精品| 久久亚洲精品无码VA大香大香| 亚洲国产精品无码久久98| 久久99精品综合国产首页| 要久久爱在线免费观看| 国产成人精品白浆久久69| 国产精品欧美久久久久无广告| 久久久久久一区国产精品| 思思久久好好热精品国产| 91视频国产91久久久| 国产精品久久新婚兰兰| 热久久最新网站获取| 91亚洲国产成人久久精品网址| 久久亚洲精品成人无码网站| 97r久久精品国产99国产精| 久久人做人爽一区二区三区| 伊人久久综在合线亚洲2019| 伊人色综合久久天天人手人婷| 久久久不卡国产精品一区二区| 国产精品一区二区久久不卡| 亚洲日本va中文字幕久久| 久久精品国产一区二区电影| 欧美伊香蕉久久综合类网站| 久久婷婷国产综合精品| 噜噜噜色噜噜噜久久| 亚洲Av无码国产情品久久| 久久国产乱子伦精品免费午夜| 国产精品视频久久久| 国产精品美女久久久| 久久亚洲精品无码aⅴ大香| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 成人精品一区二区久久| 99久久国产综合精品五月天喷水|