제출 #1065400

#제출 시각아이디문제언어결과실행 시간메모리
1065400_rain_Jobs (BOI24_jobs)C++14
11 / 100
73 ms28248 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define debug false const int maxn = 3e5; vector<int> graph[maxn+2]; int x[maxn+2] , p[maxn+2]; bool root[maxn+2]; int n; i64 s; i64 dfs(int u , int p , i64 sum){ sum += x[u]; for (auto& v : graph[u]){ if (v!=p){ sum = max(sum , dfs(v,u,sum)); } } if (debug){ cout << "( DEBUG )\n"; cout << u << ' ' << sum << '\n'; } return sum; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; for (int i = 1; i <= n; ++i){ cin >> x[i] >> p[i]; if (p[i]==0) root[i] = true; else graph[p[i]].push_back(i); } i64 alter = s; for (int i = 1; i <= n; ++i){ if (root[i]) s = max(s , dfs(i,i,s)); } cout << s - alter << '\n'; }
#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...