最近没有心情写
颓了一周( ⊙ o ⊙ )!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<queue>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e5+10,M=2e5+10,inf=0x3f3f3f;
typedef long long ll;
struct edge{
int from,to,val,next;
edge(int from=0,int to=0,int val=0,int next=0):from(from),to(to),val(val),next(next){}
}e[M];
int len=0,last[N],n,q;
ll val[N];
void add(int from,int to,int val){
e[++len]=edge(from,to,val,last[from]); last[from]=len;
}
int fa[N],dep[N];
bool vis[N];
void dfs(int from){
for(int i=last[from];i;i=e[i].next){
int id=e[i].to;
if(id!=fa[from]){
fa[id]=from;
dep[id]=dep[from]+1;
dfs(id);
}
}
}
bool solve(int from,int to){
int num=0;
ll pre[N];
while(from!=to&&num<=50){
if(dep[from]>dep[to]) pre[++num]=val[from],from=fa[from];
else pre[++num]=val[to],to=fa[to];
}
if(num>=50) return 1;
pre[++num]=val[from];
sort(pre+1,pre+num+1);
fo(i,1,num-2) if(pre[i]+pre[i+1]>pre[i+2]) return 1;
return 0;
}
int main(){
scanf("%d%d",&n,&q);
fo(i,1,n) scanf("%lld",&val[i]);
fo(i,1,n-1){
int a,b;
scanf("%d%d",&a,&b);
add(a,b,1);
add(b,a,1);
}
dfs(1);
int u,v,w;
fo(i,1,q){
scanf("%d%d%d",&u,&v,&w);
if(!u){
if(solve(v,w)) printf("Y\n");
else printf("N\n");
}
if(u) val[v]=w;
}
return 0;
}