噪音恐惧症
查看原帖
噪音恐惧症
1036000
Ojld楼主2023/10/26 20:21
#include <iostream>
#include <cstring>
using namespace std;

const int N = 210  ;

int  dist[N][N]; 
int n , m , k,cnt;

void floyd(){
	for(int  k = 1 ; k <= n ; k++){
		for(int i = 1 ;i <= n ;i ++){
			for(int j = 1 ;j <= n ;j ++){
				dist[i][j] = min (dist[i][j] ,max( dist[i][k] , dist[k][j]));
			}
		}
	}
}
int main(){
	
	while(cin>>n>>m>>k  && n && m && k){
	memset(dist, 0x3f , sizeof dist);
	for(int i = 1 ;i <= n ; i++)dist[i][i] = 0;
	while(m--){
		int  a , b ,c ;
		cin>>a>>b>>c;
		dist[a][b] =  min(dist[a][b] ,c);
		dist[b][a] = min(dist[b][a] , c);
	}
	floyd();
	cout<<"case #"<<++cnt;
	while(k--){
		int a , b ;
		cin>>a>>b;
		if(dist[a][b] > 0x3f3f3f3f / 2) cout<<"no path"<<endl;
		else cout<<dist[a][b]<<endl;
	}
	cout<<endl;
	}
}	
2023/10/26 20:21
加载中...