20pts求调
查看原帖
20pts求调
930129
xqh2010楼主2025/7/31 19:34

ac on #4,#5

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,opt,x,w,fa[N],t[N];
vector<int>g[N];
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void print(int x){
	if(x>9){
		print(x/10);
	}
	putchar(x%10+'0');
	return ;
}
inline void build(int u,int father){
	fa[u]=father;
	for(auto v:g[u]){
		if(v==father){
			continue;
		}
		build(v,u);
		t[u]=max(t[u],t[v]);
	}
	return ;
}
inline void update(int u){
	if(w>t[u]){
		t[u]=w;
		if(u==1){
			return ;
		}
		update(fa[u]);
	}
	return ;
}
signed main(){
	n=read();
	m=read();
	for(int i=1;i<=n;i++){
		t[i]=read();
	}
	for(int i=1,u,v;i<n;i++){
		u=read();
		v=read();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	build(1,0);
	while(m--){
		opt=read();
		x=read();
		if(opt==1){
			w=read();
			update(x);
		}else{
			print(t[x]);
			putchar(10);
		}
	}
	return 0;
}
2025/7/31 19:34
加载中...