QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129936#6437. Paimon's TreekkioWA 483ms20156kbC++142.1kb2023-07-23 08:57:242023-07-23 08:57:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 08:57:27]
  • 评测
  • 测评结果:WA
  • 用时:483ms
  • 内存:20156kb
  • [2023-07-23 08:57:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=155,inf=1e18;
int n;
int f[maxn][maxn][maxn][4],a[maxn];
int fp[maxn][maxn];
int siz[maxn][maxn];
vector<int> G[maxn];
void dfs(int u,int F)
{
	siz[F][u]=1;
    for(int v:G[u])
        if(v!=fp[F][u])
        {
            fp[F][v]=u;
            dfs(v,F);
            siz[F][u]+=siz[F][v];
        }
}
inline void upd(int u,int v,int t,int k,int w)
{if(f[u][v][t][k]<w)f[u][v][t][k]=w;}
void solve()
{
    scanf("%lld",&n);n++;
    for(int i=1;i<n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)G[i].clear();
    for(int i=1;i<n;i++)
    {
        static int u,v;scanf("%lld%lld",&u,&v);
        G[u].push_back(v);G[v].push_back(u);
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)fp[i][j]=siz[i][j]=0;
    for(int i=1;i<=n;i++)dfs(i,i);
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int t=0;t<=n;t++)for(int k=0;k<=3;k++)f[i][j][t][k]=-inf;
	for(int i=1;i<=n;i++)f[i][i][0][3]=0;
	for(int t=0;t<n-1;t++)
		for(int k=3;k>=0;k--)
   			for(int u=1;u<=n;u++)
   				for(int v=1;v<=n;v++) 	
			   	{
					if(f[u][v][t][k]==-inf)continue;
					int fu=fp[v][u],fv=fp[u][v],w=f[u][v][t][k],g=(u==v)?0:n-siz[v][u]-siz[u][v]+__builtin_popcount(k);
					if(k==3)
					{
						for(int su:G[u])if(su!=fu)upd(su,v,t,1,w);
						for(int sv:G[v])if(sv!=fv)upd(u,sv,t,2,w);
						if(t+1<=g)upd(u,v,t+1,3,w);
					}		
					if(k==2)
					{
						for(int su:G[u])if(su!=fu)upd(su,v,t,0,w);
						upd(u,v,t+1,3,w+a[t+1]);
						if(t+1<=g)upd(u,v,t+1,2,w);
					}
					if(k==1)
					{
						for(int sv:G[v])if(sv!=fv)upd(u,sv,t,0,w);
						upd(u,v,t+1,3,w+a[t+1]);
						if(t+1<=g)upd(u,v,t+1,1,w); 
					}
					if(k==0)
					{
						upd(u,v,t+1,1,w+a[t+1]);
						upd(u,v,t+1,2,w+a[t+1]);
						if(t+1<=g)upd(u,v,t+1,0,w);
					}
			   	}
	int ans=-1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ans=max(ans,f[i][j][n-1][3]); 
    printf("%lld\n",ans);
    return;
}
signed main()
{
    int T;
    scanf("%lld",&T);
    while(T--)solve();
    return 0;
}
/*
1
5
1 7 3 5 4
1 3
2 3
3 4
4 5
4 6
*/

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7848kb

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: 483ms
memory: 20156kb

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'