이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]; // [][0] -> exclude root; [][1] -> no restriction
void dfs(int p, int parent) {
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];
for_(i, 1, n) {
if (protocol[i] == 0) adj[host[i]].push_back(i);
else if (protocol[i] == 1) val[host[i]] += val[i];
else val[host[i]] = max(val[host[i]], val[i]);
}
dfs(0, 0);
return dp[0][1];
}
//int main() {
//#ifdef shiven
//freopen("test.in", "r", stdin);
//#endif
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//int n = 6;
//int confidence[] = {13, 3, 6, 20, 10, 15};
//int protocol[] = {-1, 0, 1, 2, 1, 0};
//int host[] = {-1, 0, 0, 1, 2, 0};
//cout << findSample(n, confidence, host, protocol) << endl;
//return 0;
//}
# | 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... |