# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1125647 | salmon | Cat Exercise (JOI23_ho_t4) | C++20 | 2095 ms | 31868 KiB |
#include <bits/stdc++.h>
using namespace std;
int N;
int lst[200100];
vector<int> adjlst[200100];
int u,v;
bool visited[200100];
int d[200100];
pair<int,int> big(int i, int p, int de){
pair<int,int> ii = {lst[i],i};
d[i] = de;
for(int j : adjlst[i]){
if(visited[j]) continue;
if(j == p) continue;
ii = max(ii, big(j,i, de+1));
}
return ii;
}
int solve(int i){
visited[i] = true;
//printf(" %d",visited[i]);
int have = -1;
int ans = 0;
for(int j : adjlst[i]){
if(visited[j]) continue;
have = j;
pair<int,int> ii = big(j,i,1);
ans = max(ans,d[ii.second] + solve(ii.second));
}
return ans;
}
int main(){
scanf(" %d",&N);
int r;
for(int i = 0; i < N; i++){
scanf(" %d",&lst[i]);
if(lst[i] == N) r = i;
visited[i] = false;
}
for(int i = 0; i < N - 1; i++){
scanf(" %d",&u);
scanf(" %d",&v);
u--;
v--;
adjlst[u].push_back(v);
adjlst[v].push_back(u);
}
printf("%d\n",solve(r));
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |