이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
const int maxn = 1e3+10;
int c[maxn];
int dp[maxn][2];
bool mark[maxn][maxn];
vector<int> grafo[maxn];
int dfs(int u, int p, bool is)
{
if (grafo[u].size() == 1 && u != 0)
{
if (is) return c[u];
return 0;
}
if (dp[u][is] != -1) return dp[u][is];
int aux = 0;
for (auto v: grafo[u])
{
if (v == p) continue;
if (is) aux += c[u] + dfs(v, u, 0);
else aux += max(dfs(v, u, 0), dfs(v, u, 1));
}
return dp[u][is] = aux;
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
for (int i = 0; i < n; i++)
c[i] = confidence[i];
if (n > 10)
{
if (protocol[1] == 2)
{
int mx = 0;
for (int i = 0; i < n; i++)
mx = max(mx, c[i]);
return mx;
}
else if (protocol[1] == 1)
{
int s = 0;
for (int i = 0; i < n; i++)
s += c[i];
return s;
}
else
{
memset(dp, -1, sizeof dp);
for (int i = 1; i < n; i++)
grafo[i].push_back(host[i]), grafo[host[i]].push_back(i);
return max(dfs(0, -1, 0), dfs(0, -1, 1));
}
}
for (int i = 1; i < n; i++)
{
int h = host[i];
if (protocol[i] == 0)
{
mark[i][h] = mark[h][i] = 1;
}
else if (protocol[i] == 1)
{
for (int j = 0; j < n; j++)
if (mark[h][j])
mark[i][j] = mark[j][i] = 1;
}
else
{
for (int j = 0; j < n; j++)
if (mark[h][j])
mark[i][j] = mark[j][i] = 1;
mark[i][h] = mark[h][i] = 1;
}
}
int ans = 0;
for (int mask = 0; mask < (1<<n); mask++)
{
bool ok = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (mark[i][j] && mask&(1<<i) && mask&(1<<j))
ok = 0;
if (ok)
{
int aux = 0;
for (int i = 0; i < n; i++)
if (mask&(1<<i))
aux += c[i];
ans = max(ans, aux);
}
}
return ans;
}
# | 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... |