青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Remmarguts' Date poj 2449 K短路

Posted on 2012-04-26 22:05 lenohoo 閱讀(375) 評論(1)  編輯 收藏 引用
Remmarguts' Date

Description

"Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story.

"Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One day their neighboring country sent them Princess Uyuw on a diplomatic mission."

"Erenow, the princess sent Remmarguts a letter, informing him that she would come to the hall and hold commercial talks with UDF if and only if the prince go and meet her via the K-th shortest path. (in fact, Uyuw does not want to come at all)"

Being interested in the trade development and such a lovely girl, Prince Remmarguts really became enamored. He needs you - the prime minister's help!

DETAILS: UDF's capital consists of N stations. The hall is numbered S, while the station numbered T denotes prince' current place. M muddy directed sideways connect some of the stations. Remmarguts' path to welcome the princess might include the same station twice or more than twice, even it is the station with number S or T. Different paths with same length will be considered disparate.

Input

The first line contains two integer numbers N and M (1 <= N <= 1000, 0 <= M <= 100000). Stations are numbered from 1 to N. Each of the following M lines contains three integer numbers A, B and T (1 <= A, B <= N, 1 <= T <= 100). It shows that there is a directed sideway from A-th station to B-th station with time T.

The last line consists of three integer numbers S, T and K (1 <= S, T <= N, 1 <= K <= 1000).

Output

A single line consisting of a single integer number: the length (time required) to welcome Princess Uyuw using the K-th shortest path. If K-th shortest path does not exist, you should output "-1" (without quotes) instead.

Sample Input

2 2 1 2 5 2 1 4 1 2 2 

Sample Output

14

Source

POJ Monthly,Zeyuan Zhu

#include<cstdio>
#include
<cstring>
#include
<iostream>
#include
<vector>
#include
<queue>
#include
<algorithm>
using namespace std;
#define re(i,n) for(int i=0;i<n;i++)
#define re2(i,n) for(int i=1;i<=n;i++)
#define pb push_back
const int MAXN = 1001;
const int inf = 999999999;
struct nod{
    
int x,val;
};
struct cmp{
    
bool operator()(nod a,nod b){
        
return a.val>b.val;
    }
};
int N,M,S,T,K,dist[MAXN],out[MAXN];
vector
<nod> g[MAXN],r[MAXN];
priority_queue
<nod,vector<nod>,cmp> Q;
void dijkstra(){
    
bool vi[MAXN];
    re2(i,N) vi[i]
=0,dist[i]=inf;
    dist[T]
=0;
    
while(1){
        
int k=-1;
        re2(i,N) 
if(!vi[i] && (k==-1 || dist[i]<dist[k])) k=i;
        
if(k==-1break;
        vi[k]
=1;
        re(i,r[k].size()){
            nod u
=r[k][i];
            
if(!vi[u.x] && dist[u.x]>dist[k]+u.val) dist[u.x]=dist[k]+u.val;
        }
    }
}
int astar(){
    dijkstra();
    nod v;
    v.x
=S,v.val=dist[S];
    Q.push(v);
    re2(i,N) 
out[i]=0;
    
while(!Q.empty() && out[T]<K){
        v
=Q.top();Q.pop();
        
if(out[v.x]>=K) continue;
        
if(v.x==T){
            
out[v.x]++;
            
if(out[v.x]==K) return v.val;
        }
        re(i,g[v.x].size()){
            nod u
=g[v.x][i];
            
if(out[u.x]>=K) continue;
            u.val
=v.val-dist[v.x]+u.val+dist[u.x];
            Q.push(u);
        }
    }
    
return -1;
}
int main(){
    
while(cin>>N>>M){
        
int a,b,w;
        re2(i,N) g[i].clear(),r[i].clear();
        re(i,M){
            cin
>>a>>b>>w;
            nod tmp;
            tmp.x
=b,tmp.val=w;
            g[a].pb(tmp);
            tmp.x
=a;
            r[b].pb(tmp);
        }
        cin
>>S>>T>>K;
        
if(S==T) K++;
        
int ans=astar();
        cout
<<ans<<endl;
    }
    
return 0;
}

Feedback

# re: Remmarguts' Date poj 2449 K短路  回復  更多評論   

2012-04-27 07:06 by lenohoo
注意s==t的時候要k++啊

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


posts - 3, comments - 1, trackbacks - 0, articles - 16

Copyright © lenohoo

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美午夜视频网站| 狠狠色丁香婷婷综合久久片| 欧美日韩亚洲一区在线观看| 狠狠入ady亚洲精品经典电影| 宅男噜噜噜66国产日韩在线观看| 欧美在线视频导航| 日韩亚洲欧美综合| 欧美a级大片| 亚洲国产欧洲综合997久久| 欧美在线观看一区二区三区| 91久久夜色精品国产九色| 91久久综合亚洲鲁鲁五月天| 久久国产精品网站| 久久国产夜色精品鲁鲁99| 国模私拍一区二区三区| 欧美一级大片在线观看| 欧美一级片久久久久久久| 亚洲图片欧洲图片av| 日韩视频在线一区二区三区| 欧美午夜宅男影院| 久久免费高清| 欧美三区在线| 欧美大片18| 国产精品一区在线播放| 农夫在线精品视频免费观看| 欧美jizzhd精品欧美巨大免费| 一区二区三区 在线观看视| 午夜精品成人在线| 99综合在线| 美女日韩欧美| 欧美一区二区三区在线观看| 免费h精品视频在线播放| 欧美一区二区免费视频| 欧美天天在线| 欧美 日韩 国产 一区| 国产欧美一区二区精品忘忧草| 亚洲成在人线av| 国内精品免费午夜毛片| 一本久道久久综合中文字幕 | 亚洲激情在线观看| 激情婷婷久久| 欧美一区二区三区电影在线观看 | 亚洲欧美视频一区| 亚洲制服av| 国产精品日韩在线观看| 午夜久久资源| 久久久久久久久一区二区| 国产欧美精品日韩区二区麻豆天美| 99在线热播精品免费| 亚洲中字黄色| 国产无遮挡一区二区三区毛片日本| 亚洲亚洲精品在线观看| 久久午夜电影网| 日韩午夜激情av| 国产乱码精品一区二区三区五月婷| 亚洲伊人第一页| 欧美承认网站| 性欧美暴力猛交另类hd| 亚洲第一色中文字幕| 欧美日韩免费在线观看| 欧美有码在线观看视频| 亚洲高清视频的网址| 亚洲欧美日韩在线综合| 在线观看一区二区视频| 欧美日韩在线大尺度| 久久人人爽人人爽爽久久| 99精品国产福利在线观看免费| 久久久精品视频成人| 99日韩精品| 亚洲精品国产无天堂网2021| 国产欧美日韩在线视频| 欧美激情精品久久久六区热门| 午夜精品免费在线| 日韩一级片网址| 亚洲欧洲精品一区二区三区不卡| 久久er99精品| 一区二区三区欧美成人| 亚洲福利视频免费观看| 国语自产精品视频在线看8查询8 | 欧美一级视频精品观看| 亚洲精品视频一区| 亚洲福利专区| 亚洲精品国偷自产在线99热| 激情一区二区| 国产一区在线视频| 伊人久久大香线蕉综合热线 | 亚洲欧美美女| 欧美日韩亚洲免费| 亚洲天堂av图片| 亚洲欧美国产日韩中文字幕| 国产乱子伦一区二区三区国色天香 | 欧美大学生性色视频| 亚洲欧美日韩视频一区| 欧美午夜精品久久久久免费视 | 亚洲三级电影全部在线观看高清| 国产日产精品一区二区三区四区的观看方式 | 欧美顶级少妇做爰| 裸体一区二区| 亚洲欧美另类国产| 欧美影院久久久| 欧美电影免费观看高清| 欧美另类久久久品 | 久久男女视频| 午夜影视日本亚洲欧洲精品| 欧美一区二区观看视频| 卡一卡二国产精品| 欧美性感一类影片在线播放| 国产一区二区丝袜高跟鞋图片| 亚洲国产精品嫩草影院| 欧美亚洲免费高清在线观看| 亚洲成人在线网| 午夜视频在线观看一区二区| 欧美多人爱爱视频网站| 国产一本一道久久香蕉| 亚洲午夜激情网站| 亚洲福利电影| 久久久久久婷| 国产欧美日韩综合精品二区| 一本大道av伊人久久综合| 免费永久网站黄欧美| 久久精品国产亚洲5555| 国产精品嫩草影院一区二区| 亚洲欧美精品中文字幕在线| 欧美日韩日韩| 夜夜爽av福利精品导航| 亚洲黄页一区| 欧美精品激情在线| 亚洲免费精品| 一区二区三区久久网| 一区二区三区国产精品| 一区二区三区免费看| 一区二区91| 国产亚洲一区精品| 欧美成人国产| 欧美日韩免费区域视频在线观看| 亚洲视频国产视频| 国产精品日韩精品欧美在线| 尹人成人综合网| 亚洲精品乱码久久久久久| 欧美日韩在线看| 亚洲欧美日韩国产中文在线| 欧美在线亚洲综合一区| 亚洲日韩成人| 午夜一区二区三区不卡视频| 亚洲欧洲另类| 亚洲一区国产视频| 韩国一区二区三区美女美女秀| 亚洲成人在线网站| 亚洲最新在线| 91久久精品一区二区三区| 亚洲性xxxx| 亚洲午夜91| 欧美日本中文| 欧美刺激午夜性久久久久久久| 国产精品婷婷午夜在线观看| 最新亚洲电影| 最新成人av网站| 欧美亚洲三区| 亚洲一区精品视频| 欧美精品一卡二卡| 欧美粗暴jizz性欧美20| 韩日精品视频| 欧美一区二区三区在线观看视频| 久久精品国亚洲| 国产一区二区三区黄| 亚洲国产一区在线观看| 男女激情视频一区| 亚洲视频一区在线| 亚洲国产精品成人综合| 欧美日韩在线视频一区| 亚洲精品看片| 亚洲免费成人av| 欧美三日本三级少妇三2023| 亚洲精品永久免费| 欧美国产日韩精品免费观看| 久久精品国产综合精品| 亚洲精品欧美精品| 久久精品成人欧美大片古装| 老司机精品视频一区二区三区| 性欧美大战久久久久久久久| 欧美福利专区| 亚洲欧美视频在线| 9久re热视频在线精品| 国产在线精品成人一区二区三区| 一本一道久久综合狠狠老精东影业| 亚洲高清网站| 欧美视频1区| 老司机免费视频久久| 日韩亚洲国产欧美| 葵司免费一区二区三区四区五区| 在线观看国产精品淫| 欧美日韩国产精品一区| 午夜在线精品偷拍| 国产精品自在线| 欧美不卡视频一区发布| 亚洲欧美日本视频在线观看| 亚洲经典在线看| 久久在线播放| 在线观看三级视频欧美| 性欧美办公室18xxxxhd|