
https://www.acwing.com/problem/content/description/922/
根据每一条线,建边,注意是有向边。求最短路,最短路的结果是最少的坐车次数,减1即为最少的换乘次数。
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
int g[N][N],dist[N],st[N];
int n,m;
string s,a;
void Dijkstra()
{
memset(dist,0x3f,sizeof dist);
dist[1]

该程序使用Dijkstra算法解决了一个图论问题,即在给定城市间的公交线路中找到从起点到终点的最少换乘次数。输入包括城市的数量、线路信息,通过构建有向图并计算最短路径来得出最少的坐车次数,最终输出结果为最少的换乘次数。
最低0.47元/天 解锁文章
323

被折叠的 条评论
为什么被折叠?



