제출 #1043926

#제출 시각아이디문제언어결과실행 시간메모리
1043926vjudge1Paprike (COI18_paprike)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5 + 10; ll n, k, a[N], sz[N], ans, tmp; vector<ll> g[N]; void dfs(ll v, ll p = -1){ sz[v] = a[v]; for (ll u : g[v]){ if (u == p) continue; dfs(u, v); sz[v] += sz[u]; } for (ll u : g[v]){ if (u == p) continue; vec.push_back(sz[u]); } sort(vec.begin(), vec.end()); while (sz[v] > k){ sz[v] -= vec.back(); vec.pop_back(); tmp++; } } int main(){ cin >> n >> k; for (ll i = 1; i <= n; i ++) cin >> a[i]; for (ll i = 1; i < n; i ++){ ll u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } ans = 1e9; for (ll v = 1; v <= n; v ++){ tmp = 0; dfs(v); ans = min(ans, tmp); } cout << ans << endl; }

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

paprike.cpp: In function 'void dfs(ll, ll)':
paprike.cpp:20:9: error: 'vec' was not declared in this scope
   20 |         vec.push_back(sz[u]);
      |         ^~~
paprike.cpp:22:10: error: 'vec' was not declared in this scope
   22 |     sort(vec.begin(), vec.end());
      |          ^~~