哪里错了啊?几乎和题解一样了
查看原帖
哪里错了啊?几乎和题解一样了
335890
Jason66661010楼主2020/5/15 21:17
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 210
#define INF 99999999
int edges[MAX][MAX];
int n, m,q;
int t[MAX];
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	cin >> n >> m;
	fill(edges[0], edges[0] + MAX*MAX, INF);
	for (int i = 0; i < n; i++)
		cin >> t[i];
	for (int i = 0; i < m; i++)
	{
		int x, y,z;
		cin >> x >> y>>z;
		edges[x][y] = edges[y][x] = z;
	}
	cin >> q;
	int now = 0;	
	for (int s = 0; s < q; s++)
	{
		int xx, yy, tt;
		cin >> xx >> yy >> tt;
		while (tt >=t[now] && now < n)
		{
				for (int i = 0; i < n; i++)
					for (int j = 0; j < n; j++)
						if (edges[i][j] > edges[i][now] + edges[now][j])
							edges[i][j]=	edges[j][i] = edges[i][now] + edges[now][j];
			now++;
		}
		if (t[xx] > tt || t[yy] >> tt)cout << -1 << endl;
		else 
		{
			if (edges[xx][yy] == INF)cout << -1<<endl;
			else cout << edges[xx][yy] << endl;
		}
	}


}

2020/5/15 21:17
加载中...