QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620303#2443. Dense SubgraphCheek_support#WA 174ms18748kbC++204.1kb2024-10-07 17:25:362024-10-07 17:25:42

Judging History

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

  • [2024-10-07 17:25:42]
  • 评测
  • 测评结果:WA
  • 用时:174ms
  • 内存:18748kb
  • [2024-10-07 17:25:36]
  • 提交

answer

#pragma GCC optimizeA("Ofast")
#pragma GCC optimizeA("inline")
#pragma GCC optimizeA("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
#define mod 1000000007
#define DEBUG_VAR(x) { cerr << "* "#x" = " << x << endl; }
using namespace std;
template<typename T> void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T> void chkmax(T &x,T y){x=x>y?x:y;}
template<typename T> void read(T &num){
    char c=getchar();T f=1;num=0;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
    num*=f;
}
template<typename T> T inc(T x,T y){return (x+y>=mod)?(x+y-mod):(x+y);}
template<typename T> T dec(T x,T y){return (x-y<0)?(x-y+mod):(x-y);}
int mul(int x,int y){return (1ll*x*y)%mod;}

const int N=35000;
int a[N+10];
vector<int>ver[N+10];

bool vis[N+10];
int dp[N+10][1<<5];
int w[N+10][1<<5];
int F[1<<6],G[1<<6];
int Num(int x,int i){
    return ((x>>(i-1))&1);
}
void dfs(int u,int fr){
    vis[u]=1;
    dp[u][0]=1;w[u][0]=0;
    dp[u][1]=1;w[u][1]=a[u];

    int cnt=1;
    for(auto x:ver[u]){
        if(vis[x])continue;
        dfs(x,u);
        if(!fr)continue;
        cnt++;
        int L=(int)ver[x].size();

        rep(i,0,(1<<cnt)-1)F[i]=G[i]=0;

        rep(i,0,(1<<(cnt-1))-1){
            rep(j,0,(1<<L)-1){
                if(!Num(i,cnt-1)){
                    F[i<<1|Num(j,L)]=inc(F[i<<1|Num(j,L)],mul(dp[u][i],dp[x][j]));
                    G[i<<1|Num(j,L)]=0;
                }else if(!Num(j,L)){
                    F[i<<1]=inc(F[i<<1],mul(dp[u][i],dp[x][j]));
                    G[i<<1]=w[u][i];
                }else{
                    if(w[u][i]+a[x]>0){
                        ;
                    }else{
                        F[i<<1|1]=inc(F[i<<1|1],mul(dp[u][i],dp[x][j]));
                        G[i<<1|1]=w[u][i]+max(0,a[x]);
                    }
                }
            }
        }

        rep(i,0,(1<<cnt)-1){
            dp[u][i]=F[i];
            w[u][i]=G[i];
        }
    }
    return;
}
int main()
{
    // freopen("1.in", "r", stdin);
    
    int T;
    read(T);
    while(T--){
        int n,x;
        read(n);read(x);
        rep(i,1,n){
            vis[i]=0;
            ver[i].clear();
        }

        rep(i,1,n){
            read(a[i]);
            a[i]-=x;
        }
        rep(i,1,n-1){
            int u,v;
            read(u);read(v);

            ver[u].push_back(v);
            ver[v].push_back(u);
        }

        int ans=1;
        rep(i,1,n){
            if(vis[i])continue;
            
            dfs(i,0);

            dp[i][0]=1;w[i][0]=0;
            dp[i][1]=1;w[i][1]=a[i];

            int cnt=1;
            for(auto x:ver[i]){
                cnt++;
                int L=(int)ver[x].size();

                rep(j,0,(1<<cnt)-1)F[j]=G[j]=0;

                rep(j,0,(1<<(cnt-1))-1){
                    rep(k,0,(1<<L)-1){
                        if(!Num(j,cnt-1)){
                            F[j<<1|Num(k,L)]=inc(F[j<<1|Num(k,L)],mul(dp[i][j],dp[x][k]));
                            G[j<<1|Num(k,L)]=0;
                        }else if(!Num(k,L)){
                            F[j<<1]=inc(F[j<<1],mul(dp[i][j],dp[x][k]));
                            G[j<<1]=w[i][j];
                        }else{
                            if(w[i][j]+a[x]>0){
                                ;
                            }else{
                                F[j<<1|1]=inc(F[j<<1|1],mul(dp[i][j],dp[x][k]));
                                G[j<<1|1]=w[i][j]+max(0,a[x]);
                            }
                        }
                    }
                }

                if(x==ver[i].back())continue;
                rep(j,0,(1<<cnt)-1){
                    dp[i][j]=F[j];
                    w[i][j]=G[j];
                }
            }

            int sum=0;
            rep(j,0,(1<<cnt)-1){
                sum=inc(sum,F[j]);
            }
            ans=mul(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 174ms
memory: 18748kb

input:

30
10 11086
10189 24947 2265 9138 27104 12453 15173 3048 30054 2382
8 1
1 4
5 10
10 4
3 5
2 10
9 7
6 10
7 1
15 9664
4127 24649 13571 8586 34629 8644 3157 33133 3713 32646 29412 8108 13583 21362 23735
14 9
7 1
15 12
10 15
2 6
3 11
9 1
1 11
6 12
4 10
13 15
8 15
12 11
5 3
20 29310
21738 9421 8412 4617 ...

output:

320
3312
1048576
304926454
90333020
834375853
453695255
105546193
295866283
806094063
496494654
746882272
325175130
741751762
593418514
112175948
761222803
910534743
57311589
900991439
560190392
824325199
437014384
615823216
20073114
298725538
320439757
634600456
145375028
633110480

result:

wrong answer 4th lines differ - expected: '60461799', found: '304926454'