本文共 1906 字,大约阅读时间需要 6 分钟。
#include #include #include #include #include #include
题意:
想去一个地方又不知道应该乘什么公交车,在什么地方转车,在什么地方下车,请帮助他用最短的时间到达目的地。
题解:
练习SPFA。就是多了一个map将 string 用 int 代替。
一开始我判断是否输出-1时是这样判断:
if(dis[ed] < INF)
return ans = dis[ed];
else
return 0;
…
if(SPFA())
cout << ans << endl;
else
cout << “-1” << endl;
错在 当初始位置和末尾相同的时候 dis[ed] = 0, 会return 0而输出-1。还有就是对string进行编号的时候,num要写在最外边,使地点单词与数字一一对应。
转载地址:http://vctpi.baihongyu.com/