QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620319#2443. Dense SubgraphIllusionaryDominance#WA 245ms15268kbC++202.6kb2024-10-07 17:30:382024-10-07 17:30:48

Judging History

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

  • [2024-10-07 17:30:48]
  • 评测
  • 测评结果:WA
  • 用时:245ms
  • 内存:15268kb
  • [2024-10-07 17:30:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 35000 + 5;
const int P = 1e9 + 7;

int N, a[MAX_N];
vector <int> edge[MAX_N];
int f[MAX_N][17], son[MAX_N][4], cnt[MAX_N];

inline int add(int a, int b) {return a < P - b ? a + b : a - P + b;}

void dfs(int u, int fa) {
    f[u][0] = 1;
    f[u][16] = 1;
    for (int i = 0; i < (int)edge[u].size(); i ++) {
        if (edge[u][i] != fa) {
            dfs(edge[u][i], u);
            son[u][cnt[u] ++] = edge[u][i];
        }
    }
    for (int i = 0; i < cnt[u]; i ++) {
        int v = son[u][i], sum = f[v][16];
        for (int s = 0; s < (1 << cnt[v]); s ++) sum = add(sum, f[v][s]);
        // fprintf(stderr, "u = %d, v = %d, sum = %d\n", u, v, sum);
        int g[17]; memset(g, 0, sizeof g);
        g[16] = 1ll * f[u][16] * sum % P;
        for (int s = 0; s < (1 << i + 1); s ++) {
            if (s >> i & 1) {
                if (a[u] + a[v] > 0) continue;
                sum = 0;
                for (int j = 0; j < cnt[u]; j ++) {
                    if (s >> j & 1) {
                        sum += a[son[u][j]];
                    }
                }
                if (a[u] + sum > 0) continue;
                for (int t = 0; t < (1 << cnt[v]); t ++) {
                    sum = 0;
                    for (int j = 0; j < cnt[v]; j ++) {
                        if (t >> j & 1) {
                            sum += a[son[v][j]];
                        }
                    }
                    if (sum + a[u] + a[v] <= 0) {
                        g[s] = (g[s] + 1ll * f[u][s ^ (1 << i)] * f[v][t]) % P;
                    }
                }
            }else {
                g[s] = 1ll * f[u][s] * f[v][16] % P;
            }
        }
        memcpy(f[u], g, sizeof g);
    }
    // fprintf(stderr, "u = %d\n", u);
    // for (int i = 0; i < 17; i ++) fprintf(stderr, "i = %d, f = %d\n", i, f[u][i]);
}

void solve() {
    int x;
    cin >> N >> x;
    for (int i = 1; i <= N; i ++) {
        cin >> a[i]; a[i] -= x;
        edge[i].clear();
        cnt[i] = 0;
        memset(f[i], 0, sizeof f[i]);
        memset(son[i], 0, sizeof son[i]);
    }
    for (int i = 1; i < N; i ++) {
        int x, y;
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    dfs(1, 0);
    int ans = 0;
    for (int i = 0; i < 17; i ++) ans = add(ans, f[1][i]);
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int T;
    cin >> T;
    while (T --) solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 245ms
memory: 15268kb

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
573020976
936285404
891118388
203784088
366193774
819902712
403041554
789512300
354510769
2355635
608076951
982971802
558411802
375240277
891491154
810970953
789027377
934582605
46994780
440576798
615823216
332193026
958424864
357809517
634600456
344550664
470455432

result:

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