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