QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134380 | #5437. Graph Completing | SnowNorth | WA | 2ms | 7672kb | C++14 | 2.0kb | 2023-08-03 18:32:22 | 2023-08-03 18:32:24 |
Judging History
answer
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
const int N = 5005;
using ll = long long ;
struct Edge {
int to, nxt;
}edge[N << 1];
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[N * N], 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[siz[u] * (siz[u] - 1) / 2 - 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[i * j - 1] % mod) %= 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 <= n * n; 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]]);
}
}
int ans = 0;
dfs(1, 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7556kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5516kb
input:
4 4 1 2 2 3 3 4 4 1
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5676kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5564kb
input:
3 3 1 2 2 3 3 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5632kb
input:
4 3 1 2 2 3 3 4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
4 3 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
4 5 1 2 2 3 3 4 4 1 1 3
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5628kb
input:
4 6 1 2 2 3 3 4 4 1 1 3 2 4
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 5732kb
input:
141 9870 124 111 31 87 121 106 127 90 54 125 38 17 115 23 129 111 8 116 90 85 10 29 96 110 24 125 51 113 119 33 58 64 8 5 54 97 112 44 70 138 116 85 38 138 138 21 26 18 69 128 68 31 69 42 126 110 49 118 83 124 69 4 9 110 88 104 48 53 46 30 111 120 99 85 13 85 73 85 40 124 39 38 121 40 46 100 29 61 4...
output:
753269315
result:
wrong answer 1st numbers differ - expected: '1', found: '753269315'