# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
823577 | thimote75 | Friend (IOI14_friend) | C++14 | 1 ms | 432 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;
using idata = vector<int>;
using igrid = vector<idata>;
using di = pair<int, int>;
idata parents;
idata types;
idata A, B;
idata coeff;
igrid roads;
int createVersion (int parent) {
parents.push_back(parent);
types .push_back(0);
coeff .push_back(0);
A .push_back(-1);
B .push_back(-1);
return parents.size() - 1;
}
di compute(int node);
di computeI (int node) {
int dp0 = 0;
int dp1 = coeff[node];
for (int next : roads[node]) {
const auto data = compute(next);
dp0 += max(data.first, data.second);
dp1 += data.first;
}
return { dp0, dp1 };
}
di compute (int node) {
if (types[node] == 0) return computeI(node);
return {0, 0};
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
idata versions(n, -1);
versions[0] = createVersion(-1);
for (int i = 1; i < n; i ++) {
int u = versions[host[i]];
versions[i] = createVersion(u);
int v = versions[i];
}
roads.resize(parents.size());
for (int i = 0; i < parents.size(); i ++)
if (parents[i] != -1)
roads[parents[i]].push_back(i);
for (int i = 0; i < n; i ++)
coeff[versions[i]] = confidence[i];
const auto data = compute(0);
return max(data.first, data.second);
}
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... |