因为题目给了边的信息,所以比较适用bell-man的方法

 /*
 ID: yingzho1
 LANG: C++
 TASK: comehome
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>

 using namespace std;
 #define inf 10000000

 ifstream fin("comehome.in");
 ofstream fout("comehome.out");

 int N;
 struct edge {
     char s, d;
     int e;
     edge(int a, int b, int c) : s(a), d(b), e(c) { }
     edge() : s(), d(), e() { }
 };
 map<char, int> dis;
 ;

 int main()
 {
     fin >> N;
     vector<edge> path(*N);

     ; i < N; i++) {
         char s, d;
         int e;
         fin >> s >> d >> e;
         path[edgenum].s = s;
         path[edgenum].d = d;
         path[edgenum++].e = e;
         path[edgenum].s = d;
         path[edgenum].d = s;
         path[edgenum++].e = e;
     }
     //for (int i = 0; i < edgenum; i++) {
         //cout << "s: " << path[i].s << ", d: " << path[i].d << ", e: " << path[i].e << endl;
     //}
     for (char i = 'a'; i <= 'z'; i++) dis[i] = inf;
     for (char i = 'A'; i <= 'Z'; i++) dis[i] = inf;
     dis[;
     bool flag;
     ; i < edgenum; i++) {
         flag = false;
         ; j < edgenum; j++) {
             if (dis[path[j].d] > dis[path[j].s]+path[j].e) {
                 dis[path[j].d] = dis[path[j].s]+path[j].e;
                 flag = true;
                 //cout << "dis[" << path[j].d << "]: " << dis[path[j].d] << endl;
             }
         }
         if (!flag) break;
     }
     int min_path = inf;
     char min_index;
     ; i < edgenum; i++) {
         if (path[i].s >= 'A' && path[i].s < 'Z' && min_path > dis[path[i].s]) {
             min_path = min(min_path, dis[path[i].s]);
             //cout << path[i].s << "'s dis: " << dis[path[i].s] << endl;
             min_index = path[i].s;
         }
     }
     fout <<  min_index << " " << min_path << endl;

     ;
 }

最新文章

  1. hibernate一对一主键单向关联
  2. 关于网络-get/post
  3. redis-key2
  4. 图表控件MsChart使用demo
  5. python os模块使用方法
  6. SQL中一种类似GUID值的函数实现
  7. 网址、URL
  8. .rdp 文件参数详解
  9. [LeetCode] 134. Gas Station 解题思路
  10. HdU 4046 Panda 段树
  11. 新书发布《每天5分钟玩转Docker容器技术》
  12. 设计模式复习小结一(Strategy Pattern/Observer Pattern/Decorator Patter/Factory Pattern)
  13. 最短路径---dijkstra算法模板
  14. koa-router 源码由浅入深的分析(7.4.0版本的)
  15. redis操作(String,Hash,List,Set,其他操作)
  16. 急速安装lnmp 编译版本
  17. HDU4288-STL模拟
  18. python实现Telnet远程登陆到设备并执行命令
  19. rocketMq排坑:如何设置rocketMq broker的ip地址
  20. 第七篇:几个经典的TCP通信函数

热门文章

  1. springmvc返回jsp源代码解决办法
  2. 使用个推的时候出现Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
  3. 前端之JavaScript第一天学习(3)-JavaScript输出
  4. sourceInsight使用技巧,持续更新中~~~
  5. HDU 5800 To My Girlfriend 背包
  6. Matlab交集并集的实现
  7. if in hlsl
  8. c++ assert
  9. ActionScript基本语法讲解
  10. .NET设计模式(9):桥接模式(Bridge Pattern)(转)