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[100009];
int dp[100009][2], A[100009];
void dfs(int pos) {
int m1 = 0, m2 = 0;
for (int i = 0; i < G[pos].size(); i++) {
dfs(G[pos][i]);
m1 += max(dp[G[pos][i]][0], dp[G[pos][i]][1]);
m2 += dp[G[pos][i]][1];
}
m2 += A[pos];
dp[pos][0] = m2; dp[pos][1] = m1;
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
int bit = 0;
for (int i = 1; i <= n - 1; i++) bit |= (1 << protocol[i]);
if (bit == 1) {
// Subtask 4.
for (int i = 0; i < n; i++) A[i] = confidence[i];
for (int i = 1; i <= n - 1; i++) G[host[i]].push_back(i);
dfs(0);
return max(dp[0][0], dp[0][1]);
}
if (bit == 2) {
// Subtask 2.
int sum = 0; for (int i = 0; i < n; i++) sum += confidence[i];
return sum;
}
if (bit == 4) {
// Subtask 3.
int sum = 0; for (int i = 0; i < n; i++) sum = max(sum, confidence[i]);
return sum;
}
if (n <= 10) {
// Subtask 5.
}
return -1;
}
Compilation message (stderr)
friend.cpp: In function 'void dfs(int)':
friend.cpp:10:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G[pos].size(); i++) {
~~^~~~~~~~~~~~~~~
# | 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... |