QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662226 | #9449. New School Term | caijianhong | WA | 0ms | 3548kb | C++20 | 3.0kb | 2024-10-20 22:03:51 | 2024-10-20 22:03:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
template <unsigned umod>
struct modint {/*{{{*/
static constexpr int mod = umod;
unsigned v;
modint() = default;
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
modint(const T& y) : v((unsigned)(y % mod + (is_signed<T>() && y < 0 ? mod : 0))) {}
modint& operator+=(const modint& rhs) { v += rhs.v; if (v >= umod) v -= umod; return *this; }
modint& operator-=(const modint& rhs) { v -= rhs.v; if (v >= umod) v += umod; return *this; }
modint& operator*=(const modint& rhs) { v = (unsigned)(1ull * v * rhs.v % umod); return *this; }
modint& operator/=(const modint& rhs) { assert(rhs.v); return *this *= qpow(rhs, mod - 2); }
friend modint operator+(modint lhs, const modint& rhs) { return lhs += rhs; }
friend modint operator-(modint lhs, const modint& rhs) { return lhs -= rhs; }
friend modint operator*(modint lhs, const modint& rhs) { return lhs *= rhs; }
friend modint operator/(modint lhs, const modint& rhs) { return lhs /= rhs; }
template <class T> friend modint qpow(modint a, T b) {
modint r = 1;
for (assert(b >= 0); b; b >>= 1, a *= a) if (b & 1) r *= a;
return r;
}
friend int raw(const modint& self) { return self.v; }
friend ostream& operator<<(ostream& os, const modint& self) { return os << raw(self); }
explicit operator bool() const { return v != 0; }
};/*}}}*/
using mint = modint<998244353>;
int n, m, fa[10010], siz[10010];
int leader(int x) { return x == fa[x] ? x : fa[x] = leader(fa[x]); }
mint f[5010];
void add(int x) {
if (!x) return ;
for (int i = n; i >= x; i--) f[i] += f[i - x];
}
void del(int x) {
if (!x) return ;
for (int i = x; i <= n; i++) f[i] -= f[i - x];
}
void merge(int x, int y) {
x = leader(x), y = leader(y);
if (x == y) return ;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y], fa[y] = x;
}
int main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cin >> n >> m, n <<= 1;
for (int i = 1; i <= n * 2; i++) fa[i] = i, siz[i] = i <= n;
f[0] = 1;
for (int i = 1; i <= n; i++) add(1);
vector<pair<int, int>> edg(m);
for (int i = 0; i < m; i++) cin >> edg[i].first >> edg[i].second;
reverse(edg.begin(), edg.end());
for (int i = 1; i <= n; i++) edg.emplace_back(1, i);
for (auto&& e : edg) {
int u = e.first, v = e.second;
debug("u = %d, v = %d\n", u, v);
if (leader(u) == leader(v)) continue;
if (leader(u) == leader(v + n)) continue;
int x = leader(u), y = leader(v + n);
del(siz[x]), del(siz[y]), add(siz[x] + siz[y]);
if (f[n / 2]) merge(u, v + n), merge(v, u + n), debug("mgd\n");
else del(siz[x] + siz[y]), add(siz[x]), add(siz[y]);
}
debug("siz[leader(1)] = %d\n", siz[leader(1)]);
for (int i = 1; i <= n * 2; i++) debug("%d ", leader(i));
for (int i = 1; i <= n; i++) cout << (leader(1) == leader(i));
cout << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3548kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1000
result:
wrong answer The number of 0s must be equal to that of 1s.