SCU 4444 Travel (补图最短路)】的更多相关文章

Travel The country frog lives in has \(n\) towns which are conveniently numbered by \(1, 2, \dots, n\). Among \(\frac{n(n - 1)}{2}\) pairs of towns, \(m\) of them are connected by bidirectional highway, which needs \(a\) minutes to travel. The other…
Travel The country frog lives in has n towns which are conveniently numbered by 1,2,…,n . Among n(n−1)2 pairs of towns, m of them are connected by bidirectional highway, which needs a minutes to travel. The other pairs are connected by railway, which…
题意: 一个完全图,有n个点,其中m条边是权值为a的无向边,其它是权值为b的无向边,问从1到n的最短路. 思路: 首先判断1和n被哪种边连通. 如果是被a连通,那么就需要全部走b的边到达n,选择最小的: 被b连通,需要走全部为a的边到达n,选择最小的. 第二种情况,用输入的边跑dijkstra: 但是第一种情况边太多,所以并不能单纯的用最短路. 可以想到的是,对于第二种情况,一个点只会经过一次. 所以用一个set来存还未访问过的点,进行bfs. 每次从队列中取出一个点x,把set中与x以a边相连…
给你一个一共由两种边的完全图 要求你求1到N的最短路 q队列为前沿队列(已探索过且最外围的点)  p队列为未探索队列(未探索过的点) depth这个数组的用法并不是代表实际上这个点在第几层 而是防止死循环 保证每次通过前沿的一个点都只会遍历p中每个点一次 #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ; ; int n,m,a,b,nm,qwq; int head[maxn]; ll dis[maxn…
Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 689    Accepted Submission(s): 238 Problem Description In graph theory, the complement of a graph G is a graph H on the same vertic…
题意:给你n个点,m条无向边,问你这n个点构成的完全图,不用那m条边,由一个s出现的单源最短路 解题思路:首先,暴力建图不行,点太多,那么我们就按照它的规则来,把m条边建好,但是建的这个图表示不走的方法,然后我们需要用一个东西来保存去除这些直接相连的边的其它点,用set 代码: #include<iostream> #include<algorithm> #include<cstring> #include<set> #include<queue>…
传送门 题意简述:给出一张nnn个点的完全图,有mmm条边边权为aaa其余点边权为bbb,问从111到nnn的最短路. 思路:分类讨论一波即可. (1,n)(1,n)(1,n)的边权为aaa,那么只用求从111到nnn不经过给出边的最短路,这个用set+bfsset+bfsset+bfs解决. (1,n)(1,n)(1,n)的边权为bbb,那么只用求从111到nnn经过给出边的最短路,上spfaspfaspfa或者dijkstradijkstradijkstra 代码: #include<bit…
题目链接:hdu5876 Sparse Graph 详见代码.. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<set> using namespace std; ; const int inf = 0x3f3f3f3f; int n, m; vector<vector<int…
题意: 给出一个图的所有边,每次从图中删除一条边,求任意点对的路径总和(求完了就将边给补回去).(有重边) 思路: #include <bits/stdc++.h> using namespace std; , INF=0x7f7f7f7f; int mapp[N][N]; bool vis[N]; //是否存在队列中 int dest[N]; vector<pair<int,int> > vect; int n, m; int num[N]; void spfa(in…
BFS+链表 代码改自某博客 #include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<string> #include<map> #include<set> #include<vector> #include<queue> using nam…