The 2nd Universal Cup. Stage 5: Northern J Sets May Be Good
题解#
我们考虑计算 ,这里 表示 集合的导出子图的边数。
我们记 。
我们考虑删掉 号点。
注意到如果 的取值会影响 的奇偶性,则正负相消,贡献为 。
所以我们需要保证下列条件满足:
我们考虑是否存在位置 ,满足 。
-
如果不存在这样的 ,那我们根据 的取值分类讨论:
- ,则贡献乘 ;
- ,贡献变成 。
-
如果存在一个位置 ,满足 。
那么,根据 ,我们可以得出:
我们考虑对于一个序列 计算答案。
于是,我们就可以把 的矩阵,在 的时间内,变成 的矩阵。
注意到 有两种取值,所以贡献要 。注意到上述式子继续展开,则 的项,所以贡献可能 。
总时间复杂度 。
代码#
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 1010, MOD = 998244353, inv2 = (MOD + 1) >> 1;
int n, m, ans = 1, t = 1;
bitset <N> a[N];
signed main() {
read(n), read(m);
F(i, 1, n) t = 2 * t % MOD;
F(i, 1, m) {
int x, y; read(x), read(y);
a[x][y] = a[y][x] = true;
}
DF(i, n, 1) {
bool flag = false;
F(j, 1, i - 1) flag |= a[i][j];
if (flag) {
int pos = -1;
F(j, 1, i - 1)
if (a[j][i]) {
pos = j;
break;
}
assert(~pos);
a[i][pos] = false;
F(j, 1, i - 1) if (j != pos && a[pos][j]) {
a[j] ^= a[i];
if (a[i][i] ^ a[i][j]) a[j][j].flip();
}
F(j, 1, i - 1) if (j != pos && a[i][j]) {
a[j] ^= a[pos];
}
if (a[pos][pos]) {
F(j, 1, i - 1)
if (j != pos && a[i][j]) a[j][j].flip();
if (a[i][i]) ans = (ll) ans * (MOD - 1) % MOD;
}
F(j, 1, i - 2) {
if (j >= pos) a[j] = a[j + 1];
bitset <N> s = (a[j] >> pos);
a[j] = a[j] ^ (s << pos) ^ ((s >> 1) << pos);
}
i--;
ans = (ll) ans * 2 % MOD;
} else if (!a[i][i]) ans = (ll) ans * 2 % MOD;
else ans = 0;
}
cout << (ll) (t + ans) * inv2 % MOD;
return 0;
}
/* why?
*/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律