为什么除了第一个其他只输出0??!1
查看原帖
为什么除了第一个其他只输出0??!1
615236
FF_pigeon楼主2023/1/24 14:47

调了半个月了 qwq

#include<bits/stdc++.h>
using namespace std;
int mp[205][205],n,m,a[205],q;
int main()
{
	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)mp[i][j]=0x3f3f3f3f;
		}
	}
	for(int i=0;i<m;i++)
	{
		int u,v,w;
		cin >> u >> v >> w;
		mp[u][v]=w;
		mp[v][u]=w;
	}
	cin >> q;
	int x,y,t;
	while(q--)
	{
		cin >> x >> y >> t;
		int tmp=0;
		while(a[tmp]<=t||tmp<n)
		{
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(mp[i][j]>mp[i][tmp]+mp[tmp][j])
					mp[i][j]=mp[j][i]=mp[i][tmp]+mp[tmp][j];
				}
			}
			tmp++;
		}
		if(a[x]>t||a[y]>t||mp[x][y]==0x3f3f3f3f)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << mp[x][y] << endl;
		}
	}
	return 0;
}

2023/1/24 14:47
加载中...