이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |