QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72069#4815. Flower's LandCharlieVinnieCompile Error//C++171.9kb2023-01-13 21:50:372023-01-13 21:50:41

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-13 21:50:41]
  • 评测
  • [2023-01-13 21:50:37]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
using namespace std;
const int N=4e4+5,M=3e3+5; typedef long long ll;
int n,k,a[N],ban[N],siz[N],cursiz,rt,Mxval,lis[N],lcnt; vector<int> to[N]; int f[N][M],g[N][M],tmp[N][M],ans[N];
void ckmax(int& x,int y) { if(x<y) x=y; }
void dfs0(int u,int pa) { siz[u]=1; int mx=0; for(int v:to[u]) if(v!=pa&&!ban[v]) dfs0(v,u),siz[u]+=siz[v],mx=max(mx,siz[v]); ; mx=max(mx,cursiz-siz[u]); if(mx<Mxval) Mxval=mx,rt=u; }
void dfs1(int u,int pa) { lis[++lcnt]=u; siz[u]=1; for(int v:to[u]) if(v!=pa&&!ban[v]) dfs1(v,u),siz[u]+=siz[v]; }
void solve(int A){
    if(cursiz<k) return;
    rt=0; Mxval=1e9; dfs0(A,0); A=rt;
    // fprintf(stderr,"Solve(%d)\n",A);
    lcnt=0; dfs1(A,0); lis[lcnt+1]=0; For(i,1,lcnt) For(j,0,k) f[lis[i]][j]=g[lis[i]][j]=tmp[lis[i]][j]=-1e9;
    g[0][0]=0; Rev(i,lcnt,1) { int u=lis[i]; g[u][0]=0; For(j,1,k) g[u][j]=max(tmp[u][j]=g[lis[i+1]][j-1]+a[u],g[lis[i+siz[u]]][j]); }
    f[A][0]=0; For(i,1,lcnt) { int u=lis[i]; For(j,0,k) ckmax(f[lis[i+1]][j+1],f[u][j]+a[u]),ckmax(f[lis[i+siz[u]]][j],f[u][j]); }
    For(i,1,lcnt) { int u=lis[i]; For(j,0,k) ckmax(ans[u],f[u][j]+tmp[u][k-j])/*,fprintf(stderr,"ans[%d] <- %d ( j=%d,f=%d,tmp=%d )\n",u,f[u][j]+tmp[u][k-j],j,f[u][j],tmp[u][k-j]);*/ }
    ban[A]=1; for(int B:to[A]) if(!ban[B]) cursiz=siz[B],solve(B);
}
signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n>>k; For(i,1,n) cin>>a[i]; ; For(i,1,n-1) { int x,y; cin>>x>>y; to[x].push_back(y); to[y].push_back(x); }
    cursiz=n; solve(1); For(i,1,n) cout<<ans[i]<<' '; ; cout<<'\n';
    cerr<<"Time = "<<clock()<<" ms"<<endl;
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO

详细

answer.code: In function ‘void solve(int)’:
answer.code:20:79: error: expected ‘;’ before ‘}’ token
   20 |     For(i,1,lcnt) { int u=lis[i]; For(j,0,k) ckmax(ans[u],f[u][j]+tmp[u][k-j])/*,fprintf(stderr,"ans[%d] <- %d ( j=%d,f=%d,tmp=%d )\n",u,f[u][j]+tmp[u][k-j],j,f[u][j],tmp[u][k-j]);*/ }
      |                                                                               ^                                                                                                        ~
      |                                                                               ;