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 <bits/stdc++.h>
#include "friend.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXN = 1e5;
vi adj[MXN+1];
int val[MXN+1], dp[MXN+1][3], id[MXN+1]; // [][0] -> exclude root; [][1] -> no restriction
bool vis[MXN+1];
void dfs(int p, int parent) {
vis[p] = true;
dp[p][1] = val[p];
for (int i: adj[p]) if (i != parent) {
dfs(i, p);
dp[p][0] += dp[i][1];
dp[p][1] += dp[i][0];
}
dp[p][1] = max(dp[p][1], dp[p][0]);
}
int findSample(int n, int confidence[], int host[], int protocol[]) {
for_(i, 0, n) {
val[i] = confidence[i];
id[i] = i;
}
for_(i, 1, n) {
if (protocol[i] == 0) adj[id[host[i]]].push_back(i);
else if (protocol[i] == 1) {
val[id[host[i]]] += val[i];
id[i] = id[host[i]];
}
else {
val[id[host[i]]] = max(val[id[host[i]]], val[i]);
id[i] = id[host[i]];
}
}
int ans = 0;
for_(i, 0, n) if (!vis[i] and id[i] == i) {
dfs(i, i);
ans += dp[i][1];
}
return ans;
}
# | 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... |