이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <numeric>
#include <vector>
#include "friend.h"
using namespace std;
using llong = long long;
const int maxN = 100'005;
vector<int> nei[maxN];
enum Protocol { ME = 0, MY = 1, WE = 2 };
pair<int, int> SolveTree(int v, int* a)
{
pair<int, int> res(a[v], 0);
for (int to: nei[v])
{
pair<int, int> cur = SolveTree(to, a);
res.first += cur.second;
res.second += max(cur.first, cur.second);
}
return res;
}
// Find out best sample
int findSample(int n, int a[], int host[], int prot[]){
if (n <= 10)
{
bool g[11][11];
for (int i = 0; i < n; ++i)
{
for (int j = 1; j <= n; ++j)
g[i][j] = g[j][i] = false;
if (i == 0) continue;
int j = host[i];
if (prot[i] == ME)
g[i][j] = g[j][i] = true;
else
{
for (int k = 1; k <= n; ++k)
if (g[j][k])
g[i][k] = g[k][i] = true;
if (prot[i] == WE)
g[i][j] = g[j][i] = true;
}
}
int ans = 0;
for (int mask = 1; mask < (1 << n); ++mask)
{
bool ok = true;
int cur = 0;
for (int i = 0; i < n; ++i)
{
if (!(mask & (1 << i))) continue;
cur += a[i];
for (int j = i + 1; j < n; ++j) {
if (!(mask & (1 << j))) continue;
if (g[i][j])
ok = false;
}
}
if (ok) ans = max(ans, cur);
}
return ans;
}
if (count(prot + 1, prot + n, ME) == n - 1) {
for (int i = 1; i < n; ++i)
nei[host[i]].push_back(i);
auto p = SolveTree(0, a);
return max(p.first, p.second);
}
if (count(prot + 1, prot + n, MY) == n - 1)
return accumulate(a, a + n, 0);
if (count(prot + 1, prot + n, WE) == n - 1)
return *max_element(a, a + n);
}
컴파일 시 표준 에러 (stderr) 메시지
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:74:1: warning: control reaches end of non-void function [-Wreturn-type]
74 | }
| ^
# | 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... |