题意:问两个城市是否相连,不相连输出not connected,否则输出两个城市间的最短距离
思路:用并查集判断两个城市的连通性,如果联通则做法和lca一样,但是注意的一点是地图不连通的话,我们要将所有点都建起来,就要加一个模拟的点,将所有图串起来,很好处理的,看一下就会了
#include #include #include #include #include #include using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int maxn=10010; struct edge{ int to,cost; edge(int a,int b){to=a;cost=b;} }; vectorg[maxn]; int dp[maxn*2][20],l[maxn*2],e[maxn*2],dis[maxn],h[maxn],f[maxn]; bool vis[maxn]; int n,k; void dfs(int t,int deep){ k++;e[k]=t;l[k]=deep;h[t]=k; for(unsigned int i=0;iri) swap(le,ri); int kk=0; while((1
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/605547.html