|
|
|
@ -0,0 +1,73 @@
|
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 110;
|
|
|
|
|
#define INF 0x7ffffff
|
|
|
|
|
/**
|
|
|
|
|
分析:模板题,理解floyd 的在 i , j 路径中没有包含k(因为此时k未用来更新),即可写出最小环
|
|
|
|
|
在INF这里wa了两发,习惯值 1e9 不是最大值(查找时判断一下可以避免,但。。。懒了)
|
|
|
|
|
*/
|
|
|
|
|
int n, m;
|
|
|
|
|
int mp[N][N];
|
|
|
|
|
int g[N][N];
|
|
|
|
|
int path[N][N];
|
|
|
|
|
int ans[N];
|
|
|
|
|
int cnt;
|
|
|
|
|
int mm;
|
|
|
|
|
void floyd() {
|
|
|
|
|
mm = INF;
|
|
|
|
|
for (int k = 1; k <= n; k++) {
|
|
|
|
|
for (int i = 1; i < k; i++) {
|
|
|
|
|
for (int j = i + 1; j < k; j++) {
|
|
|
|
|
int x = g[i][j] + mp[k][i] + mp[k][j];
|
|
|
|
|
if (x < mm) {
|
|
|
|
|
mm = x;
|
|
|
|
|
int tmp = j;
|
|
|
|
|
cnt = 0;
|
|
|
|
|
|
|
|
|
|
while (tmp != i) {
|
|
|
|
|
ans[cnt++] = tmp;
|
|
|
|
|
tmp = path[i][tmp];
|
|
|
|
|
}
|
|
|
|
|
ans[cnt++] = i;
|
|
|
|
|
ans[cnt++] = k;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
for (int j = 1; j <= n; j++) {
|
|
|
|
|
if (g[i][j] > g[i][k] + g[k][j]) {
|
|
|
|
|
g[i][j] = g[i][k] + g[k][j];
|
|
|
|
|
path[i][j] = path[k][j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
while (cin >> n >> m) {
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
for (int j = 1; j <= n; j++) {
|
|
|
|
|
g[i][j] = mp[i][j] = INF;
|
|
|
|
|
path[i][j] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
|
int a, b, c;
|
|
|
|
|
cin >> a >> b >> c;
|
|
|
|
|
g[a][b] = g[b][a] = min(g[a][b], c); // 防重边
|
|
|
|
|
mp[a][b] = mp[b][a] = g[a][b];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
floyd();
|
|
|
|
|
|
|
|
|
|
if (mm == INF) {
|
|
|
|
|
puts("No solution.");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < cnt; ++i) printf("%d%s", ans[i], (i == cnt - 1) ? "\n" : " ");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|