QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670945 | #6437. Paimon's Tree | louhao088 | WA | 11ms | 3608kb | C++23 | 2.2kb | 2024-10-24 08:58:58 | 2024-10-24 08:58:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=150+5,M=3e5+5;
#define pb push_back
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1){x=-x;}return x;
}
int T,n,m,x,y,a[maxn];
long long f[maxn][maxn],g[maxn][maxn];
int sz[maxn],mx,F,flag[maxn];
int s[maxn],dis[maxn];
int D[maxn],cnt=0;
vector<int>e[maxn];
void dfs(int x,int fa){
dis[x]=dis[fa]+1;
if(dis[mx]<dis[x])mx=x;
for(auto i:e[x])if(i^fa){
dfs(i,x);
}
}
void getd(int x,int fa){
if(x==mx){
F=1;D[++cnt]=x;flag[x]=1;
return;
}
for(auto i:e[x])if(i!=fa&&!F){
getd(i,x);
}
if(F)D[++cnt]=x,flag[x]=1;
}
void getsz(int x,int fa){
sz[x]++;
for(auto i:e[x])if(i!=fa&&!flag[i]){
getsz(i,x);sz[x]+=sz[i];
}
}
int o=0;
void solve(){
n=read();
o++; if(o==48)cout<<n<<endl;
for(int i=1;i<=n;i++){
a[i]=read();
if(o==48)cout<<a[i]<<" ";
}
n++;
for(int i=1;i<n;i++){
x=read(),y=read(),e[x].pb(y),e[y].pb(x);
if(o==48)cout<<x<<" "<<y<<endl;
}//return ;
dfs(1,0);dis[mx]=0;int z=mx;
dfs(z,0);F=0;cnt=0;
getd(z,0);//return;
for(int i=0;i<=cnt;i++)getsz(D[i],0);
for(int j=1;j<=cnt;j++)s[j]=s[j-1]+sz[D[j]]-1;
for(int i=1;i<=cnt;i++)
for(int j=i;j<=cnt;j++)f[i][j]=0;
for(int i=1;i<n;i++){
for(int j=1;j<=cnt;j++){
for(int k=j;k<=cnt;k++){
g[j][k]=0;
if(s[k]-s[j-1]>=i-(k-j))g[j][k]=max(f[j][k],g[j][k]);
if(j!=k)g[j][k]=max(g[j][k],f[j+1][k]+a[i]);
if(j!=k)g[j][k]=max(g[j][k],f[j][k-1]+a[i]);
//cout<<g[j][k]<<" "<<j<<" "<<k<<endl;
}
}
for(int j=1;j<=cnt;j++)
for(int k=j;k<=cnt;k++)
f[j][k]=g[j][k];
}
if(T<=3)cout<<f[1][cnt]<<endl;
mx=0;F=0;
for(int i=1;i<=n;i++)e[i].clear(),dis[i]=0,flag[i]=0;
}
signed main(){
T=read();
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
2 5 1 7 3 5 4 1 3 2 3 3 4 4 5 4 6 1 1000000000 1 2
output:
16 1000000000
result:
ok 2 number(s): "16 1000000000"
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 3592kb
input:
5000 19 481199252 336470888 634074578 642802746 740396295 773386884 579721198 396628655 503722503 971207868 202647942 2087506 268792718 46761498 443917727 16843338 125908043 691952768 717268783 9 4 4 18 12 9 10 9 4 1 6 12 2 18 9 13 6 14 4 8 2 3 10 17 2 20 19 20 5 1 12 15 15 16 4 7 17 11 4 240982681 ...
output:
11 826964816 360169072 244734874 217736438 141593810 970513012 927840561 557460609 765705513 752533680 713801657 8 7 4 7 6 8 12 4 7 11 3 6 1 6 2 8 9 12 5 6 9 10 3528224153 6234619598 5890011026 6162055587
result:
wrong answer 1st numbers differ - expected: '5750811120', found: '11'