답안 #930675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930675 2024-02-20T09:17:37 Z Xiaoyang Cat Exercise (JOI23_ho_t4) C++17
31 / 100
219 ms 249384 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int prod(ll a,ll b) {return ll(a)*ll(b)%mod;}
int lowbit(ll x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}



const ll maxn=5555;
vector<ll>alist[maxn];
ll p[maxn],blocked[maxn];
ll dp[maxn];

ll dfs(ll u,ll fa){
	blocked[u]=1;
	ll tmp=0;
	for(auto x:alist[u]){
		if(x==fa)continue;
		if(blocked[x])continue;
		ll mx=x;
		bool vis[maxn];
		memset(vis,0,sizeof vis);
		vis[x]=1;
		ll dis[maxn];
		memset(dis,0,sizeof dis);
		dis[x]=1;
		queue<ll>q;
		q.push(x);
		while(!q.empty()){
			ll uu=q.front();
			q.pop();
			for(auto xx:alist[uu]){
				if(blocked[xx])continue;
				if(vis[xx])continue;
				if(p[xx]>p[mx])mx=xx;
				dis[xx]=dis[uu]+1;
				vis[xx]=1;
				q.push(xx);
			}
		}
		//rep(i,1,10)cout<<dis[i]<<" ";
		//cout<<endl;
		//debug(mx);
		tmp=max(tmp,dfs(mx,-1)+dis[mx]);
	}
	return dp[u]=tmp;
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;cin>>n;
	rep(i,1,n+1)cin>>p[i];
	rep(i,1,n){
		ll a,b;cin>>a>>b;
		alist[a].pb(b);
		alist[b].pb(a);
	}
	ll st=0;
	rep(i,1,n+1){
		if(p[i]>p[st])st=i;
	}
	memset(dp,0,sizeof dp);
	cout<<dfs(st,-1)<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 8 ms 15452 KB Output is correct
12 Correct 8 ms 14044 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 1 ms 1368 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 8 ms 15452 KB Output is correct
12 Correct 8 ms 14044 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 1 ms 1368 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 219 ms 249384 KB Output is correct
19 Correct 190 ms 226632 KB Output is correct
20 Correct 196 ms 226516 KB Output is correct
21 Correct 6 ms 2136 KB Output is correct
22 Correct 7 ms 2140 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 7 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 8 ms 15452 KB Output is correct
12 Correct 8 ms 14044 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 1 ms 1368 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 219 ms 249384 KB Output is correct
19 Correct 190 ms 226632 KB Output is correct
20 Correct 196 ms 226516 KB Output is correct
21 Correct 6 ms 2136 KB Output is correct
22 Correct 7 ms 2140 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 7 ms 1884 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 181 ms 174864 KB Output is correct
27 Correct 184 ms 175076 KB Output is correct
28 Correct 182 ms 175008 KB Output is correct
29 Correct 191 ms 174964 KB Output is correct
30 Correct 16 ms 8772 KB Output is correct
31 Correct 28 ms 14976 KB Output is correct
32 Correct 19 ms 10064 KB Output is correct
33 Correct 26 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 8 ms 15452 KB Output is correct
12 Correct 8 ms 14044 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 1 ms 1368 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 219 ms 249384 KB Output is correct
19 Correct 190 ms 226632 KB Output is correct
20 Correct 196 ms 226516 KB Output is correct
21 Correct 6 ms 2136 KB Output is correct
22 Correct 7 ms 2140 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 7 ms 1884 KB Output is correct
25 Runtime error 2 ms 1112 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Runtime error 2 ms 1116 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 1 ms 1368 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 856 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 8 ms 15452 KB Output is correct
12 Correct 8 ms 14044 KB Output is correct
13 Correct 8 ms 14428 KB Output is correct
14 Correct 1 ms 1368 KB Output is correct
15 Correct 1 ms 1368 KB Output is correct
16 Correct 2 ms 1372 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 219 ms 249384 KB Output is correct
19 Correct 190 ms 226632 KB Output is correct
20 Correct 196 ms 226516 KB Output is correct
21 Correct 6 ms 2136 KB Output is correct
22 Correct 7 ms 2140 KB Output is correct
23 Correct 7 ms 2140 KB Output is correct
24 Correct 7 ms 1884 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 181 ms 174864 KB Output is correct
27 Correct 184 ms 175076 KB Output is correct
28 Correct 182 ms 175008 KB Output is correct
29 Correct 191 ms 174964 KB Output is correct
30 Correct 16 ms 8772 KB Output is correct
31 Correct 28 ms 14976 KB Output is correct
32 Correct 19 ms 10064 KB Output is correct
33 Correct 26 ms 13908 KB Output is correct
34 Runtime error 2 ms 1112 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -