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 <bits/stdc++.h>
using namespace std;
#define pii pair <int,int>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ll long long
const int N = 3e5 + 100;
const int M = 1e3 + 100;
vector <int> g[N];
bool con[M][M],u[N];
int cost[N],dp[N][2],d[N];
void dfs(int v) {
u[v] = 1;
dp[v][0] = 0;
dp[v][1] = cost[v];
for(auto to : g[v]) {
if(u[to])continue;
dfs(to);
dp[v][0] += max(dp[to][1],dp[to][0]);
dp[v][1] += dp[to][0];
}
}
int findSample(int n,int c[],int st[],int type[]){
int mx = 0;
bool ch1 = 0;
for(int i = 0;i < n;i++) {
mx = max(mx,c[i]);
if(i > 0 && type[i] == 2)ch1 = 1;
}
if(mx == 1 && !ch1) {
d[0] = c[0];
mx = 0;
mx = max(mx,c[0]);
for(int i = 1;i < n;i++) {
if(type[i] == 0) {
con[i][st[i]] = 1;
con[st[i]][i] = 1;
d[i] = c[i];
for(auto to : g[st[i]]) {
d[i] = max(d[i],d[to] + c[i]);
}
g[i].pb(st[i]);
g[st[i]].pb(i);
}else {
for(auto to : g[st[i]]) {
g[to].pb(i);
g[i].pb(to);
con[i][to] = 1;
con[to][i] = 1;
}
d[i] = d[st[i]] + c[i];
}
mx = max(mx,d[i]);
}
return mx;
}
if(n <= 10) {
for(int i = 1;i < n;i++) {
if(type[i] == 0) {
g[st[i]].pb(i);
g[i].pb(st[i]);
con[i][st[i]] = 1;
con[st[i]][i] = 1;
}else if(type[i] == 1) {
for(auto to : g[st[i]]) {
g[to].pb(i);
g[i].pb(to);
con[i][to] = 1;
con[to][i] = 1;
}
}else {
g[st[i]].pb(i);
g[i].pb(st[i]);
con[i][st[i]] = 1;
con[st[i]][i] = 1;
for(auto to : g[st[i]]) {
g[to].pb(i);
g[i].pb(to);
con[i][to] = 1;
con[to][i] = 1;
}
}
}
int mx = 0;
for(int i = 0;i < (1 << n);i++) {
bool ch = 0;
int sum = 0;
for(int j = 0;j < n;j++) {
if(i & (1 << j)) {
for(int h = 0;h < j;h++) {
if((i & (1 << h)) && con[j][h]) {
ch = 1;
break;
}
}
if(ch)break;
sum += c[j];
}
}
if(!ch)mx = max(mx,sum);
}
return mx;
}
int ans = 0;
if(type[1] == 1) {
for(int i = 0;i < n;i++)ans += c[i];
}else if(type[1] == 2){
for(int i = 0;i < n;i++)ans = max(ans,c[i]);
}else {
cost[0] = c[0];
for(int i = 1;i < n;i++) {
cost[i] = c[i];
g[st[i]].pb(i);
g[i].pb(st[i]);
}
for(int i = 0;i < n;i++) {
if(!u[i]) {
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... |