• <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>

            我希望你是我獨(dú)家記憶

            一段永遠(yuǎn)封存的記憶,隨風(fēng)而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            P1716

            Posted on 2008-09-07 13:30 Hero 閱讀(118) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
            //1716 Accepted 880K 0MS C++ 2474B PKU

            #include 
            <stdio.h>
            #include 
            <string.h>
            #include 
            <stdlib.h>

            const int INF = 100000000 ;
            const int size = 11000 ;

            struct NODE 
            {
                
            int en ;
                
            int len ;
                
            int next ;
            };

            struct NODE nhead[size*100] ;
            int chead ;

            int dist[size+100] ;
            int visit[size+100] ;
            int que[size*20] ;  
            int head, tail ;

            int inmax ;
            int inn ;

            void input()
            {
                
            int sn, en ; int len = 2 ; inmax = -1 ; chead = size ;

                
            forint i=0; i<size; i++ ) nhead[i].next = -1 ;

                
            forint i=1; i<=inn; i++ )
                {
                    scanf( 
            "%d %d"&sn, &en ) ; sn++ ; en++ ; en++ ;
                    
            if( inmax < en )    inmax = en ;

                    nhead[sn].len
            ++ ; nhead[chead].next = nhead[sn].next ; nhead[sn].next = chead ;
                    nhead[chead].en 
            = en ; nhead[chead].len = -2 ; chead++ ;
                }

                
            forint i=1; i<=inmax; i++ )
                {
                    sn 
            = i ; en = i-1 ;
                    nhead[sn].len
            ++ ; nhead[chead].next = nhead[sn].next ; nhead[sn].next = chead ;
                    nhead[chead].en 
            = en ; nhead[chead].len = 1 ; chead++ ;

                    sn 
            = i-1; en = i ;
                    nhead[sn].len
            ++ ; nhead[chead].next = nhead[sn].next ; nhead[sn].next = chead ;
                    nhead[chead].en 
            = en ; nhead[chead].len = 0 ; chead++ ;
                }

                
            forint i=1; i<=inmax; i++ )
                {
                    nhead[
            0].len++ ; nhead[chead].next = nhead[0].next; nhead[0].next = chead ;
                    nhead[chead].en 
            = i ; nhead[chead].len = 0 ; chead++ ;
                }
            /*
                for( int i=0; i<=inmax; i++ )
                {
                    printf( "head[%d]==%d", i, i ) ;
                    for( int p=nhead[i].next; p!=-1; p=nhead[p].next )
                        printf( " %4d ", nhead[p].en ) ;
                    printf( "\n" ) ;
                }
            */
            }

            void SPFA( int sn, int n )
            {
                
            for(int i=0; i<=n; i++
                {
                    dist[i] 
            = INF ; visit[i] = 0 ;
                }
                tail 
            = 0 ; que[++tail] = sn ; dist[sn] = 0 ; visit[sn] = 1 ;

                
            int cursn = 100 ;

                
            while( tail > 0 )
                {
                    cursn 
            = que[tail--] ; visit[cursn] = 0 ;
                    
            forint p=nhead[cursn].next ; p!=-1; p=nhead[p].next )
                    {
                        
            if( dist[nhead[p].en] > dist[cursn] + nhead[p].len )
                        {
                            dist[nhead[p].en] 
            = dist[cursn] + nhead[p].len ;
                            
            if0 == visit[nhead[p].en] )
                            {
                                visit[nhead[p].en] 
            = 1 ; que[++tail] = nhead[p].en ;
                            }
                        }
                    }
                }
            }


            void process()
            {
                SPFA( 
            0, inmax ) ;

                
            //for( int i=0; i<=inmax; i++ ) printf( "dist[%d]===%d\n", i, dist[i] ) ;

                printf( 
            "%d\n"0-dist[inmax] ) ;
            }

            int main()
            {
                
            //freopen( "in.txt", "r", stdin ) ;

                
            while( scanf( "%d"&inn ) != EOF )
                {
                    input() ;

                    process() ;

                    
            //output() ;
                }

                
            return 0 ;
            }
            精品视频久久久久| 久久国产欧美日韩精品| 久久A级毛片免费观看| 日本精品久久久久影院日本| 久久av无码专区亚洲av桃花岛| 久久精品人人做人人爽97| 久久国产AVJUST麻豆| 久久婷婷五月综合97色一本一本| 亚洲日本久久久午夜精品| 国产精品亚洲美女久久久| 亚洲?V乱码久久精品蜜桃 | 欧美精品丝袜久久久中文字幕| 久久99国产精品久久99小说| 久久亚洲日韩精品一区二区三区| 国产精品99久久久精品无码| 精品伊人久久大线蕉色首页| 青青热久久综合网伊人| 伊人久久大香线蕉亚洲| 亚洲欧美日韩久久精品第一区| 伊人色综合久久天天人守人婷| 午夜久久久久久禁播电影| 久久人人爽人人爽人人AV| 三上悠亚久久精品| 欧洲成人午夜精品无码区久久| 久久人人爽人人爽人人av东京热| 久久丝袜精品中文字幕| 精品欧美一区二区三区久久久| 91精品国产高清久久久久久91| 九九99精品久久久久久| 久久久无码一区二区三区| 久久精品国产精品青草| 久久本道综合久久伊人| 久久久国产精华液| 日韩精品久久无码人妻中文字幕| 亚洲午夜久久久精品影院| 国产99久久久国产精免费| 久久99国产精品久久| 精品久久久久久久久午夜福利| 亚洲国产精品久久久天堂| 久久亚洲2019中文字幕| 久久精品国产99久久香蕉|