QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620365 | #2443. Dense Subgraph | Cheek_support# | WA | 179ms | 18688kb | C++20 | 4.1kb | 2024-10-07 17:44:08 | 2024-10-07 17:44:08 |
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]=w[u][i]+max(0,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]=w[i][j]+max(0,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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 179ms
memory: 18688kb
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 651419449 756144299 88000235 630287119 425953669 544387975 639967305 261173036 746882272 110840718 826489492 350461053 8298248 963175623 889459317 522563537 316648545 437546737 432165369 258968324 177040325 712302832 617789498 75254078 634600456 151740100 265157868
result:
wrong answer 4th lines differ - expected: '60461799', found: '651419449'