2021.11.03 P2886 [USACO07NOV]Cow Relays G(矩阵+floyed) [P2886 USACO07NOV]Cow Relays G - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题意: 给出一张无向连通图,求S到E经过k条边的最短路. 分析: 对于floyed,在第k个点时,任意的i到j之间的最短路已经经过了(k-1)个点.当fa[i] [j]经过了x条边,fb[i] [j]经过了y条边,想要算出经过了x+y条边,只需要按照floyed的算…
本题就是求两点间只经过n条边的最短路径,定义广义的矩阵乘法,就是把普通的矩阵乘法从求和改成了取最小值,把内部相乘改成了相加. 代码包含三个内容:广义矩阵乘法,矩阵快速幂,离散化: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int INF=0x3f3f3f3f; 4 const int N=120; 5 int Hash[1000005],cnt=0;//用于离散化 6 struct matrix{ 7 int m[N][N…
题目 For their physical fitness program, \(N (2 ≤ N ≤ 1,000,000)\) cows have decided to run a relay race using the \(T (2 ≤ T ≤ 100)\) cow trails throughout the pasture. Each trail connects two different intersections \((1 ≤ I1_i ≤ 1,000; 1 ≤ I2_i ≤ 1,…
题目大意 洛谷链接 给定一张\(T\)条边的无向连通图,求从\(S\)到\(E\)经过\(N\)条边的最短路长度. 输入格式 第一行四个正整数\(N,T,S,E\),意义如题面所示. 接下来\(T\)行每行三个正整数\(w,u,v\)分别表示路径的长度,起点和终点. 输出格式 一行一个整数表示图中从\(S\)到\(E\)经过\(N\)条边的最短路长度. 数据范围 对于所有的数据,保证\(1\le N\le 10^6,2\le T\le 100\). 所有的边保证\(1\le u,v\le 100…
题目大意 给出一张无向连通图(点数小于1000),求S到E经过k条边的最短路. 算法 这是之前国庆模拟赛的题 因为懒 所以就只挑一些题写博客 在考场上写了个dp 然后水到了50分 出考场和神仙们一问才知道是lyd蓝书原题 我们考虑有两个floyd的矩阵 A代表走了x条边的矩阵 B代表走了y条边的矩阵 那么我们想求出C这个代表走了(x + y)这个矩阵的值呢 我们考虑这么一个式子 \(C[i][j] = min( A[i][k] + B[k][j] )\) 然后我们发现 其中\(A[i][k] +…
2021.11.03 P6175 无向图的最小环问题 P6175 无向图的最小环问题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题意: 给定一张无向图,求图中一个至少包含 33 个点的环,环上的节点不重复,并且环上的边的长度之和最小.该问题称为无向图的最小环问题.在本题中,你需要输出最小的环的边权和.若无解,输出 No solution. 分析: 对于floyed,在第k个点时,任意的i到j之间的最短路已经经过了(k-1)个点. 代码如下: #include<cstdio…
map+floyed+矩阵乘法(倍增floyed) # include <stdio.h> # include <stdlib.h> # include <iostream> # include <algorithm> # include <string.h> # include <map> # define IL inline # define RG register # define Fill(a, b) memset(a, b,…
传送门 矩阵快速幂,本质是floyd 把 * 改成 + 即可 注意初始化 因为只有100条边,所以可以离散化 #include <cstdio> #include <cstring> #include <algorithm> #define N 101 #define min(x, y) ((x) < (y) ? (x) : (y)) int n, t, s, e, cnt; int x[N], y[N], z[N], a[N]; struct Matrix {…
题目描述 For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture. Each trail connects two different intersections (1 ≤ I1i ≤ 1,000; 1 ≤ I2i ≤ 1,000), each…
!:自环也算一条路径 矩阵快速幂,把矩阵乘法的部分替换成Floyd(只用一个点扩张),这样每"乘"一次,就是经过增加一条边的最短路,用矩阵快速幂优化,然后因为边数是100级别的,所以把点hash一下最多剩下200个 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=205,inf=1e9; int n,m,s,t,g[N],…