比赛 CSP2023-S模拟赛 评测结果 AAAAAAWAAWWWWWWWWWWW
题目名称 坡伊踹 最终得分 40
用户昵称 sweetD 运行时间 3.372 s
代码语言 C++ 内存使用 21.84 MiB
提交时间 2023-10-17 19:33:58
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100,M=1e3+100;
#define ll long long
ll num[N],min_dis[M][M],dis[N],tot[N];
int n,q,u,v,value;
ll maxx,now_max;
struct INT{
	int first,last,way_value;
}edge[N];
int cnt;
bool flag_1,flag_2;
int main(){
	freopen("poitry.in","r",stdin);
	freopen("poitry.out","w",stdout);
	scanf("%d %d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%lld",&num[i]);
	if(n<=1e3+10){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i!=j){
					min_dis[i][j]=1e16;
				}
			}
		}
		for(int i=1;i<n;i++){
			scanf("%d %d %d",&u,&v,&value);
			min_dis[u][v]=value;
			min_dis[v][u]=value;
		}
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					min_dis[i][j]=min(min_dis[i][k]+min_dis[k][j],min_dis[i][j]);
				} 
			}
		}
		while(q--){
			maxx=1e16;
			scanf("%d %d",&u,&v);
			for(int i=1;i<=n;i++){
				if(min_dis[u][i]+min_dis[i][v]==min_dis[u][v]){
					if(min_dis[u][i]==1e16||min_dis[i][v]==1e16||min_dis[u][v]==1e16)continue;
					now_max=max(num[i],min_dis[i][u]);
					maxx=min(maxx,now_max);
				}
			}
			printf("%lld\n",maxx);
		}
		return 0;
	}
	else{
		flag_1=flag_2=true; 
		for(int i=1;i<n;i++){
			scanf("%d %d %d",&edge[i].first,&edge[i].last,&edge[i].way_value);
			if(edge[i].first!=1)flag_1=false;
			if(edge[i].first+1!=edge[i].last)flag_2=false;
			dis[edge[i].last]=edge[i].way_value;
			tot[i]=tot[i-1]+edge[i].way_value;
		}
		if(flag_1){
			while(q--){
				scanf("%d %d",&u,&v);
				if(u==1){
					printf("%lld\n",min(max(num[1],(ll)0),max(num[v],dis[v])));
				}
				else{
					printf("%lld\n",min(max(num[u],(ll)0),min(max(num[1],dis[u]),max(num[v],dis[u]+dis[v]))));
				}
			}
			return 0;
		}
		else{
			while(q--){
				scanf("%d %d",&u,&v);
				for(int i=min(u,v);i<=max(u,v);i++){
					
				}
			}
		}
	}
	return 0;
}