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<vector<int>> adj;
int findSample(int n, int confidence[], int host[], int protocol[]){
int mip = 4, map = 0;
for(int i = 1; i < n; i++) {
mip = min(mip, protocol[i]);
map = max(map, protocol[i]);
}
if(n <= 10) { // Subtask 1
adj.resize(n);
for(int i = 1; i < n; i++) {
int x, y;
if(protocol[i] == 0) {
tie(x, y) = {i, host[i]};
adj[x].push_back(y);
adj[y].push_back(x);
}
if(protocol[i] == 1) {
for(int g : adj[host[i]]) {
adj[i].push_back(g);
adj[g].push_back(i);
}
}
if(protocol[i] == 2) {
for(int g : adj[host[i]]) {
adj[i].push_back(g);
adj[g].push_back(i);
}
tie(x, y) = {i, host[i]};
adj[x].push_back(y);
adj[y].push_back(x);
}
}
int best = 0;
for(int i = 0; i < (1 << n); i++) {
vector<int> goods;
for(int j = 0; j < n; j++) {
if(i & (1 << j)) goods.push_back(j);
}
bool ok = true;
for(int g : goods) {
for(int h : goods) {
if(g == h) continue;
for(int k : adj[g]) {
if(k == h) ok = false;
}
}
}
if(!ok) continue;
int ans = 0;
for(int g : goods) {
ans += confidence[g];
}
best = max(best, ans);
vector<int>().swap(goods);
}
return best;
}
else if(mip == map && mip == 1) { // Subtask 2
int ans = 0;
for(int i = 0; i < n; i++) ans += confidence[i];
return ans;
}
else if(mip == map && mip == 2) { // Subtask 3
sort(confidence, confidence+n);
return confidence[n-1];
}
else if(mip == map) { // Subtask 4
// It is a tree
adj.resize(n);
for(int i = 1; i < n; i++) {
adj[i].push_back(host[i]);
adj[host[i]].push_back(i);
}
function<int(int, int, int)> dfs = [&](int n, int x, int par) {
if(x == 0) {
int ans = 0;
for(int ch : adj[n]) {
if(ch == par) continue;
ans += dfs(ch, 1, n);
}
return ans;
}
int ans = confidence[n];
for(int ch : adj[n]) {
if(ch == par) continue;
ans += dfs(ch, 0, n);
}
return max(ans, dfs(n, 0, par));
};
return dfs(0, 1, -1);
}
else if(map - mip == 1) { // Subtask 5
}
// Subtask 6
return -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... |