제출 #941451

#제출 시각아이디문제언어결과실행 시간메모리
941451Mike_Vu경주 (Race) (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; const int inf = 1e9; int n, k, re = 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

컴파일 시 표준 에러 (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:31:5: error: 'res' was not declared in this scope; did you mean 're'?
   31 |     res = min(res, len + min_length[k - sum]);
      |     ^~~
      |     re
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:49:39: error: expected ';' before ':' token
   49 |             undo_length.push_back(sum):
      |                                       ^
      |                                       ;
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]){
      |              ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:69:8: error: 'res' was not declared in this scope; did you mean 're'?
   69 |     if(res >= inf) res = -1;
      |        ^~~
      |        re
race.cpp:70:12: error: 'res' was not declared in this scope; did you mean 're'?
   70 |     return res;
      |            ^~~
      |            re