QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620259 | #2443. Dense Subgraph | Cheek_support# | WA | 172ms | 18788kb | C++20 | 4.1kb | 2024-10-07 17:13:10 | 2024-10-07 17:13:20 |
Judging History
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]+w[x][j]>0){
;
}else{
F[i<<1|1]=inc(F[i<<1|1],mul(dp[u][i],dp[x][j]));
G[i<<1|1]=max(w[u][i],w[x][j]);
}
}
}
}
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]+w[x][k]>0){
;
}else{
F[j<<1|1]=inc(F[j<<1|1],mul(dp[i][j],dp[x][k]));
G[j<<1|1]=max(w[i][j],w[x][k]);
}
}
}
}
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: 172ms
memory: 18788kb
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 851968 460609834 751070348 65741582 281265511 686721260 742323103 341608267 449041719 292211773 478418331 168079407 214843001 521803669 245351483 295434319 425287929 484068670 905919420 688950324 810113202 678362924 712889698 792984977 777439142 634600456 787531777 565314250
result:
wrong answer 3rd lines differ - expected: '1048576', found: '851968'