QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#629481#6437. Paimon's Treeeggegg185WA 272ms18516kbC++142.7kb2024-10-11 12:22:172024-10-11 12:22:18

Judging History

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

  • [2024-10-11 12:22:18]
  • 评测
  • 测评结果:WA
  • 用时:272ms
  • 内存:18516kb
  • [2024-10-11 12:22:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n; vector<int> vecs[155];
int dp[155][155][155][2][2],a[155],sws[155][155],dep[155][155];
inline void foo(int& x,int y) {x = (x>y)?(x):(y);} //for convince
void dfs(int now,int pa,int c) {
	dep[c][now] = dep[c][pa]+1; sws[c][now] = 1;
	for(auto v:vecs[now]) {
		if(v == pa) continue; dfs(v,now,c);
		sws[c][now] += sws[c][v];
	}
}
void solve() { //damn, multitest???!
	cin >> n; n++; for(int i = 1; i < n; i++) {cin >> a[i]; vecs[i].clear();} vecs[n].clear();
	for(int i = 1; i < n; i++) {
		int u,v; cin >> u >> v;
		vecs[u].push_back(v); vecs[v].push_back(u);
	}
	for(int i = 1; i <= n; i++) dfs(i,0,i);
	for(int k = 0; k < n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
		dp[k][i][j][0][0] = dp[k][i][j][0][1] = dp[k][i][j][1][0] = dp[k][i][j][1][1] = -0x3f3f3f3f3f3f3f3f;
	}
	for(int i = 1; i <= n; i++) {
		for(auto v:vecs[i]) {
			dp[0][i][v][1][0] = dp[0][v][i][0][1] = 0;
			for(auto w:vecs[i]) if(v != w) dp[0][w][v][0][0] = 0;
		}
	}
	for(int k = 0; k < n-1; k++) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				foo(dp[k+1][i][j][1][1],dp[k][i][j][1][1]); //ci && cj
				//!ci && cj
				foo(dp[k+1][i][j][1][1],dp[k][i][j][0][1]+a[k+1]); 
				if(k < n+1-sws[j][i]) foo(dp[k+1][i][j][0][1],dp[k][i][j][0][1]);
				for(auto v:vecs[i]) {
					if(dep[v][j] < dep[i][j]) continue;
					foo(dp[k+1][v][j][0][1],dp[k][i][j][0][1]+a[k+1]);
				}
				//ci && !cj
				foo(dp[k+1][i][j][1][1],dp[k][i][j][1][0]+a[k+1]); 
				if(k < n+1-sws[i][j]) foo(dp[k+1][i][j][1][0],dp[k][i][j][1][0]);
				for(auto v:vecs[j]) {
					if(dep[v][i] < dep[j][i]) continue;
					foo(dp[k+1][i][v][1][0],dp[k][i][j][1][0]+a[k+1]);
				}
				//!ci && !cj
				foo(dp[k+1][i][j][1][0],dp[k][i][j][0][0]+a[k+1]);
				foo(dp[k+1][i][j][0][1],dp[k][i][j][0][0]+a[k+1]);
				if(k < n+2-sws[i][j]-dep[i][j]-sws[j][i]-dep[j][i]) foo(dp[k+1][i][j][0][0],dp[k][i][j][0][0]);
				for(auto v:vecs[i]) {
					if(dep[v][j] < dep[i][j]) continue;
					foo(dp[k+1][v][j][0][0],dp[k][i][j][0][0]+a[k+1]);
				}
				for(auto v:vecs[j]) {
					if(dep[v][i] < dep[j][i]) continue;
					foo(dp[k+1][i][v][0][0],dp[k][i][j][0][0]+a[k+1]);
				}
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) for(int ci = 0; ci < 2; ci++) 
		for(int cj = 0; cj < 2; cj++) ans = max(ans,dp[n-1][i][j][ci][cj]);
	}
	printf("%lld\n",ans);
	for(int i = 1; i <= n; i++) vecs[i].clear();
}
signed main() {
	//freopen("length.in","r",stdin);
	//freopen("length.out","w",stdout);
	cin.tie(0)->sync_with_stdio(false);
	int T; cin >> T; while(T--) solve();
	return 0;
}

详细

Test #1:

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

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: 272ms
memory: 18516kb

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
4185088775
4140156713
5361004844
1875024569
3690026656
3164300370
3412485417
7303703112
5152145282
2355946110
3090496776
5582927591
4729664767
2207592767
572868833
4746866517
2944749369
2538044586
3083947956
5534713385
1421427135
3971435093
1197051728
396588615
251138097
221986...

result:

wrong answer 3rd numbers differ - expected: '4208559611', found: '4185088775'