• <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 閱讀(870) 評論(2)  編輯 收藏 引用

            評論:
            # re: Pku 2449 Remmarguts' Date 2009-08-03 23:19 | Linz
            太奇怪了,我用優先隊列怎么樣都MLE,手寫堆才過的。  回復  更多評論
              
            # re: Pku 2449 Remmarguts' Date[未登錄] 2009-08-24 22:47 | super
            為什么你的dijkstra那樣也可以的???  回復  更多評論
              
            精品久久久无码21p发布| 麻豆精品久久精品色综合| 人妻系列无码专区久久五月天| 久久精品国产亚洲av影院| 国产欧美一区二区久久| 国产精品成人无码久久久久久 | 久久久久久极精品久久久| 亚洲精品美女久久久久99小说| 中文字幕久久波多野结衣av| 99久久99久久精品国产片| 亚洲精品无码久久久久AV麻豆| 7777久久亚洲中文字幕| 久久这里有精品视频| 久久婷婷五月综合色奶水99啪| 国产成人久久777777| 麻豆成人久久精品二区三区免费| 久久精品无码专区免费 | 亚洲精品国产自在久久| 久久久久无码精品国产不卡| 青青草国产97免久久费观看| 国产精品久久网| 久久99精品久久久大学生| 久久久久一本毛久久久| 亚洲乱亚洲乱淫久久| 久久se精品一区二区| 99久久夜色精品国产网站| 久久久久无码专区亚洲av| 成人国内精品久久久久一区| 久久精品国产亚洲AV不卡| 久久精品成人| 久久99精品久久久久久水蜜桃| 国产成人精品久久二区二区| 久久国产色AV免费看| 久久人爽人人爽人人片AV| 伊人久久大香线蕉av一区| 久久久久亚洲av成人网人人软件| 精品国产婷婷久久久| 久久久这里有精品中文字幕| 久久一区二区三区免费| 久久久久久国产精品无码下载| 欧美粉嫩小泬久久久久久久 |