제출 #1086544

#제출 시각아이디문제언어결과실행 시간메모리
1086544IBoryJobs (BOI24_jobs)C++17
0 / 100
2097 ms26192 KiB
#include <bits/stdc++.h> #define pii pair<ll, ll> typedef long long ll; using namespace std; const int MAX = 300003; vector<int> G[MAX]; ll S[MAX], P[MAX], V[MAX]; pii DFS(int cur, int prev, ll lim, ll down, ll up) { pii ret = {-1, cur}; if (!V[cur] && down <= lim) ret = max(ret, pii{up, cur}); for (int next : G[cur]) { if (next == prev) continue; ret = max(ret, DFS(next, cur, lim, min(down, up + S[next]), up + S[next])); } return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll N; cin >> N >> S[0]; for (int i = 1; i <= N; ++i) { cin >> S[i] >> P[i]; G[P[i]].push_back(i); } ll ans = 0, cnt = 0, init = S[0]; while (1) { pii go = DFS(0, 0, ans, 0, S[0]); if (go.first < 0) break; ans += go.first; int cur = go.second; while (!V[cur]) { V[cur] = 1; S[cur] = 0; cur = P[cur]; } } cout << ans - init; return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:29:14: warning: unused variable 'cnt' [-Wunused-variable]
   29 |  ll ans = 0, cnt = 0, init = S[0];
      |              ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...