QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134368 | #5437. Graph Completing | SnowNorth | WA | 1ms | 3572kb | C++14 | 2.1kb | 2023-08-03 18:12:39 | 2023-08-03 18:12:40 |
Judging History
answer
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
const int N = 5005;
const int M = N << 1;
using ll = long long ;
struct Edge {
int to, nxt;
}edge[M];
int n, m, _u[N], _v[N], head[N], cnt = 1;
int low[N], dfn[N], tim;
stack<int> st;
int bl[N], num[N], tot;
int two[M], siz[N], f[N][N], g[N];
void conn(int u, int v) {
edge[++cnt] = {v, head[u]};
head[u] = cnt;
}
void tarjan(int u, int inEg) {
low[u] = dfn[u] = ++tim;
st.push(u);
for (int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].to;
if (!dfn[v]) {
tarjan(v, i);
low[u] = min(low[u], low[v]);
} else if (i != (inEg ^ 1))
low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u]) {
++tot;
while (true) {
int t = st.top(); st.pop();
bl[t] = tot;
siz[tot]++;
if (t == u) break ;
}
}
}
void dfs(int u, int rt) {
f[u][siz[u]] = two[num[u]];
for (int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].to;
if (v == rt) continue ;
dfs(v, u);
for (int i = 0; i <= siz[u]; i++) g[i] = f[u][i], f[u][i] = 0;
for (int i = 0; i <= siz[u]; i++) {
for (int j = 0; j <= siz[v]; j++) {
(f[u][i + j] += (ll)g[i] * f[v][j] % mod * two[num[u] * num[v] - 1]) %= mod;
(f[u][i] += mod - (ll)g[i] * f[v][j] % mod) %= mod;
}
}
siz[u] += siz[v];
}
}
void solve() {
cin >> n >> m;
two[0] = 1;
for (int i = 1; i < M; i++) two[i] = two[i - 1] * 2 % mod;
for (int i = 1; i <= m; i++) {
cin >> _u[i] >> _v[i];
conn(_u[i], _v[i]);
conn(_v[i], _u[i]);
}
tarjan(1, 0);
cnt = 0;
memset(head, 0, sizeof head);
for (int i = 1; i <= m; i++) {
if (bl[_u[i]] == bl[_v[i]]) num[bl[_u[i]]]++;
else {
conn(bl[_u[i]], bl[_v[i]]);
conn(bl[_v[i]], bl[_u[i]]);
}
}
for (int i = 1; i <= tot; i++) {
num[i] = siz[i] * (siz[i] - 1) / 2 - num[i];
}
dfs(1, 0);
int ans = 0;
for (int i = 0; i <= n; i++) {
ans += f[1][i];
if (ans >= mod) ans -= mod;
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
4 4 1 2 2 3 3 4 4 1
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3568kb
input:
2 1 1 2
output:
998244352
result:
wrong answer 1st numbers differ - expected: '0', found: '998244352'