Submission #1097744

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10977442024-10-08 06:52:48vjudge1The Xana coup (BOI21_xanadu)C++17
100 / 100
76 ms26708 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+10,inf=0x3f3f3f3f;
int n,a[maxn],f[maxn][3][3],g1[maxn][3],g2[maxn][3];
vector<int>e[maxn];
void dfs(int u,int fa){
if(e[u].size()==1&&u!=1){
if(a[u]==1){
f[u][0][1]=0;
f[u][1][0]=1;
}
else{
f[u][0][0]=0;
f[u][1][1]=1;
}
return ;
}
for(int v:e[u]){
if(v==fa)continue;
dfs(v,u);
}
g1[0][1]=g2[0][1]=inf;
int cnt=0;
for(int v:e[u]){
if(v==fa)continue;
++cnt;
g1[cnt][0]=min(g1[cnt-1][1]+f[v][1][0],g1[cnt-1][0]+f[v][0][0]);
g1[cnt][1]=min(g1[cnt-1][1]+f[v][0][0],g1[cnt-1][0]+f[v][1][0]);
g2[cnt][0]=min(g2[cnt-1][1]+f[v][1][1],g2[cnt-1][0]+f[v][0][1]);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...