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 "friend.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 1005;
vector <int> g[N];
int u[N], dp[N][2], ans;
void dfs (int v) {
u[v] = 1;
dp[v][1] = 1;
for (auto to : g[v]) {
if (u[to] == 0)
dfs(to);
dp[v][1] += dp[to][0];
dp[v][0] += max(dp[to][0], dp[to][1]);
}
}
int findSample(int n, int val[], int batya[], int type[]) {
assert(val[0] == 1);
for (int i = 1; i < n; i++) {
assert(val[i] == 1);
if (type[i] == 0) {
g[batya[i]].pb(i);
g[i].pb(batya[i]);
}
else if (type[i] == 1) {
for (auto it: g[batya[i]]) {
g[i].pb(it);
g[it].pb(i);
}
}
else
assert(0);
}
for (int i = 0; i < n; i++) {
if (u[i]) continue;
dfs(i);
ans += max(dp[i][0], dp[i][1]);
}
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... |