제출 #887231

#제출 시각아이디문제언어결과실행 시간메모리
887231amsraman경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int best_path(int n, int k, int h[][2], int l[]) { int ans = n + 1; vector<int> sz(n); vector<bool> vis(n, false); vector<vector<pair<int, int>>> g(n); for(int i = 0; i < n - 1; i++) { g[h[i][0]].emplace_back(h[i][1], l[i]); g[h[i][1]].emplace_back(h[i][0], l[i]); } map<int, int> m1, m2; auto proc = [&](auto rec, int u, int p, int num, int sum) -> void { if(!m2.count(sum)) m2[sum] = num; else m2[sum] = min(m2[sum], num); for(auto [v, w]: g[u]) { if(v == p || vis[v]) continue; rec(rec, v, u, num + 1, sum + w); } }; auto get_size = [&](auto rec, int u, int p = 0) -> int { sz[u] = 1; for(auto [v, w]: g[u]) { if(v != p && !vis[v]) { sz[u] += rec(rec, v, u); } } return sz[u]; }; auto find_centroid = [&](auto rec, int u, int p, int full_sz) -> int { for(auto [v, w]: g[u]) { if(v != p && !vis[v] && 2 * sz[v] > full_sz) { return rec(rec, v, u, full_sz); } } return u; }; auto centroid_decomp = [&](auto rec, int u) -> void { get_size(get_size, u, u); u = find_centroid(find_centroid, u, u, sz[u]); get_size(get_size, u, u); vis[u] = true; m1[0] = 0; for(auto [v, w]: g[u]) { if(!vis[v]) { proc(proc, v, v, 1, w); for(auto [sum, num]: m2) { if(m1.count(k - sum)) { ans = min(ans, num + m1[k - sum]); } } for(auto [sum, num]: m2) { if(!m1.count(sum)) m1[sum] = num; else m1[sum] = min(m1[sum], num); } m2.clear(); } } m1.clear(); for(auto [v, w]: g[u]) { if(!vis[v]) rec(rec, v); } }; centroid_decomp(centroid_decomp, 0); return ans == n + 1 ? -1 : ans; } int main() { cout << best_path(3, 3, {{0, 1}, {1, 2}}, {1, 1}) << endl; cout << best_path(11, 12, {{0, 1}, {0, 2}, {2, 3}, {3, 4}, {4, 5}, {0, 6}, {6, 7}, {6, 8}, {8, 9}, {8, 10}}, {3, 4, 5, 4, 6, 3, 2, 5, 6, 7}) << endl; }

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'int main()':
race.cpp:70:53: error: cannot convert '<brace-enclosed initializer list>' to 'int (*)[2]'
   70 |     cout << best_path(3, 3, {{0, 1}, {1, 2}}, {1, 1}) << endl;
      |                                                     ^
      |                                                     |
      |                                                     <brace-enclosed initializer list>
race.cpp:5:33: note:   initializing argument 3 of 'int best_path(int, int, int (*)[2], int*)'
    5 | int best_path(int n, int k, int h[][2], int l[]) {
      |                             ~~~~^~~~~~
race.cpp:71:144: error: cannot convert '<brace-enclosed initializer list>' to 'int (*)[2]'
   71 |     cout << best_path(11, 12, {{0, 1}, {0, 2}, {2, 3}, {3, 4}, {4, 5}, {0, 6}, {6, 7}, {6, 8}, {8, 9}, {8, 10}}, {3, 4, 5, 4, 6, 3, 2, 5, 6, 7}) << endl;
      |                                                                                                                                                ^
      |                                                                                                                                                |
      |                                                                                                                                                <brace-enclosed initializer list>
race.cpp:5:33: note:   initializing argument 3 of 'int best_path(int, int, int (*)[2], int*)'
    5 | int best_path(int n, int k, int h[][2], int l[]) {
      |                             ~~~~^~~~~~