悬赏一贯
查看原帖
悬赏一贯
550933
Tjaweiof楼主2023/8/8 19:37
#include <bits/stdc++.h>
using namespace std;
int c, s, q, u, v, w, tot = 0;
long long d[101][101];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while (1){
		cin >> c >> s >> q;
		if (c == 0 && s == c && q == 0){
			break;
		} else {
			if (tot){
				cout << endl << endl;
			}
			cout << "Case #" << ++tot << endl;
		}
		for (int i = 1; i <= c; i++){
			for (int j = 1; j <= c; j++){
				d[i][j] = 0x3f3f3f3f;
			}
		}
		for (int i = 1; i <= c; i++){
			d[i][i] = 0;
		}
		while (s--){
			cin >> u >> v >> w;
			d[u][v] = w;
			d[v][u] = w;
		}
		for (int k = 1; k <= c; k++){
			for (int i = 1; i <= c; i++){
				for (int j = 1; j <= c; j++){
					d[i][j] = min(d[i][j], max(d[i][k], d[k][j]));
				}
			}
		}
		while (q--){
			cin >> u >> v;
			if (d[u][v] == 0x3f3f3f3f){
				cout << "no path";
			} else {
				cout << d[u][v];
			}
			if (q){
				cout << endl;
			}
		}
	}
	return 0;
}

九九海子把

2023/8/8 19:37
加载中...