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>
#include "friend.h"
#pragma GCC optimize("O3")
using namespace std;
int st1(int n, int confidence[], int host[], int protocol[]){
vector<int> g(n);
for(int i = 1; i < n; i++){
if(protocol[i]){
g[i] |= g[host[i]];
for(int j = 0; j < i; j++) if(g[host[i]]&(1<<j)) g[j] |= (1<<i);
}
if(protocol[i] != 1){
g[i] |= (1<<host[i]);
g[host[i]] |= (1<<i);
}
}
int t, s = 0;
for(int i = 0; i < (1<<n); i++){
t = 0;
for(int j = 0; j < n; j++) if(i&(1<<j)) t += confidence[j];
for(int j = 0; j < n; j++) if((i&(1<<j)) && (i&(g[j]))) t = 0;
s = max(s, t);
}
return s;
}
int st2(int n, int confidence[]){
int s = 0;
for(int i = 0; i < n; i++) s += confidence[i];
return s;
}
int st3(int n, int confidence[]){
int mx = 0;
for(int i = 0; i < n; i++) mx = max(mx, confidence[i]);
return mx;
}
void dfs(int u, vector< vector<int> >& g, vector<int>& dp, vector<int>& a){
for(int v : g[u]){
dfs(v, g, dp, a);
a[u] += dp[v];
dp[u] += a[v];
}
dp[u] = max(dp[u], a[u]);
}
int st4(int n, int confidence[], int host[]){
vector< vector<int> > g(n);
vector<int> dp(n), a(n);
for(int i = 1; i < n; i++) g[host[i]].push_back(i);
for(int i = 0; i < n; i++) dp[i] = confidence[i];
dfs(0, g, dp, a);
return dp[0];
}
int match(int u, vector<int>& x, vector<int>& vis, vector< vector<int> >& g){
for(int v : g[u]){
if(vis[v]) continue;
vis[v] = 1;
if(x[v] == -1 || match(x[v], x, vis, g)){
x[v] = u;
return 1;
}
}
return 0;
}
int st5(int n, int host[], int protocol[]){
vector< vector<int> > g(n);
for(int i = 1; i < n; i++){
if(protocol[i]){
for(int v : g[host[i]]) g[i].push_back(v), g[v].push_back(i);
}
else{
g[i].push_back(host[i]), g[host[i]].push_back(i);
}
}
int s = n;
vector<int> x(n, -1), vis;
for(int i = 0; i < n; i++){
vis.assign(n, 0);
if(match(i, x, vis, g)) s--;
}
return s;
}
int findSample(int n, int confidence[], int host[], int protocol[]){
if(n <= 10) return st1(n, confidence, host, protocol);
for(int i = 2; i < n; i++) if(protocol[i] != protocol[i-1])
return st5(n, host, protocol);
if(protocol[1] == 1) return st2(n, confidence);
if(protocol[1]) return st3(n, confidence);
return st4(n, confidence, host);
}
# | 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... |