제출 #1052838

#제출 시각아이디문제언어결과실행 시간메모리
1052838vjudge1Jobs (BOI24_jobs)C++17
11 / 100
56 ms25936 KiB
/* بسم الله الرحمن الرحيم Author: (:Muhammad Aneeq:) */ #include <iostream> #include <vector> #include <algorithm> using namespace std; #define int long long int const N=3e5+10; vector<int>nei[N]={}; int a[N]; int p[N]={}; int dfs(int u) { int x=0; for (auto i:nei[u]) x+=max(0ll,dfs(i)); return a[u]+x; } inline void solve() { int n,s; cin>>n>>s; for (int i=1;i<=n;i++) { cin>>a[i]; cin>>p[i]; if (p[i]) nei[p[i]].push_back(i); } if (s==1e18) { int ans=0; for (int i=1;i<=n;i++) { if (p[i]==0) ans+=max(0ll,dfs(i)); } cout<<ans<<endl; } } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 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...