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;
int Sub1(int n, int confidence[], int host[], int protocol[]) {
vector<vector<bool>> g(n, vector<bool>(n, false));
auto add_edge = [&g] (int u, int v) {
g[u][v] = g[v][u] = true;
};
for (int i = 1; i < n; i++) {
if (protocol[i] == 0 || protocol[i] == 2) {
add_edge(i, host[i]);
}
if (protocol[i] == 1 || protocol[i] == 2) {
for (int j = 0; j < n; j++) if (g[host[i]][j]) {
add_edge(j, i);
}
}
}
int ans = -1;
for (int mask = 0; mask < (1 << n); mask++) {
bool flag = true;
int now = 0;
for (int i = 0; i < n; i++) if (mask & (1 << i)) {
now += confidence[i];
for (int j = i + 1; j < n; j++) if (mask & (1 << j)) {
flag &= !g[i][j];
}
}
if (!flag)
continue;
ans = max(ans, now);
}
return ans;
}
int Sub2(int n, int confidence[], int host[], int protocol[]) {
int ans = confidence[0];
for (int i = 1; i < n; i++) {
if (protocol[i] != 1)
return -1;
ans += confidence[i];
}
return ans;
}
int Sub3(int n, int confidence[], int host[], int protocol[]) {
int ans = confidence[0];
for (int i = 1; i < n; i++) {
if (protocol[i] != 2)
return -1;
ans = max(ans, confidence[i]);
}
return ans;
}
int findSample(int n, int confidence[], int host[], int protocol[]){
int ans = -1;
if (n <= 10)
return Sub1(n, confidence, host, protocol);
if ((ans = Sub2(n, confidence, host, protocol)) != -1)
return ans;
if ((ans = Sub3(n, confidence, host, protocol)) != -1)
return ans;
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... |