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>
#define pb push_back
#include "friend.h"
using namespace std;
int n;
int *conf;
int *h;
int *p;
constexpr static int IAM = 0;
constexpr static int MYF = 1;
constexpr static int WER = 2;
constexpr static int MX1 = 10;
int c[MX1][MX1];
int subtask1()
{
for (int i = 1; i < n; i++)
{
if (p[i] == IAM || p[i] == WER)
c[h[i]][i] = c[i][h[i]] = 1;
if (p[i] == MYF || p[i] == WER)
for (int j = 0; j < i; j++)
if (c[j][h[i]])
c[j][i] = c[i][j] = 1;
}
int res = 0;
for (int i = 0; i < (1<<n); i++)
{
vector<int> v;
for (int j = 0; j < n; j++)
if (i & (1<<j))
v.pb(j);
bool found = false;
for (int j = 0; j < v.size(); j++)
for (int k = j+1; k < v.size(); k++)
if (c[v[j]][v[k]])
found = true;
if (found)
continue;
int sum = 0;
for (int i : v)
sum += conf[i];
res = max(res, sum);
}
return res;
}
int subtask2()
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += conf[i];
return sum;
}
int subtask3()
{
int best = 0;
for (int i = 0; i < n; i++)
best = max(best, conf[i]);
return best;
}
constexpr static int MXSIZE = 1000;
int dp[MXSIZE][2];
vector<int> g[MXSIZE];
void dfs4(int node)
{
dp[node][1] = conf[node];
for (int c : g[node])
{
dfs4(c);
dp[node][1] += dp[c][0];
dp[node][0] += max(dp[c][0], dp[c][1]);
}
}
int subtask4()
{
for (int i = 1; i < n; i++)
g[h[i]].pb(i);
dfs4(0);
return max(dp[0][0], dp[0][1]);
}
int colord[MXSIZE][2];
int _col[MXSIZE];
int comp[MXSIZE];
void dfs5(int node, int c, int color)
{
comp[node] = c;
colord[node][color]++;
for (int cc : g[node])
if (comp[cc] == -1)
dfs5(cc, c, color^1);
else
assert(_col[cc] == (color^1));
}
int subtask5()
{
for (int i = 1; i < n; i++)
{
if (p[i] == IAM)
{
g[h[i]].pb(i);
g[i].pb(h[i]);
}
else
{
assert(p[i] == MYF);
for (int j : g[h[i]])
{
g[j].pb(i);
g[i].pb(j);
}
}
}
for (int i = 0; i < n; i++)
comp[i] = -1;
int csize = 0;
for (int i = 0; i < n; i++)
if (comp[i] == -1)
dfs5(i, csize++, 0);
int res = 0;
for (int i = 0; i < csize; i++)
res += max(colord[i][0], colord[i][1]);
return res;
}
// Find out best sample
int findSample(int _n,int _conf[],int _h[],int _p[])
{
n = _n;
conf = _conf;
h = _h;
p = _p;
if (n <= 10)
return subtask1();
bool seen_wer = p[1] == WER;
int current = p[1];
for (int i = 2; i < n; i++)
{
if (p[i] != current)
current = -1;
if (p[i] == WER)
seen_wer = true;
}
if (current == MYF)
return subtask2();
if (current == WER)
return subtask3();
if (current == IAM)
return subtask4();
if (!seen_wer)
return subtask5();
return 42;
}
Compilation message (stderr)
friend.cpp: In function 'int subtask1()':
friend.cpp:37:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
friend.cpp:38:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int k = j+1; k < v.size(); k++)
| ~~^~~~~~~~~~
# | 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... |