제출 #1084047

#제출 시각아이디문제언어결과실행 시간메모리
1084047sonho00경주 (Race) (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define int long long using namespace std; struct CD { int n; vector<vector<int>> adj, tree; vector<int> sz; vector<bool> used; CD(int n) : n(n), adj(n + 1), tree(n + 1), sz(n + 1), used(n + 1) {} int getSz(int cur, int par) { sz[cur] = 1; for (int nei : adj[cur]) { if (used[nei] || nei == par) continue; sz[cur] += getSz(nei, cur); } return sz[cur]; } int getCent(int cur, int tot, int par) { for (int nei : adj[cur]) { if (used[nei] || nei == par) continue; if (tot < sz[nei] * 2) return getCent(nei, tot, cur); } return cur; } int getRoot(int cur = 1) { cur = getCent(cur, getSz(cur, -1), -1); used[cur] = 1; for (int nei : adj[cur]) { if (used[nei]) continue; tree[cur].push_back(getRoot(nei)); } return cur; } }; signed best_path(int n,int k,int h[n-1][2],int l[n-1]) { CD cd(n); vector<vector<pair<int, int>>> adj(n); for (int i = 0; i < n-1; ++i) { cd.adj[h[i][0]].push_back(h[i][1]); cd.adj[h[i][1]].push_back(h[i][0]); adj[h[i][0]].emplace_back(l[i], h[i][1]); adj[h[i][1]].emplace_back(l[i], h[i][0]); } vector<bool> used(n); vector<int> dp(k + 1, n); int ans = n; function<void(int, int, int, int, int)> dfs = [&](int cur, int par, int dist, int dep, int type) { if (dist > k) return; if (type == 1) ans = min(ans, dep + dp[k - dist]); if (type == 2) dp[dist] = min(dp[dist], dep); if (type == 3) dp[dist] = n; for (auto &[wei, nei] : adj[cur]) { if (used[nei] || nei == par) continue; dfs(nei, cur, dist + wei, dep + 1, type); } }; function<void(int)> solve = [&](int root) { used[root] = 1; dp[0] = 0; for (auto &[wei, nei] : adj[root]) { if (used[nei]) continue; dfs(root, -1, 0, 0, 1); dfs(root, -1, 0, 0, 2); } for (auto &[wei, nei] : adj[root]) { if (used[nei]) continue; dfs(root, -1, 0, 0, 3); } for (int nei : cd.tree[root]) { if (used[nei]) continue; solve(nei); } }; solve(cd.getRoot(0)); if (ans == n) ans = -1; return ans; }

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

race.cpp:38:37: error: use of parameter outside function body before '-' token
   38 | signed best_path(int n,int k,int h[n-1][2],int l[n-1]) {
      |                                     ^
race.cpp:38:43: error: expected ')' before ',' token
   38 | signed best_path(int n,int k,int h[n-1][2],int l[n-1]) {
      |                 ~                         ^
      |                                           )
race.cpp:3:13: error: expected unqualified-id before 'long'
    3 | #define int long long
      |             ^~~~
race.cpp:38:44: note: in expansion of macro 'int'
   38 | signed best_path(int n,int k,int h[n-1][2],int l[n-1]) {
      |                                            ^~~