Submission #1125647

#TimeUsernameProblemLanguageResultExecution timeMemory
1125647salmonCat Exercise (JOI23_ho_t4)C++20
31 / 100
2095 ms31868 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)); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf(" %d",&N);
      |     ~~~~~^~~~~~~~~~
Main.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf(" %d",&lst[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf(" %d",&u);
      |         ~~~~~^~~~~~~~~~
Main.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf(" %d",&v);
      |         ~~~~~^~~~~~~~~~
#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...