Submission #941455

#TimeUsernameProblemLanguageResultExecution timeMemory
941455Mike_VuRace (IOI11_race)C++14
100 / 100
218 ms53324 KiB
#include<bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; const int inf = 1e9; int n, k, res = inf, sz[MAX], min_length[MAX]; bool deleted[MAX]; vector<int> undo_length; vector<pair<int, int>> adj[MAX]; stack<pair<int, int>> updates; int get_size(int u, int pre){ sz[u] = 1; for(auto [v, w] : adj[u]) if(v != pre and !deleted[v]){ sz[u] += get_size(v, u); } return sz[u]; } int find_centroid(int u, int pre, int target){ for(auto [v, w] : adj[u]) if(v != pre and !deleted[v] and sz[v] * 2 > target){ return find_centroid(v, u, target); } return u; } void compute(int u, int pre, int len, int sum){ if(sum > k) return; res = min(res, len + min_length[k - sum]); updates.push(make_pair(len, sum)); for(auto [v, w] : adj[u]) if(v != pre and !deleted[v]){ compute(v, u, len + 1, sum + w); } } void decompose(int u){ int c = find_centroid(u, -1, get_size(u, -1)); deleted[c] = true; undo_length.clear(); for(auto [v, w] : adj[c]) if(!deleted[v]){ compute(v, c, 1, w); while(!updates.empty()){ int len, sum; tie(len, sum) = updates.top(); updates.pop(); min_length[sum] = min(min_length[sum], len); undo_length.push_back(sum); } } for(auto v : undo_length) min_length[v] = inf; for(auto [v, w] : adj[c]) if(!deleted[v]){ decompose(v); } } int best_path(int N, int K, int H[][2], int L[]){ n = N; k = K; for(int i = 0; i < n - 1; ++i){ int u = H[i][0], v = H[i][1], w = L[i]; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } fill(min_length + 1, min_length + 1 + k, inf); decompose(1); if(res >= inf) res = -1; return res; } //#define Zero_OP #ifdef Zero_OP void init(void){ } void process(){ int H[2][2]; H[0][0] = 0; H[0][1] = 1; H[1][0] = 1; H[1][1] = 2; int L[2]; L[0] = 1; L[1] = 1; cout << best_path(3, 3, H, L) << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); init(); process(); return 0; } #endif

Compilation message (stderr)

race.cpp: In function 'int get_size(int, int)':
race.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for(auto [v, w] : adj[u]) if(v != pre and !deleted[v]){
      |              ^
race.cpp: In function 'int find_centroid(int, int, int)':
race.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto [v, w] : adj[u]) if(v != pre and !deleted[v] and sz[v] * 2 > target){
      |              ^
race.cpp: In function 'void compute(int, int, int, int)':
race.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |     for(auto [v, w] : adj[u]) if(v != pre and !deleted[v]){
      |              ^
race.cpp: In function 'void decompose(int)':
race.cpp:43:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     for(auto [v, w] : adj[c]) if(!deleted[v]){
      |              ^
race.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [v, w] : adj[c]) if(!deleted[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...