# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037218 | onbert | Friend (IOI14_friend) | C++17 | 24 ms | 10720 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, a[maxn];
vector<int> adj[maxn][2];
int dp[maxn][2];
bool vis[maxn];
void dfs(int u) {
vis[u] = true;
for (int i=0;i<2;i++) for (int v:adj[u][i]) dfs(v);
dp[u][1] = a[u];
for (int v:adj[u][0]) dp[u][1] += dp[v][0];
for (int v:adj[u][1]) dp[u][1] += dp[v][1];
int pt = 0, cur = 0;
for (int v:adj[u][0]) cur += dp[v][1];
for (int v:adj[u][1]) cur += dp[v][0];
dp[u][0] = cur;
for (int v:adj[u][0]) {
while (pt<adj[u][1].size() && adj[u][1][pt] < v) cur += dp[adj[u][1][pt]][1] - dp[adj[u][1][pt]][0], pt++;
dp[u][0] = max(cur, dp[u][0]);
cur += dp[v][0] - dp[v][1];
}
while (pt<adj[u][1].size()) cur += dp[adj[u][1][pt]][1] - dp[adj[u][1][pt]][0], pt++;
dp[u][0] = max(cur, dp[u][0]);
dp[u][1] = max(dp[u][0], dp[u][1]);
}
int findSample(int N, int confidence[], int host[], int t[]){
n = N;
for (int i=0;i<n;i++) a[i] = confidence[i];
for (int i=1;i<n;i++) adj[host[i]][t[i]].push_back(i);
dfs(0);
return dp[0][1];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |