제출 #1026594

#제출 시각아이디문제언어결과실행 시간메모리
1026594IssaJobs (BOI24_jobs)C++17
14 / 100
2064 ms25112 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 3e5 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e9 + 100; const int MOD = 1e9 + 7; const int maxl = 350; const int P = 31; ll sum, start; int n; vector<int> g[maxn]; int p[maxn]; int a[maxn]; ll mn[maxn]; ll sm[maxn]; int used[maxn]; void test(){ cin >> n >> start; sum = start; for(int i = 1; i <= n; i++){ cin >> a[i] >> p[i]; g[p[i]].push_back(i); } used[0] = 1; while(true){ for(int i = 1; i <= n; i++){ sm[i] = mn[i] = 0; } ll nxt = sum, f; for(int v = 1; v <= n; v++){ if(used[v]) continue; sm[v] += a[v]; mn[v] = min(mn[v], sm[v]); for(int to: g[v]){ sm[to] = sm[v]; mn[to] = mn[v]; } if(sum + mn[v] >= 0 && sum + sm[v] > nxt){ nxt = sum + sm[v]; f = v; } } if(nxt > sum){ sum = nxt; while(!used[f]){ used[f] = 1; f = p[f]; } } else break; } cout << sum - start; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while(t--) test(); cout << ent; }

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

Main.cpp: In function 'void test()':
Main.cpp:50:17: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |    while(!used[f]){
      |           ~~~~~~^
#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...