• <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>
            #include <cstdio>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <functional>

            using namespace std;

            #define MAXN  1010
            typedef pair
            <int,int> PAIR;

            int n, m, s, t, k;
            vector
            < PAIR > map[MAXN], graph[MAXN];
            int h[MAXN];

            struct Node
            {
                
            int v, cost;
                Node() {}
                Node( 
            int a, int b ):v(a), cost(b) {}
            };

            bool operator< ( Node a, Node b )
            {
                
            return a.cost+ h[a.v]> b.cost+ h[b.v];
            }

            void dijk()
            {
                fill( h, h
            + n+ 1, INT_MAX );
                priority_queue
            < PAIR > q;
                
                q.push( make_pair( t, 
            0 ) );
                h[t]
            = 0;
                
                
            while!q.empty() )
                {
                    
            int u= q.top().first, len= q.top().second; q.pop();
                    
                    
            if( h[u]!= len ) continue;
                    
                    
            for( size_t i= 0; i< graph[u].size(); ++i )
                    {
                        
            int v= graph[u][i].first, cost= graph[u][i].second;
                        
                        
            if( h[v]> len+ cost )
                        {
                            q.push( make_pair( v, len
            + cost ) );
                            h[v]
            = len+ cost;
                        }
                    }
                }
            }

            int A_star()
            {
                priority_queue
            < Node > q;
                
            int c[MAXN];
                
                fill( c, c
            + n+ 10 );
                
            if( h[s]== INT_MAX ) return -1;
                
                q.push( Node( s, 
            0 ) );                                                                                                                                                                                                                                                                                                                                                              
                
            while!q.empty() )
                {
                    
            int v= q.top().v, cost= q.top().cost; q.pop();
                    
                    c[v]
            ++;
                    
            if( c[t]== k ) return cost;
                    
            if( c[v]> k  ) continue;
                    
                    
            for( size_t i= 0; i< map[v].size(); ++i )
                        q.push( Node( map[v][i].first, cost
            + map[v][i].second ) );
                }
                
                
            return -1;
            }

            int main()
            {
                scanf(
            "%d%d",&n,&m );
                
                
            forint i= 0; i< m; ++i )
                {
                    
            int u, v, d;
                    scanf(
            "%d%d%d",&u,&v,&d );
                    
                    map[u].push_back ( make_pair( v, d ) );
                    graph[v].push_back ( make_pair( u, d ) );
                }
                
                scanf(
            "%d%d%d",&s,&t,&k );
                
            if( s== t ) k++;
                
                dijk();
                printf(
            "%d\n",A_star() );
                
                
            return 0;
            }



            #include <iostream>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <functional>
            #include 
            <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>

            using namespace std;

            #define N 1002
            #define inf 1<<30

            typedef pair
            <int,int> PAIR;

            int n, m, S, T, K;
            vector
            <PAIR> g1[N], g2[N];
            int h[N], cnt[N];

            void dijk(){
                priority_queue
            <PAIR,vector<PAIR>,greater<PAIR> > q;
                
            forint i= 0; i<= n; ++i ) h[i]= inf;
                h[T]
            = 0;  q.push( PAIR(0,T) );
                
                
            while!q.empty() ){
                    
            int u= q.top().second, w= q.top().first; q.pop();
                    
                    
            if( w!= h[u] ) continue;
                    
                    
            for( size_t i= 0; i< g2[u].size(); ++i ){
                        
            int v= g2[u][i].first, d= g2[u][i].second;
                        
            if( h[u]+ d< h[v] ){
                            h[v]
            = h[u]+ d;
                            q.push( PAIR( h[v], v ) );
                        }
                    }
                }
            }

            struct cmp{
                inline 
            bool operator()( PAIR const& a, PAIR const& b ){
                    
            return a.second+ h[a.first]> b.second+ h[b.first];
                }
            };

            int A_star(){
                
            if( h[S]== inf ) return -1;
                
                priority_queue
            <PAIR,vector<PAIR>,cmp> q;
                q.push( PAIR( S, 
            0 ) );
                
                
            while!q.empty() ){
                    
            int u= q.top().first, w= q.top().second; q.pop();
                    
                    cnt[u]
            ++;
                    
            if( cnt[T]== K ) return w;
                    
            if( cnt[u]> K ) continue;
                    
                    
            for( size_t i= 0; i< g1[u].size(); ++i )
                    q.push( PAIR( g1[u][i].first, g1[u][i].second
            + w ) );
                }
                
                
            return -1;
            }

            inline 
            int read(){
                
            char ch;
                
            int d;
                
            while( ch= getchar(), ch< '0' || ch> '9' );
                d
            = ch- '0';
                
            while( ch= getchar(), ch>= '0' && ch<= '9' )
                d
            = d* 10+ ch- '0';
                
            return d;
            }

            int main(){
                scanf(
            "%d%d",&n,&m );
                
                
            int u, v, d;
                
            while( m-- ){
                    u
            = read(); v= read(); d= read();
                    
                    g1[u].push_back( PAIR(v,d) );
                    g2[v].push_back( PAIR(u,d) );
                }
                scanf(
            "%d%d%d",&S,&T,&K );
                
            if( S== T ) K++;
                
                dijk();
                printf(
            "%d\n", A_star() );
                
                
            return 0;
            }
            posted on 2008-12-04 14:00 Darren 閱讀(878) 評論(2)  編輯 收藏 引用

            評論:
            # re: Pku 2449 Remmarguts' Date 2009-08-03 23:19 | Linz
            太奇怪了,我用優(yōu)先隊(duì)列怎么樣都MLE,手寫堆才過的。  回復(fù)  更多評論
              
            # re: Pku 2449 Remmarguts' Date[未登錄] 2009-08-24 22:47 | super
            為什么你的dijkstra那樣也可以的???  回復(fù)  更多評論
              

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            99久久精品免费看国产一区二区三区 | 亚洲精品tv久久久久久久久| 久久久久久久91精品免费观看| 久久人人爽人人爽人人片AV麻烦| 亚洲欧洲日产国码无码久久99| 国产成人精品久久免费动漫| 久久久久久av无码免费看大片| 亚洲AV无码久久| 久久精品无码一区二区三区日韩| 久久夜色精品国产噜噜麻豆| 精品乱码久久久久久夜夜嗨 | 99久久99久久| 99久久这里只精品国产免费| 亚洲国产精品久久久久婷婷软件| 久久精品国产2020| 欧美与黑人午夜性猛交久久久 | 国内精品久久久久影院优| 日韩美女18网站久久精品| 大伊人青草狠狠久久| 无码国内精品久久人妻蜜桃| 久久亚洲色一区二区三区| av无码久久久久久不卡网站| 色综合久久中文字幕无码| 伊人久久大香线蕉成人| 久久精品国产亚洲Aⅴ蜜臀色欲| 九九久久自然熟的香蕉图片| A级毛片无码久久精品免费| 久久久91人妻无码精品蜜桃HD| 伊人久久大香线蕉影院95| 久久精品国产亚洲精品2020 | 精品久久久久久久国产潘金莲 | 一本一本久久a久久综合精品蜜桃| 久久久久亚洲精品男人的天堂| 国内精品久久久久久野外| 久久久久亚洲AV无码永不| 久久精品欧美日韩精品| 72种姿势欧美久久久久大黄蕉| 久久99国产综合精品女同| 99热成人精品热久久669| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 亚洲AV无码久久精品成人|