30分求助!!!阳历美国
  • 板块P1119 灾后重建
  • 楼主J_Kobe
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/20 08:03
  • 上次更新2024/8/20 08:05:42
查看原帖
30分求助!!!阳历美国
844496
J_Kobe楼主2024/8/20 08:03
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, m, q, f[205][205], a[205];
void floyd(int k)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (f[i][j] > f[i][k] + f[k][j])
			{
				f[i][j] = f[j][i] = f[i][k] + f[k][j];
			}
		}
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i != j)
			{
				f[i][j] = INT_MAX;
			}
		}
	}
	for (int i = 1; i <= m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		f[u][v] = w;
		f[v][u] = w;
	}
	int now = 0;
	cin >> q;
	while (q--)
	{
		int x, y, t;
		cin >> x >> y >> t;
		while (a[now] <= t && now < n)
		{
			floyd(now);
			now++;
		}
		if (a[x] < t || a[y] < t || f[x][y] == INT_MAX)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << f[x][y] << endl;
		}
	}
	return 0;
}
/*

*/
2024/8/20 08:03
加载中...