QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620264 | #2443. Dense Subgraph | IllusionaryDominance# | WA | 242ms | 15144kb | C++20 | 2.8kb | 2024-10-07 17:14:27 | 2024-10-07 17:14:37 |
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 << cnt[u]); s ++) {
if (s >> i & 1) {
if (a[u] + a[v] > 0) continue;
char flag = 1;
for (int j = 0; j < cnt[u]; j ++) {
if (j != i && (s >> j & 1)) {
if (a[u] + a[v] + a[son[u][j]] > 0) {
flag = 0; break;
}
}
}
if (!flag) continue;
for (int t = 0; t < (1 << cnt[v]); t ++) {
flag = 1;
for (int j = 0; j < cnt[v]; j ++) {
if (t >> j & 1) {
if (a[u] + a[v] + a[son[v][j]] > 0) {
flag = 0; break;
}
}
}
if (flag) {
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: 242ms
memory: 15144kb
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 428648761 799497565 840192586 473482800 609525844 303887775 58962594 681428379 354510769 934532981 98847637 345684331 499832606 18379714 234468663 882529214 813940859 507777499 676975680 298509209 615823216 318541589 63608091 225664347 634600456 743329186 504363306
result:
wrong answer 4th lines differ - expected: '60461799', found: '428648761'