B3647求调
  • 板块灌水区
  • 楼主lylcpp
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/18 19:25
  • 上次更新2025/1/18 19:32:50
查看原帖
B3647求调
1124898
lylcpp楼主2025/1/18 19:25

rt

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits>
#include<vector>

using namespace std;

int n, m;
const int INF = numeric_limits<int>::max();
int e[102][102];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i == j) e[i][j] = 0;
			else e[i][j] = INF;
		}
	}
	for (int i = 0; i < m; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		e[u][v] = w;
		e[v][u] = w;
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			printf("%d ", e[i][j]);
		printf("\n");
	}
	return 0;
}
2025/1/18 19:25
加载中...