이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5050;
const int inf = 1e9;
int n, pd[maxn], V[maxn], dp[maxn], c[maxn], a[maxn], type[maxn];
vector<int> t[maxn];
int par[maxn], adj[maxn];
int dfs(int v){
if (type[v] == 1){
int lc = t[v][0], rc = t[v][1];
dfs(lc);
dfs(rc);
dp[v] = dp[lc]+pd[rc];
pd[v] = pd[lc]+dp[rc];
dp[v] = max(dp[v],pd[v]);
}
else{
dp[v] = c[v];
for (auto u : t[v]){
dfs(u);
dp[v] += dp[u];
pd[v] += pd[u];
}
dp[v] = max(dp[v],pd[v]);
}
return dp[v];
}
void addEdge(int v, int u){
t[v].push_back(u);
par[u] = v;
}
int findSample(int N,int confidence[],int host[],int protocol[]){
n = N;
if (n <= 10){
for (int i = 0; i < n; i++)
adj[i] = (1 << i);
for (int i = 1; i < n; i++){
if (protocol[i] == 0)
adj[host[i]] |= (1 << i), adj[i] |= (1 << host[i]);
else
for (int j = 0; j < n; j++)
if (adj[host[i]] & (1 << j) and j != host[i])
adj[j] |= (1 << i), adj[i] |= (1 << j);
if (protocol[i] == 2)
adj[host[i]] |= (1 << i), adj[i] |= (1 << host[i]);
}
dp[0] = 0;
for (int mask = 1; mask < (1 << n); mask++){
dp[mask] = -inf;
for (int i = 0; i < n; i++){
if (mask & (1 << i)){
int sub = (mask & (adj[i]|(1<<i)));
dp[mask] = dp[mask^sub] + confidence[i];
}
}
}
return *max_element(dp, dp+(1<<n));
}
if (*min_element(protocol+1, protocol+n) == 2 and *max_element(protocol+1, protocol+n) == 2)
return *max_element(confidence, confidence+n);
int newint = n+1;
addEdge(0, 1);
V[0] = 1;
c[1] = confidence[0];
for (int i = 1; i < n; i++){
int v = V[host[i]];
if (protocol[i] == 0){
c[V[host[i]]] = 0;
type[v] = 1;
addEdge(v, newint++);
addEdge(newint-1, newint);
V[host[i]] = newint++;
addEdge(v, newint++);
addEdge(newint-1, newint);
V[i] = newint++;
c[V[i]] = confidence[i];
c[V[host[i]]] = confidence[host[i]];
}
else{
addEdge(par[v], newint++);
V[i] = newint-1;
c[V[i]] = confidence[i];
}
}
return dfs(0);
}
# | 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... |