|
|
|
@ -8,29 +8,27 @@ const int N = 110;
|
|
|
|
|
*/
|
|
|
|
|
int n, m;
|
|
|
|
|
int g[N][N];
|
|
|
|
|
int dis[N][N];
|
|
|
|
|
int dis[N][N]; // dp结果数组
|
|
|
|
|
int path[N][N];
|
|
|
|
|
int ans[N];
|
|
|
|
|
int cnt;
|
|
|
|
|
int mm;
|
|
|
|
|
int res = INF;
|
|
|
|
|
void floyd() {
|
|
|
|
|
mm = INF;
|
|
|
|
|
for (int k = 1; k <= n; k++) {
|
|
|
|
|
// dp
|
|
|
|
|
for (int i = 1; i < k; i++) {
|
|
|
|
|
for (int j = i + 1; j < k; j++) {
|
|
|
|
|
int x = dis[i][j] + g[k][i] + g[k][j];
|
|
|
|
|
if (x < mm) {
|
|
|
|
|
mm = x;
|
|
|
|
|
int tg = j;
|
|
|
|
|
cnt = 0;
|
|
|
|
|
for (int j = i + 1; j < k; j++) { // i,j,k序号由小到大
|
|
|
|
|
if (res > dis[i][j] + g[i][k] + g[k][j]) {
|
|
|
|
|
res = dis[i][j] + g[i][k] + g[k][j];
|
|
|
|
|
|
|
|
|
|
while (tg != i) {
|
|
|
|
|
ans[cnt++] = tg;
|
|
|
|
|
tg = path[i][tg];
|
|
|
|
|
int x = j, y = i;
|
|
|
|
|
cnt = 0;
|
|
|
|
|
while (x != y) {
|
|
|
|
|
ans[cnt++] = x;
|
|
|
|
|
x = path[i][x];
|
|
|
|
|
}
|
|
|
|
|
ans[cnt++] = i;
|
|
|
|
|
ans[cnt++] = k;
|
|
|
|
|
ans[cnt++] = y;
|
|
|
|
|
ans[cnt++] = k; // 序号最大的节点k
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -50,7 +48,7 @@ int main() {
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
for (int j = 1; j <= n; j++) {
|
|
|
|
|
dis[i][j] = g[i][j] = INF;
|
|
|
|
|
path[i][j] = i;
|
|
|
|
|
path[i][j] = i; // 这里也是不一样,需要思考与整理
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 读入边
|
|
|
|
@ -63,7 +61,7 @@ int main() {
|
|
|
|
|
|
|
|
|
|
floyd();
|
|
|
|
|
|
|
|
|
|
if (mm == INF) {
|
|
|
|
|
if (res == INF) {
|
|
|
|
|
puts("No solution.");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|