版本比较
【题解】apart
正文
增加 102 行删除 1 行
12345634 行未改动41424344::::warning没有参考代码(作者玩 florr 去了)。::::## 一、Subtask Solution### I. 20 pts Solution34 行未改动我们考虑存在路径的情况,那么这个问题就成了之前那个环状问题,只要不改变最短路树结构即可拓展。完结撒花!12345634 行未改动4142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145::::warning难 debug(作者玩 florr 去了)。::::## 一、Subtask Solution### I. 20 pts Solution34 行未改动我们考虑存在路径的情况,那么这个问题就成了之前那个环状问题,只要不改变最短路树结构即可拓展。完结撒花!## 三、代码```cpp#include<bits/stdc++.h>#define int long long#define rep(K,F,T) for(int K = F;K <= T;K++)#define rip(K,F,T) for(int K = F;K >= T;K--)using namespace std;namespace florr{inline int read(){int x = 0, f = 1;char ch = getchar();while (ch<'0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();return x * f;}void write(int x){if (x < 0)putchar('-'), x = -x;if (x > 9)write(x / 10);putchar(x % 10 + '0');return;}}using namespace florr;const int INF = (int)4e18;signed main(){freopen("apart.in", "r", stdin);freopen("apart.out", "w", stdout);int T = read();while (T--){int n = read(), m = read();vector<array<int, 3>> e(m);vector<vector<pair<int, int>>> g(n + 1);for (auto &[u, v, w] : e){u = read();v = read();w = read();if (u != v){g[u].push_back({v, w});g[v].push_back({u, w});}}vector<vector<int>> d(n + 1, vector<int>(n + 1, INF));rep(s, 1, n){priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;d[s][s] = 0;pq.push({0, s});while (!pq.empty()){auto [dd, u] = pq.top();pq.pop();if (dd > d[s][u])continue;for (auto [v, w] : g[u])if (d[s][v] > dd + w){d[s][v] = dd + w;pq.push({dd + w, v});}}}int ans2 = 0;rep(i, 1, n)rep(j, 1, n)ans2 = max(ans2, 2 * d[i][j]);for (auto &[u, v, w] : e)rep(k, 1, n)ans2 = max(ans2, d[u][k] + d[v][k] + w);rep(i, 0, m - 1)rep(j, i + 1, m - 1){auto [u, v, w] = e[i];auto [a, b, c] = e[j];ans2 = max(ans2, w + c + min(d[u][b] + d[v][a], d[v][b] + d[u][a]));}write(ans2 / 2);putchar('.');putchar((ans2 & 1) ? '5' : '0');putchar('\n');}return 0;}```