QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620328 | #2443. Dense Subgraph | IllusionaryDominance# | WA | 232ms | 15120kb | C++20 | 2.6kb | 2024-10-07 17:32:43 | 2024-10-07 17:32:45 |
Judging History
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 += max(a[son[u][j]], 0);
}
}
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 += max(a[son[v][j]], 0);
}
}
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 232ms
memory: 15120kb
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 102153110 900146658 552231233 761703357 751911994 810949217 284929205 648535032 573621091 168252011 240527753 476402587 903552946 237041491 747158935 785468862 810570046 160884103 350904388 233603624 664738901 235366080 238943913 473302333 456710344 780509728 398380677
result:
wrong answer 4th lines differ - expected: '60461799', found: '102153110'