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

USACO Section 2.4 Bessie Come Home

Bessie Come Home

Kolstad & Burch

It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow).

Between milkings, each cow is located in her own pasture, though some pastures have no cows in them. Each pasture is connected by a path to one or more other pastures (potentially including itself). Sometimes, two (potentially self-same) pastures are connected by more than one path. One or more of the pastures has a path to the barn. Thus, all cows have a path to the barn and they always know the shortest path. Of course, cows can go either direction on a path and they all walk at the same speed.

The pastures are labeled `a'..`z' and `A'..`Y'. One cow is in each pasture labeled with a capital letter. No cow is in a pasture labeled with a lower case letter. The barn's label is `Z'; no cows are in the barn, though.

PROGRAM NAME: comehome

INPUT FORMAT

Line 1: Integer P (1 <= P <= 10000) the number of paths that interconnect the pastures (and the barn)
Line 2..P+1: Space separated, two letters and an integer: the names of the interconnected pastures/barn and the distance between them (1 <= distance <= 1000)

SAMPLE INPUT (file comehome.in)

5
A d 6
B d 3
C e 9
d Z 8
e Z 3

OUTPUT FORMAT

A single line containing two items: the capital letter name of the pasture of the cow that arrives first back at the barn, the length of the path followed by that cow.

SAMPLE OUTPUT (file comehome.out)

B 11
Analysis

Since the problem aims to solve a single-source shortest path problem, we can use the classical algorithms, such as Dijkstra, Bellman-Ford and the Floyd algorithm. Thanks to the small data amount, all of them are correct for this prblem.

Code

/*
ID:braytay1
TASK:comehome
LANG:C++
*/

#include 
<iostream>
#include 
<fstream>
using namespace std;
ifstream fin(
"comehome.in");
ofstream fout(
"comehome.out");

int map[55][55];
int dis[55];

void bellman_ford(){
    dis[
52]=0;
    
for (int k=1;k<52;k++)
        
for (int u=1;u<=52;u++)
            
for (int v=1;v<=52;v++)
                
if ((dis[v]>dis[u]+map[u][v])&&map[u][v]<=10000
                    dis[v]
=dis[u]+map[u][v];
}

char find_min(int a[55]){
    
char source;
    
int min=1000000;
    
for (int i=27;i<=51;i++){
        
if (min>a[i]) {min=a[i];source=i-26+64;}
    }

    
return source;
}

int main(){
    
int N;
    fin
>>N;
    memset(map,
100,sizeof(map));
    
for (int i=1;i<=N;i++){
        
char source,dest;
        fin
>>source>>dest;
        
int s,d;
        s
=(source>=97&&source<=122)?(source-96):(source-64+26);
        d
=(dest>=97&&dest<=122)?(dest-96):(dest-64+26);
        
int ds;
        fin
>>ds;
        
if (ds<map[s][d]) map[s][d]=ds;        
        map[d][s]
=map[s][d];
    }

    memset(dis,
100,sizeof(dis));
    bellman_ford();
    
char res;
    res
=find_min(dis);
    fout
<<res<<" "<<dis[res-64+26]<<endl;
    
return 0;
}

posted on 2008-08-19 22:19 幻浪天空領主 閱讀(236) 評論(0)  編輯 收藏 引用 所屬分類: USACO

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美中文在线观看| 亚洲激情网站| 免费av成人在线| 久久久精品久久久久| 久久本道综合色狠狠五月| 久久av资源网站| 免费不卡在线观看av| 欧美极品一区| 欧美三级小说| 国产精品久久激情| 国产欧美日韩在线视频| 一区二区三区中文在线观看| 亚洲美女精品成人在线视频| 亚洲一区二区三区精品在线| 午夜一级久久| 欧美mv日韩mv国产网站| 99国产精品久久| 亚洲欧美www| 蜜臀av性久久久久蜜臀aⅴ四虎| 欧美日韩在线播放一区二区| 国产一区二区黄色| 亚洲精品欧美精品| 久久国产一二区| 亚洲日本aⅴ片在线观看香蕉| 亚洲国产综合91精品麻豆| 亚洲一区二区三区视频| 免费欧美视频| 国产欧美丝祙| 在线视频精品| 欧美成人午夜激情| 亚洲欧美视频在线观看| 欧美二区不卡| 国产伦精品一区二区三区照片91 | 欧美精品在线一区| 红桃视频亚洲| 久久爱另类一区二区小说| 最新国产成人av网站网址麻豆| 亚洲深夜福利| 免费观看成人鲁鲁鲁鲁鲁视频 | 亚洲最新视频在线| 久久激情五月激情| 一区二区免费看| 欧美不卡视频| 在线欧美日韩国产| 欧美在线视频导航| 9i看片成人免费高清| 奶水喷射视频一区| 亚洲福利视频网| 久久综合伊人77777蜜臀| 亚洲欧美精品| 国产欧美激情| 欧美一二三区在线观看| 亚洲一区二区三区在线| 欧美系列电影免费观看| 日韩午夜激情av| 欧美激情bt| 免费在线日韩av| 亚洲国产美女| 欧美激情第五页| 欧美成人午夜激情| 亚洲三级视频在线观看| 欧美黄色免费网站| 欧美黄在线观看| 亚洲视频一起| 亚洲一区中文字幕在线观看| 国产精品免费一区二区三区观看| 亚洲一区视频在线| 亚洲一区二区三区精品视频| 国产精品网站在线观看| 久久狠狠一本精品综合网| 午夜在线精品偷拍| 韩国av一区| 亚洲国产三级在线| 欧美午夜精品一区| 欧美一区午夜精品| 久久精品国产99国产精品| 一区二区三区在线观看国产| 亚洲国产精品t66y| 欧美日韩一区二区在线| 午夜免费久久久久| 久久成人综合视频| 亚洲欧洲日本专区| 亚洲精品韩国| 亚洲国内自拍| 国产精品久久久久77777| 久久久亚洲高清| 女女同性精品视频| 亚洲欧美精品伊人久久| 久久精品123| 夜夜精品视频| 久久精品国产一区二区三区免费看| 亚洲国产精品一区二区尤物区| 91久久精品一区二区别| 国产精品一区二区欧美| 欧美激情按摩在线| 国产欧美日韩综合一区在线播放| 欧美成人免费在线| 日韩一级黄色大片| 激情亚洲网站| 亚洲图片自拍偷拍| 亚洲美女福利视频网站| 欧美主播一区二区三区美女 久久精品人| 亚洲人线精品午夜| 欧美一级专区免费大片| 99国产麻豆精品| 久久看片网站| 久久精品视频va| 欧美日韩日日骚| 久热成人在线视频| 国产免费成人av| 亚洲美女中出| 最新国产の精品合集bt伙计| 午夜久久久久久| 亚洲一区二区三区免费在线观看| 老司机午夜精品视频在线观看| 久久国产精品亚洲va麻豆| 欧美日韩综合一区| 亚洲经典在线| 亚洲日本中文字幕| 美女黄色成人网| 免费久久99精品国产| 国模精品一区二区三区| 亚洲五月六月| 亚洲自拍偷拍一区| 欧美亚韩一区| 夜夜嗨一区二区| 一区二区三区四区国产| 欧美日本一区| 亚洲靠逼com| 亚洲国产视频直播| 免费观看久久久4p| 亚洲第一网站免费视频| 亚洲国产欧美日韩另类综合| 久久精品国产精品亚洲精品| 欧美一二三视频| 国产午夜亚洲精品羞羞网站| 亚洲影院色无极综合| 亚洲欧美中文日韩v在线观看| 国产精品v片在线观看不卡| 一级日韩一区在线观看| 亚洲欧美另类中文字幕| 国产精品一二一区| 欧美一区二区高清| 久久夜色精品国产噜噜av| 精品va天堂亚洲国产| 久久字幕精品一区| 亚洲大胆av| 亚洲深夜福利| 国产亚洲美州欧州综合国| 久久精品视频亚洲| 亚洲国内精品在线| 亚洲欧美日韩国产中文| 国产欧美一区二区精品仙草咪| 久久av红桃一区二区小说| 免费在线亚洲| aa级大片欧美三级| 国产精品一区免费观看| 久久久一本精品99久久精品66| 亚洲风情在线资源站| 亚洲小说春色综合另类电影| 国产精品专区一| 麻豆精品在线观看| 亚洲香蕉网站| 玖玖国产精品视频| 一区二区免费在线观看| 国产视频久久久久| 欧美不卡视频一区发布| 国产精品久久久久国产精品日日| 亚洲综合第一页| 国内久久视频| 欧美日韩精品国产| 午夜宅男久久久| 亚洲国产精品黑人久久久 | 香蕉精品999视频一区二区| 国模精品一区二区三区色天香| 欧美激情综合在线| 午夜综合激情| 在线亚洲电影| 亚洲福利视频一区二区| 欧美在线视频观看| 中文精品99久久国产香蕉| 一区二区三区自拍| 国产精品入口66mio| 免费看的黄色欧美网站| 亚洲男同1069视频| 最新中文字幕一区二区三区| 久久久xxx| 亚洲欧美在线aaa| 亚洲日韩欧美一区二区在线| 狠狠色狠狠色综合日日小说| 国产精品久久久久久妇女6080| 欧美a级片一区| 久久精品99无色码中文字幕| 亚洲视频中文| 在线亚洲欧美专区二区| 91久久中文| 亚洲高清av| 亚洲第一精品在线| 欧美二区在线播放| 免费观看日韩|