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;
vector<int> g[100005];
vector<int> sg[100005];
int rn[100005];
int dp[100005][2]; // dp[u][including u?]
void dfs(int u, int* confidence, int p = -1){
for(int v : g[u]){
dfs(v, confidence, u);
}
for(int v : sg[u]){
dfs(v, confidence, u);
}
// compute dp[u][0]
for(int v : g[u]){
dp[u][0] += max(dp[v][0], dp[v][1]);
}
// compute dp[u][1]
dp[u][1] = confidence[u];
for(int v : sg[u]){
dp[u][1] += dp[v][1];
}
for(int v : g[u]){
dp[u][1] += dp[v][0];
}
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i = 0; i < n; i++) rn[i] = i;
for(int i = 1; i < n; i++){
switch(protocol[i]){
case 0:
g[rn[host[i]]].push_back(i);
break;
case 1:
sg[rn[host[i]]].push_back(i);
break;
case 2:
rn[i] = host[i];
confidence[host[i]] = max(confidence[host[i]], confidence[i]);
break;
}
}
dfs(0, confidence);
return max(dp[0][0], dp[0][1]);
}
# | 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... |