标签:scanf 代码 数据 mat efi int pre 题解 路径
$ ans = (dis[i][k] + dis[i][k] - dis[i][j] ) / 2 $
300数据乱搞之——最短路求解直径
300数据乱搞之——n^3的最短路求法 求 n的唯一路径求法
300数据乱搞之——n^2枚举路径F
300数据乱搞之——AC
300数据乱搞代码:
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 0x3fffffff
using namespace std;
int n, s, G[310][310], dis[310][310], u, v, k, ans;
int main(){
cin >> n >> s;
memset(dis, 0x3f, sizeof(dis));
for(int i = 1; i < n; i++){
dis[i][i] = 0;
scanf("%d%d%d", &u, &v, &k);
G[u][v] = G[v][u] = k;
dis[u][v] = dis[v][u] = k;
}
dis[n][n] = 0;
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
ans = 1061109567;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(dis[i][j] <= s){
int maxlen = 0;
for(int k = 1; k <= n; k++){
maxlen = max(maxlen, (dis[i][k] + dis[j][k] - dis[i][j]) / 2);
}
ans = min(ans, maxlen);
}
}
}
cout << ans << endl;
return 0;
}
标签:scanf 代码 数据 mat efi int pre 题解 路径
原文地址:https://www.cnblogs.com/ZhengkunJia/p/13581485.html