Submission #546529

#TimeUsernameProblemLanguageResultExecution timeMemory
546529emuyumiFriend (IOI14_friend)C++17
35 / 100
60 ms7176 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int MN = 1e5 + 1, inf = 0x3f3f3f3f; int dp[MN][2], val[MN]; struct Edge{ int to, t; }; vector<Edge> adj[MN]; void dfs(int v){ vector<pii> vec = {{0, 0}}; int tota = 0; int tot0 = 0; for (auto [to, t] : adj[v]){ dfs(to); tota += dp[to][0]; if (t == 0) tot0 += dp[to][1]; else tot0 += dp[to][0]; if (t == 1 || t == 2){ if (t == 1){ val[v] += dp[to][1]; } pii res = {vec[0].first, vec[0].second}; vec.erase(vec.begin()); for (auto [a, b] : vec){ res.first += a; res.second += max(a, b); } res.first += dp[to][0]; res.second = max(res.second + dp[to][0], dp[to][1]); vec = {res}; } else{ vec.push_back({dp[to][0], dp[to][1]}); } } dp[v][0] = vec[0].first; dp[v][1] = max(vec[0].first, vec[0].second); vec.erase(vec.begin()); for (auto [a, b] : vec){ dp[v][0] += max(a, b); dp[v][1] += max(a, b); } dp[v][0] = max(tot0, dp[v][0]); dp[v][1] = max(dp[v][1], tota + val[v]); } int findSample(int n, int confidence[], int host[], int protocol[]){ for (int i = 0; i < n; ++i) val[i] = confidence[i]; for (int i = 1; i < n; ++i){ adj[host[i]].push_back({i, protocol[i]}); } dfs(0); // for (int i = 0; i < n; ++i) cout << i << ": " << dp[i][0] << " " << dp[i][1] << '\n'; 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...