Submission #998783

#TimeUsernameProblemLanguageResultExecution timeMemory
998783THXuanSeptember (APIO24_september)C++17
45 / 100
121 ms33072 KiB
#include <bits/stdc++.h> #include "september.h" #include <bits/stdc++.h> #define INF 1e18 using namespace std; typedef long long ll; vector<int>adj[800005]; int dp[800005]; void dfs(int s, int e){ for(auto u : adj[s]){ if(u==e) continue; dfs(u, s); dp[s] = max(dp[s], dp[u]); } } int solve(int N, int M, vector<int> F, vector<vector<int>>S) { for(int i = 0;i<N;i++){ adj[i].clear(); dp[i] = 0; } for(int i =1; i < N;i++){ adj[i].push_back(F[i]); adj[F[i]].push_back(i); } int ans = INF; for(int j =0;j<M;j++){ for(int i = 0;i<S[j].size();i++){ dp[S[j][i]] = i; } dfs(0, -1); int anss = 0; int i=0; while(i < S[j].size()){ int maxn = dp[S[j][i]]; int k = i; while(k <= maxn){ maxn = max(maxn, dp[S[j][k]]); ++k; } ++anss; i = maxn + 1; } ans = min(ans, anss); } return ans; }

Compilation message (stderr)

september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:4:13: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    4 | #define INF 1e18
      |             ^~~~
september.cpp:28:15: note: in expansion of macro 'INF'
   28 |     int ans = INF;
      |               ^~~
september.cpp:30:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(int i = 0;i<S[j].size();i++){
      |                       ~^~~~~~~~~~~~
september.cpp:35:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while(i < S[j].size()){
      |               ~~^~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...