QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718907#6437. Paimon's TreeqwqUwU_WA 225ms8068kbC++141.5kb2024-11-06 21:45:242024-11-06 21:45:25

Judging History

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

  • [2024-11-06 21:45:25]
  • 评测
  • 测评结果:WA
  • 用时:225ms
  • 内存:8068kb
  • [2024-11-06 21:45:24]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll; 
typedef unsigned long long ull;
typedef pair<int,int> pii;
inline ll read(){
	ll x=0,f=1,c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
const int N=153;
int n,a[N];
ll f[N][N][N];
vector<int>G[N];
int rt;
int sz[N][N],F[N][N];
inline void dfs(int u,int fa){
	F[rt][u]=fa; sz[rt][u]=1;
	for(int v:G[u])if(v!=fa)dfs(v,u),sz[rt][u]+=sz[rt][v];
}
inline void ck(ll &x,ll y){if(y>x)x=y;}
inline void solve(){
	n=read();rep(i,1,n)a[i]=read();
	rep(i,1,n+1)G[i].clear();
	rep(i,1,n){
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
	}
	rep(i,1,n+1) dfs(rt=i,0);
	rep(i,0,n)rep(j,1,n+1)rep(k,1,n+1)f[i][j][k]=0;
	rep(i,1,n+1)f[0][i][i]=0;
	rep(i,0,n-1)rep(u,1,n+1)rep(v,1,n+1)if(f[i][u][v]!=-1){
		ck(f[i+1][u][v],f[i][u][v]);
		for(int w:G[u])if(w!=F[v][u]&&i<=n-sz[v][w])ck(f[i+1][w][v],f[i][u][v]+a[i+1]);
		if(u==v)continue;
		for(int w:G[v])if(w!=F[u][v]&&i<=n-sz[u][w])ck(f[i+1][u][w],f[i][u][v]+a[i+1]);
	}
	ll ans=0;
	rep(u,1,n+1)rep(v,1,n+1)ans=max(ans,f[n][u][v]);
	printf("%lld\n",ans);
}
int main() {
    //freopen("data.in", "r", stdin);
    // freopen("myans.out","w",stdout);
	int T=read();while(T--)solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3908kb

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: 225ms
memory: 8068kb

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:

5750811120
1896999359
4208559611
4140156713
5361004844
1875024569
3690026656
3702623113
3412485417
7807375141
5341435147
2355946110
3090496776
5626636202
4729664767
2207592767
572868833
4759005973
2944749369
2538044586
3083947956
5757497518
1421427135
3971435093
1197051728
396588615
251138097
221986...

result:

wrong answer 48th numbers differ - expected: '5317528311', found: '5514819848'