Submission #899594

#TimeUsernameProblemLanguageResultExecution timeMemory
899594LucaIlieWorst Reporter 4 (JOI21_worst_reporter4)C++17
0 / 100
8 ms17500 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5; int n; int dp[1000][1000]; int parent[MAX_N + 1], height[MAX_N + 1], cost[MAX_N + 1], sc[MAX_N + 1]; vector <int> children[MAX_N + 1]; map <int, int> mp; map <int, long long> inc[MAX_N + 1]; void dfs( int u ) { sc[u] = cost[u]; for ( int v: children[u] ) { dfs( v ); sc[u] += sc[v]; } int maxSize = 0, h = -1; for ( int v: children[u] ) { if ( inc[v].size() > maxSize ) { maxSize = inc[v].size(); h = v; } } inc[u][-1] = 0; if ( h == -1 ) { inc[u][0] -= cost[u]; inc[u][height[u] + 1] += cost[u]; } else { swap( inc[u], inc[h] ); for ( int v: children[u] ) { if ( v == h ) continue; for ( auto x: inc[v] ) inc[u][x.first] += x.second; inc[v].clear(); } auto p = inc[u].lower_bound( height[u] ); if ( p != inc[u].begin() ) { p--; long long c = inc[u][height[u]]; vector<pair<int, long long>> pos; pos.push_back( { height[u], 0 } ); while ( p->first != -1 && c <= cost[u] ) { pos.push_back( { p->first, c } ); c += p->second; p--; } for ( int i = pos.size() - 1; i >= 0; i-- ) { int p = pos[i].first; long long c = pos[i].second; inc[u][p] += (i == pos.size() - 1 ? c - cost[u] : c - pos[i + 1].second); } inc[u][height[u] + 1] += cost[u]; } } inc[u][-1] = 0; int cc = dp[u][height[u]] - cost[u]; for ( int x = height[u]; x >= 0; x-- ) dp[u][x] = min( dp[u][x], cc ); } int main() { long long c = 0; cin >> n; for ( int v = 1; v <= n; v++ ) cin >> parent[v] >> height[v] >> cost[v]; for ( int v = 2; v <= n; v++ ) children[parent[v]].push_back( v ); for ( int v = 1; v <= n; v++ ) c += cost[v]; dfs( 1 ); cout << c + inc[1][0]; return 0; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'void dfs(int)':
worst_reporter2.cpp:22:28: warning: comparison of integer expressions of different signedness: 'std::map<int, long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         if ( inc[v].size() > maxSize ) {
      |              ~~~~~~~~~~~~~~^~~~~~~~~
worst_reporter2.cpp:57:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 inc[u][p] += (i == pos.size() - 1 ? c - cost[u] : c - pos[i + 1].second);
      |                               ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...