제출 #94473

#제출 시각아이디문제언어결과실행 시간메모리
94473fjzzq2002친구 (IOI14_friend)C++14
27 / 100
51 ms17408 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; #define SZ 666666 int val[SZ],fa[SZ],fe[SZ]; vector<int> so[SZ]; int f[SZ][2][2]; inline void cmax(int&a,int b) {if(a<b)a=b;} void dfs(int x) { int ts[2][2][2]; memset(ts,-127/2,sizeof ts); ts[0][0][0]=0; ts[0][1][0]=val[x]; ts[1][0][0]=0; for(auto ch:so[x]) { dfs(ch); int g[2][2][2]; memset(g,-127/2,sizeof g); if(fe[ch]==0) { for(int a=0;a<2;++a) for(int b=0;b<2;++b) for(int c=0;c<2;++c) { cmax(g[a][b][c],ts[a][b][c]+f[ch][b][0]); if(!b) cmax(g[a][b][1],ts[a][b][c]+f[ch][b][1]); } } else if(fe[ch]==1) { for(int a=0;a<2;++a) for(int b=0;b<2;++b) for(int c=0;c<2;++c) { cmax(g[a][b][c],ts[a][b][c]+f[ch][0][0]); if(!a&&!c) cmax(g[a][b][c],ts[a][b][c]+f[ch][0][1]); } } else if(fe[ch]==2) { for(int a=0;a<2;++a) for(int b=0;b<2;++b) for(int c=0;c<2;++c) { cmax(g[a][b][c],ts[a][b][c]+f[ch][0][0]); if(!a&&!c&&!b) cmax(g[a][b][c],ts[a][b][c]+f[ch][0][1]); } } memcpy(ts,g,sizeof g); } for(int a=0;a<2;++a) for(int b=0;b<2;++b) f[x][a][b]=max(ts[a][b][0],ts[a][b][1]); } int findSample(int n,int confidence[], int host[],int protocol[]){ for(int i=0;i<n;++i) val[i]=confidence[i]; for(int i=1;i<n;++i) fa[i]=host[i],fe[i]=protocol[i], so[host[i]].push_back(i); dfs(0); return max(f[0][0][1],f[0][0][0]); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...