无向图 用map 起点和终点可能一样 数组不能开太大 WA了好多发

Sample Input
6
xiasha westlake //起点 终点
xiasha station 60
xiasha ShoppingCenterofHangZhou 30
station westlake 20
ShoppingCenterofHangZhou supermarket 10
xiasha supermarket 50
supermarket westlake 10
-1

Sample Output
50

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <algorithm>
# include <cmath>
# include <queue>
# include <map>
# define LL long long
using namespace std ; const int INF=0x3f3f3f3f;
const int MAXN=; int n ;
map<string,int> mp ;
bool vis[MAXN];
int cost[MAXN][MAXN] ;
int lowcost[MAXN] ; void Dijkstra(int beg)
{
for(int i=;i<n;i++)
{
lowcost[i]=INF;vis[i]=false;
}
lowcost[beg]=;
for(int j=;j<n;j++)
{
int k=-;
int Min=INF;
for(int i=;i<n;i++)
if(!vis[i]&&lowcost[i]<Min)
{
Min=lowcost[i];
k=i;
}
if(k==-)
break ;
vis[k]=true;
for(int i=;i<n;i++)
if(!vis[i]&&lowcost[k]+cost[k][i]<lowcost[i])
{
lowcost[i]=lowcost[k]+cost[k][i]; }
} } int main ()
{
// freopen("in.txt","r",stdin) ;
int m ;
while(cin>>m)
{
if (m == -)
break ;
mp.clear() ;
string s1 ,s2 ;
int i , j , w ;
for (i = ; i < MAXN ; i++)
for (j = ; j < MAXN ; j++)
{
if (i == j)
cost[i][j] = ;
else
cost[i][j] = INF ;
} cin>>s1>>s2 ;
mp[s1] = ;
mp[s2] = ;
n = ;
bool flag = ;
if (s1 == s2)
flag = ;
while(m--)
{
cin>>s1>>s2>>w ;
if (!mp[s1])
mp[s1] = n++ ;
if (!mp[s2])
mp[s2] = n++ ;
if (w < cost[mp[s1]-][mp[s2]-])
{
cost[mp[s1]-][mp[s2]-] = w ;
cost[mp[s2]-][mp[s1]-] = w ;
} }
n-- ;
if (flag)
{
cout<<<<endl ;
continue ;
}
Dijkstra() ; if (lowcost[] != INF)
cout<<lowcost[]<<endl ;
else
cout<<-<<endl ; } return ;
}

hdu 2112 map+Dijkstra的更多相关文章

  1. HDU 2112 Today(Dijkstra+map)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 题目大意: 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050 ...

  2. 【hdu 2112】 HDU Today ( 最短路 Dijkstra)(map)

    http://acm.hdu.edu.cn/showproblem.php?pid=2112 这道题给了一个将字符串与int对应的思路,就是使用map 这道题答案对了,但是没有AC,我也不知道为什么. ...

  3. hdu 2112 HDU Today(map与dijkstra的结合使用)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. hdu 2112 (最短路+map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others)  ...

  5. HDU 2112 HDU Today(Dijkstra)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others ...

  6. HDU Today HDU杭电2112【Dijkstra || SPFA】

    http://acm.hdu.edu.cn/showproblem.php?pid=2112 Problem Description 经过锦囊相助,海东集团最终度过了危机,从此.HDU的发展就一直顺风 ...

  7. HDU 2112 HDU Today (Dijkstra算法)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU 2112 HDU Today(最短路径+map)

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. HDU - 2112 HDU Today Dijkstra

    注意: 1.去重边 2.终点和起点一样,应当输出0 3.是无向图 AC代码 #include <cstdio> #include <cmath> #include <al ...

随机推荐

  1. Linux记录-CentOS配置Docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何 ...

  2. Easyui和IE浏览器的兼容问题

    现在Easyui版本已经更新到1.3.4,今天下载最新的版本,同时下载了IETestert软件,分别模拟IE浏览器5.5,6.0,7.0,8.0和9.0的环境进行测试. Easyui1.3.3与1.3 ...

  3. Phalcon的Mvc结构及启动流程(部分源码分析)

    Phalcon本身有支持创建多种形式的Web应用项目以应对不同场景,包括迷你应用.单模块标准应用.以及较复杂的多模块应用 创建项目 Phalcon环境配置安装后,可以通过命令行生成一个标准的Phalc ...

  4. datetimepicker bootstrap的时间插件显示位置问题及其他配置

    位置问题: 在bootstrap中用 datetimepicker 时默认是在输入框下面弹出的, 但是遇到输入框在屏幕最下面时,日期选择框会有一部分在屏幕下面,显示不了,因此需要能够从上面弹出. 可以 ...

  5. Python3.X爬虫

    1.Python很有名,但是一直没在实际项目中用过,今天花30分钟学习下.去Python官网https://www.python.org/downloads/ 2.2.X与3.X版本相差比较大,新手用 ...

  6. ICS Hack Tools

    参考链接:http://icstraining.org/en/security-tools/configurations ICS-Security-Tool: https://github.com/I ...

  7. rest framework错误笔记——身份验证和权限

    按照官网教程(http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/)走到最后一步验证时,命令窗 ...

  8. 最新Linux系统Ubuntu16.04搭建HUSTOJ(LAMP环境)

    应该跟着下面的步骤就OK了吧! 1.升级软件库,更新软件 打开终端 输入 sudo apt-get update sudo apt-get upgrade 2.安装mysql5.7 (注意:mysql ...

  9. hdp3: regionserver running as process 3170. Stop it first.

    1 启动hbase报错 hdp3: regionserver running as process 3170. Stop it first. 2 始终没有发现错误日志 3 jps没有发现hbase的r ...

  10. FPN-Feature Pyramid Networks for Object Detection

    FPN-Feature Pyramid Networks for Object Detection 标签(空格分隔): 深度学习 目标检测 这次学习的论文是FPN,是关于解决多尺度问题的一篇论文.记录 ...