QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72665 | #4815. Flower's Land | xuqin | Compile Error | / | / | C++ | 2.7kb | 2023-01-17 19:53:27 | 2023-01-17 19:53:28 |
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-17 19:53:28]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-01-17 19:53:27]
- 提交
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=40020, maxk=3020;
struct pj{int y, nxt;} gg[maxn<<1];
int Len, la[maxn], a[maxn], n, k, sz[maxn], son[maxn];
long long f[maxn][maxk], g[maxn][maxk], tmp[maxk], h[maxk], u[maxn][maxk];
void add_e(int x, int y) {
gg[++Len].y=y; gg[Len].nxt=la[x]; la[x]=Len;
}
void dfs(int x, int F) {
sz[x]=1;
for(int i=la[x]; i; i=gg[i].nxt) {
int y=gg[i].y;
if(y!=F) dfs(y, x), sz[x]+=sz[y];
}
tmp[0]=0;
int pre=0;
for(int i=la[x]; i; i=gg[i].nxt) {
int y=gg[i].y;
if(y==F) continue;
for(int j=0; j<=pre+sz[y]&&j<k; ++j) h[j]=-1e18;
for(int j=0; j<=pre&&j<k; ++j)
for(int l=0; l<=sz[y]&&l+j<k; ++l) h[j+l]=max(h[j+l], tmp[j]+f[y][l]);
for(int j=0; j<=pre+sz[y]&&j<k; ++j) tmp[j]=h[j];
pre+=sz[y];
}
for(int i=1; i<=k&&i<=sz[x]; ++i) f[x][i]=tmp[i-1]+a[x]; f[x][0]=0;
}
void dfs1(int x, int F) {
int cnt=0, sum=n-sz[x];
for(int i=0; i<k-1&&i<=sum; ++i) u[0][i]=g[x][i+1]-a[x];
for(int i=la[x]; i; i=gg[i].nxt) {
int y=gg[i].y;
if(y==F) continue;
son[++cnt]=y;
for(int j=0; j<k-1&&j<=sum; ++j)
for(int l=0; l<=sz[y]&&l+j<k-1; ++l) u[y][l+j]=max(u[y][l+j], u[son[cnt-1]][j]+f[y][l]);
sum+=sz[y];
}
tmp[0]=0;
int pre=0;
for(int i=cnt; i; --i) {
// for(int j=0; j<=pre; ++j) printf("%lld ", tmp[j]); puts("");
int y=son[i]; sum-=sz[y];
// printf("sum=%d pre=%d\n", sum, pre);
for(int j=0; j<k-1&&j<=sum; ++j)
for(int l=0; l<=pre&&l+j<k-1; ++l)
g[y][j+l+2]=max(g[y][l+j+2], a[x]+a[y]+u[son[i-1]][j]+tmp[l]);
g[y][1]=a[y]; g[y][0]=0;
// for(int j=0; j<=sum+pre&&j<k-1; ++j) assert(g[y][j]>=0);
if(i==cnt) {for(int j=1; j<k-1&&j<=sz[y]; ++j) tmp[j]=f[y][j];}
else {
for(int j=0; j<=pre+sz[y]&&j<k-1; ++j) h[j]=-1e18;
for(int j=0; j<=pre&&j<k-1; ++j)
for(int l=0; l<=sz[y]&&l+j<k-1; ++l)
h[l+j]=max(h[l+j], tmp[j]+f[y][l]);
for(int j=0; j<=pre+sz[y]&&j<k-1; ++j) tmp[j]=h[j];
}
pre+=sz[y];
}
for(int i=la[x]; i; i=gg[i].nxt) {
int y=gg[i].y;
if(y!=F) dfs1(y, x);
}
}
int main() {
int ttttt;
ttttt=scanf("%d%d", &n, &k);
for(int i=1; i<=n; ++i) ttttt=scanf("%d", a+i);
for(int i=1, x, y; i<n; ++i)
ttttt=scanf("%d%d", &x, &y), add_e(x, y), add_e(y, x);
memset(f, 0xcc, sizeof f);
memset(g, 0xcc, sizeof g);
memset(u, 0xcc, sizeof u);
dfs(1, 0);
g[1][1]=a[1]; g[1][0]=0;
dfs1(1, 0);
// for(int i=1; i<=n; ++i)
// for(int j=1; j<=k; ++j) printf("[%d][%d]:%lld %lld\n", i, j, u[i][j], g[i][j]);
for(int i=1; i<=n; ++i) {
long long ans=-1e18;
for(int j=1; j<=k; ++j) ans=max(ans, f[i][j]+g[i][k+1-j]-a[i]);
printf("%lld ", ans);
}
return 0;
}
/*
7 4
1 3 2 1 7 12 17
4 6
1 4
5 1
2 5
7 6
3 2
*/
详细
/tmp/ccAmyGM8.o: in function `add_e(int, int)': answer.code:(.text+0x6): relocation truncated to fit: R_X86_64_PC32 against symbol `Len' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0xd): relocation truncated to fit: R_X86_64_PC32 against symbol `la' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x22): relocation truncated to fit: R_X86_64_PC32 against symbol `gg' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x2e): relocation truncated to fit: R_X86_64_PC32 against symbol `Len' defined in .bss section in /tmp/ccAmyGM8.o /tmp/ccAmyGM8.o: in function `dfs(int, int)': answer.code:(.text+0x50): relocation truncated to fit: R_X86_64_PC32 against symbol `la' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x5e): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x89): relocation truncated to fit: R_X86_64_PC32 against symbol `gg' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0xb2): relocation truncated to fit: R_X86_64_PC32 against symbol `sz' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0xc9): relocation truncated to fit: R_X86_64_PC32 against symbol `k' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x116): relocation truncated to fit: R_X86_64_PC32 against symbol `gg' defined in .bss section in /tmp/ccAmyGM8.o answer.code:(.text+0x133): additional relocation overflows omitted from the output collect2: error: ld returned 1 exit status