样例过了交上去全wa求调
  • 板块P1119 灾后重建
  • 楼主1nes
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/26 17:57
  • 上次更新2024/8/26 20:35:05
查看原帖
样例过了交上去全wa求调
1114867
1nes楼主2024/8/26 17:57
// P1119 灾后重建
// Memory Limit: 125 MB
// Time Limit: 1000 ms

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e2 + 3;
int n , m , q;
int f[N][N][N];
int t[N];
int main(){
	cin >> n >> m;
	for(int i = 0 ; i < n ; i++){
		cin >> t[i];
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++){
			if(i != j)	f[0][i][j] = 1e9 + 7;
		}
	}
	for(int i = 1 ; i <= m ; i++){
		int x , y , z;
		cin >> x >> y >> z;
		f[0][x][y] = f[0][y][x] = z;
	}
	//floyd
	for(int k = 1 ; k < n ; k++){
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				f[k][i][j] = min(f[k - 1][i][j] , f[k - 1][i][k] + f[k - 1][k][j]);
			}
		}
	}
	// 处理询问
	cin >> q;
	for(int i = 1 ; i <= q ; i++){
		int x , y , z;
		cin >> x >> y >> z;
		if(t[x] > z || t[y] > z)	cout << -1;
		else{
			int pos = upper_bound(t , t + n , z) - (t + 1);
			if(f[pos][x][y] == 1e9 + 7)	cout << -1;
			else	cout << f[pos][x][y];
		}
		cout << '\n';
	}
	return 0;
}
2024/8/26 17:57
加载中...