WA莫名奇妙的负数 0pts!
查看原帖
WA莫名奇妙的负数 0pts!
486441
13833925596mm楼主2023/3/26 10:48
#include<bits/stdc++.h>
using namespace std;
int n,m,a[201],nm,f[201][201];
int main(){
	cin>>n>>m;
	int x,y,z;
    memset(f,127,sizeof(f));
	for(int i=0;i<n;i++){
		cin>>a[i];
		f[i][i]=0;
	}
	for(int i=1;i<=m;i++){
		cin>>x>>y>>z;
		f[x][y]=z;
		f[y][x]=z;
	}
	cin>>nm;
	int t;
    int last=0;
	for(int itn=1;itn<=nm;itn++){
	    cin>>x>>y>>t;
		while(last<n && a[last]<=t){
		    for(int i=0;i<n;i++){
		        for(int j=0;j<n;j++){
                    if(a[i]<=t && a[j]<=t){
                        f[i][j]=min(f[i][j],f[i][last]+f[last][j]);
                    }
		        }
		    }
            last++;
		}
		if(a[x]>t || a[y]>t) cout<<-1<<endl;
		else if(f[x][y]>99999999) cout<<-1<<endl;
		else cout<<f[x][y]<<endl;
	}
	return 0;
}
2023/3/26 10:48
加载中...