제출 #1029066

#제출 시각아이디문제언어결과실행 시간메모리
1029066OtalpJobs (BOI24_jobs)C++14
11 / 100
203 ms39504 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pb push_back #define ff first #define ss second vector<int> q[300100]; ll a[300100]; ll dp[300100][2]; void dfs(int v, int p){ dp[v][0] = a[v]; dp[v][1] = 0; for(int to: q[v]){ if(to == p) continue; dfs(to, v); dp[v][0] += dp[to][0]; dp[v][1] += dp[to][1]; } dp[v][1] = min(dp[v][1], dp[v][0]); } void solve(){ ll n, s; cin>>n>>s; ll ans = s; for(int i=1; i<=n; i++){ int l, r; cin>>l>>r; q[r].pb(i); q[i].pb(r); a[i] = l; ans += a[i]; } dfs(0, -1); ans -= dp[0][1]; cout<<ans-s; } signed main(){ solve(); }
#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...