• <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)  編輯 收藏 引用
            97久久国产露脸精品国产| 久久久国产一区二区三区| 伊人久久大香线焦AV综合影院| 日本精品久久久久久久久免费| 国产2021久久精品| 欧美伊人久久大香线蕉综合| 久久综合给久久狠狠97色| 99热精品久久只有精品| 亚洲日本va午夜中文字幕久久| 久久精品夜夜夜夜夜久久| 久久亚洲精品无码观看不卡| 亚洲精品第一综合99久久| 国产精品久久久亚洲| 人妻少妇精品久久| 精品午夜久久福利大片| 精品无码久久久久国产动漫3d | 欧美精品国产综合久久| 久久成人影院精品777| 一本久久a久久精品亚洲| 亚洲精品无码久久久| 国产A级毛片久久久精品毛片| 免费无码国产欧美久久18| 久久99精品久久久久久秒播| 久久国产精品成人影院| 色妞色综合久久夜夜| 久久亚洲2019中文字幕| 久久最近最新中文字幕大全| 午夜精品久久久久久久| 国产激情久久久久久熟女老人| 久久精品国产精品亚洲| 久久精品国产免费一区| 99久久无码一区人妻a黑| 久久综合香蕉国产蜜臀AV| 久久久无码精品亚洲日韩京东传媒| 亚洲国产成人久久综合一| 粉嫩小泬无遮挡久久久久久| 亚洲AV日韩AV永久无码久久 | 精品久久久久久综合日本| 久久w5ww成w人免费| 99久久久精品免费观看国产| 国产精品久久国产精麻豆99网站|