QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#69586 | #2443. Dense Subgraph | he_ren_shi_lyp# | WA | 501ms | 21904kb | C++23 | 2.5kb | 2022-12-28 20:16:37 | 2022-12-28 20:16:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int B = 5;
const int mod = 998244353;
const int inv2 = (mod + 1) / 2;
const int inf = 0x3f3f3f3f;
inline int inc(int x, int y) { x += y - mod; return x + (x >> 31 & mod); }
inline int dec(int x, int y) { x -= y; return x + (x >> 31 & mod); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
auto inc(const auto &first, const auto ...args) {
return inc(first, inc(args...));
}
auto mul(const auto &first, const auto ...args) {
return mul(first, mul(args...));
}
inline void upd(int &x, int y) { x = inc(x, y); }
inline void dpu(int &x, int y) { x = dec(x, y); }
inline void pud(int &x, int y) { x = mul(x, y); }
int n, X, a[N], fa[N], dp[N][3];
bool ban[N][1 << B][2];
vector<int> G[N], sons[N];
void dfs(int x, int f) {
fa[x] = f;
for (int y : G[x]) if (y != f) {
sons[x].push_back(y);
dfs(y, x);
}
for (int mask = 0; mask < (1 << sons[x].size()); ++mask) {
for (int o_fa : {0, 1}) {
int sum = 0, cnt = 0;
for (int i = 0; i < sons[x].size(); ++i)
if (mask >> i & 1) {
sum += a[sons[x][i]];
++cnt;
}
if (o_fa) {
sum += a[fa[x]];
++cnt;
}
sum += a[x];
++cnt;
if (cnt > 1 && sum > X * cnt) {
ban[x][mask][o_fa] = true;
}
}
}
}
void solve(int x) {
for (int y : sons[x]) {
solve(y);
}
// father is chosen
// 0: x is chosen, fa[x] is NOT chosen
// 1: x is chosen, fa[x] is chosen
// 2: x is not chosen
for (int o : {0, 1}) {
if (x == 1 && o == 1) continue;
for (int mask = 0; mask < (1 << sons[x].size()); ++mask) {
if (ban[x][mask][o])
continue;
int ways = 1;
for (int i = 0; i < sons[x].size(); ++i)
if (mask >> i & 1) {
pud(ways, dp[sons[x][i]][1]);
}
else {
pud(ways, dp[sons[x][i]][2]);
}
upd(dp[x][o], ways);
}
}
int ways = 1;
for (int y : sons[x]) {
pud(ways, inc(dp[y][0], dp[y][2]));
}
dp[x][2] = ways;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
cin >> n >> X;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i < n; ++i) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(1, 0);
solve(1);
cout << inc(dp[1][0], dp[1][2]) << '\n';
memset(ban, 0, sizeof ban);
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; ++i) {
G[i].clear();
sons[i].clear();
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 501ms
memory: 21904kb
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 955648560 84228328 704609901 228883793 355131524 532196970 23752208 596034203 109545683 743343083 811341273 166463155 323064293 467295052 713217476 341633523 351345818 89346911 3675507 330620099 581503581 895580834 696195923 546479849 466627391 979447457 189180904
result:
wrong answer 4th lines differ - expected: '60461799', found: '955648560'