제출 #1150899

#제출 시각아이디문제언어결과실행 시간메모리
1150899jiahngCat Exercise (JOI23_ho_t4)C++20
0 / 100
6 ms12100 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define ll int
typedef pair<int,int> pi;
typedef pair<ll,ll> pill;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define INF (ll)1e18
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
typedef pair <pi,pi> pipi;
#define maxn 500010

int N,M,K,sr,sc,gr,gc;
int dp[maxn],A[maxn],B[maxn];
vi adj[maxn];
int dfs(int x,int p, int h){
	int ans = dp[x];
	aFOR(i,adj[x]) if (i != p && A[i] <= h){
		ans = max(ans, 1 + dfs(i,x,h));
		
	}
	return ans;
}
int32_t main(){
	fast;
	cin >> N;
	FOR(i,1,N) cin >> A[i];
	FOR(i,1,N) B[A[i]] = i;
	int a,b;
	FOR(i,1,N-1){
		cin >> a >> b;
		adj[a].pb(b); adj[b].pb(a);
	}
	FOR(i,1,N){
		int x = B[i];
		dp[x] = dfs(x,-1,i);		
	}
	FOR(i,1,N) cout << dp[i] << ' ';
	cout << '\n';
	cout << dp[B[N]];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...