Submission #1280040

#TimeUsernameProblemLanguageResultExecution timeMemory
1280040LeynaFriend (IOI14_friend)C++20
16 / 100
2 ms588 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; /* SUBTASK 4 vector<int> take, not_take; vector<vector<int>> children; void dfs(int u, int confidence[]){ take[u] += confidence[u]; for (int v : children[u]){ dfs(v, confidence); take[u] += not_take[v]; not_take[u] += max(not_take[v], take[v]); } } // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]){ children.resize(n); for (int i=1; i<n; i++){ children[host[i]].push_back(i); } take = not_take = vector<int>(n); dfs(0, confidence); return max(take[0], not_take[0]); }*/ /* SUBTASK 2 int findSample(int n,int confidence[],int host[],int protocol[]){ int ans = 0; for (int i=0; i<n; i++) ans += confidence[i]; return ans; } */ /* int findSample(int n,int confidence[],int host[],int protocol[]){ int ans = 0; for (int i=0; i<n; i++) ans = max(confidence[i], ans); return ans; }*/ int findSample(int n,int confidence[],int host[],int protocol[]){ int res = 0; vector<int> p(n), q(n); for (int i=0; i<n; i++) p[i] = confidence[i]; for (int i=n-1; i > 0; i--){ int j = host[i]; if (protocol[i] == 0){ // IAmYourFriend p[j] += q[i]; q[j] += p[i]; } else if (protocol[i] == 1){ // MyFriendsAreYourFriends p[j] += p[i]; q[j] += q[i]; } else{ p[j] = max(p[j], p[i]); q[j] += q[i]; } /*for (int i=0; i<n; i++){ cout << p[i] << " " << q[i] << endl; } cout << "-------" << endl;*/ } res = max(p[0], q[0]); /*for (int i=0; i<n; i++){ cout << p[i] << " " << q[i] << endl; }*/ return res; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...