Submission #137819

#TimeUsernameProblemLanguageResultExecution timeMemory
137819Osama_AlkhodairyFriend (IOI14_friend)C++17
35 / 100
5 ms2808 KiB
#include <bits/stdc++.h> #include "friend.h" //~ #include "grader.cpp" using namespace std; const int N = 100001; int p[N], dp[N][2]; vector <int> c, v[N]; int find(int x){ if(p[x] == x) return x; return p[x] = find(p[x]); } void merge(int x, int y){ x = find(x); y = find(y); if(x == y) return; p[y] = x; } void dfs(int node){ dp[node][1] = c[node]; for(auto &i : v[node]){ dfs(i); dp[node][0] += max(dp[i][0], dp[i][1]); dp[node][1] += dp[i][0]; } } int findSample(int n, int confidence[], int host[], int protocol[]){ for(int i = 0 ; i < n ; i++) p[i] = i; for(int i = 1 ; i < n ; i++){ if(protocol[i] == 0){ v[find(host[i])].push_back(i); } else if(protocol[i] == 1){ confidence[find(host[i])] += confidence[i]; merge(host[i], i); } else{ confidence[find(host[i])] = max(confidence[find(host[i])], confidence[i]); merge(host[i], i); } } for(int i = 0 ; i < n ; i++){ c.push_back(confidence[i]); } dfs(0); return max(dp[0][0], dp[0][1]); }
#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...