QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620401#2443. Dense SubgraphLavender_Field#WA 273ms14004kbC++204.2kb2024-10-07 17:58:152024-10-07 17:58:16

Judging History

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

  • [2024-10-07 17:58:16]
  • 评测
  • 测评结果:WA
  • 用时:273ms
  • 内存:14004kb
  • [2024-10-07 17:58:15]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define pb push_back
using namespace std;
inline int rd() {
    int r = 0; bool w = false; char ch = getchar();
    while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
    while( ch >= '0' && ch <= '9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
    return w ? -r : r;
}

#define MAXN 35000
const int mod = 1e9+7;
const int qpow3[] = {1, 3, 9, 27, 81, 243};
int n, x;
int a[MAXN+5];
bool minimal_status[MAXN+5][32];
vector<int> to[MAXN+5], son[MAXN+5]; int fa[MAXN+5];
vector<int> constraint[MAXN+5];
void dft( int u ) {
    for(auto v: to[u]) if( fa[u] != v ) {
        fa[v] = u;
        son[u].pb(v);
        dft(v);
    }
}
inline void add( int u , int v ) {
    to[u].pb(v);
}
int f[MAXN+5], g[MAXN+5], h[MAXN+5];
bool chk( int u , int typ , int sta ) {
    int tmpsta = sta;
    if( typ >= 1 ) {
        for(int j = 0; j < son[u].size(); ++j) {
            if( tmpsta % 3 == 2 ) return false;
            tmpsta /= 3;
        }
    }
    bool typ2_topflag = false;
    for(auto st: constraint[u]) {
        if( typ == 0 ) {
            ;
        } else if( typ == 1 ) {
            bool flag = false;
            for(int j = 0; j < son[u].size(); ++j) {
                if( (st>>j & 1) == 1 && sta / qpow3[j] == 0 ) {
                    flag = true;
                    break;
                }
            }
            if( flag == false ) return false;
        } else if( typ == 2 ) {
            if( (st >> son[u].size()) & 1 ) {
                bool flag = false;
                for(int j = 0; j < son[u].size(); ++j) {
                    if( (st>>j & 1) == 1 && sta / qpow3[j] == 0 ) {
                        flag = true;
                        break;
                    }
                }
                if( flag == false ) typ2_topflag = true;
            } else {
                bool flag = false;
                for(int j = 0; j < son[u].size(); ++j) {
                    if( (st>>j & 1) == 1 && sta / qpow3[j] == 0 ) {
                        flag = true;
                        break;
                    }
                }
                if( flag == false ) return false;
            }
        }
    }
    if( typ == 2 && typ2_topflag == false ) return false;
    return true;
}
void dfs( int u ) {
    if( son[u].size() == 0 ) {
        f[u] = g[u] = 1;
        return;
    }
    for(auto v: son[u]) dfs(v);
    for(int s = 0; s < qpow3[son[u].size()]; ++s) {
        int mul = 1;
        int tmps = s;
        for(int j = 0; j < son[u].size(); ++j) {
            int v = son[u][j];
            mul = 1ll * mul * (tmps%3 == 0 ? f[v] : (tmps%3 == 1 ? g[v] : h[v]));
            tmps /= 3;
        }
        if( chk(u,0,s) ) f[u] = (f[u] + mul) % mod;
        if( chk(u,1,s) ) g[u] = (g[u] + mul) % mod;
        if( chk(u,2,s) ) h[u] = (h[u] + mul) % mod;
    }
    // printf("%d: %d %d %d\n", u, f[u], g[u], h[u]);
}   
int popcount( int x ) {
    int ret = 0;
    while( x ) ret += (x&1), x >>= 1;
    return ret;
}
void solve() {
    n = rd(), x = rd();
    FOR(i,1,n) a[i] = rd() - x;
    FOR(i,1,n-1) {
        int u = rd(), v = rd();
        add(u,v), add(v,u);
    }
    dft(1);
    FOR(i,1,n) {
        for(int s = 1; s < 1 << to[i].size(); ++s) {
            if( minimal_status[i][s] ) continue;
            int sum = a[i];
            if( i != 1 && (s>>(to[i].size()-1)) ) sum += a[fa[i]];
            for(int j = 0; j < son[i].size(); ++j) {
                if( s>>j & 1 ) sum += a[son[i][j]];
            }
            if( sum > 0 ) {
                for(int S = s; S < 1 << to[i].size(); S = (S + 1) | s) {
                    minimal_status[i][S] = true;
                }
                if( i != 1 && ((s >> son[i].size()) & 1) && popcount(s) == 1 ) {
                    ;
                }
                else constraint[i].pb(s);
            }
        }
    }
    dfs(1);
    printf("%d\n", (f[1] + g[1]) % mod);
    FOR(i,1,n) to[i].clear(), son[i].clear(), fa[i] = 0, constraint[i].clear(), memset(minimal_status[i], 0, sizeof(minimal_status[0]));
    FOR(i,1,n) f[i] = g[i] = h[i] = 0;
    return;
}

int main() {
    int T = rd(); while( T-- ) solve();
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 273ms
memory: 14004kb

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:

280
2880
1048576
0
0
0
0
-692943153
0
-358266020
0
755251652
0
0
-420991777
0
0
0
216901945
0
-348226488
0
0
-198555585
0
0
0
-834099850
0
-317390746

result:

wrong answer 1st lines differ - expected: '320', found: '280'