QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588162 | #5437. Graph Completing | ucup-team2526 | WA | 1ms | 8728kb | C++14 | 4.7kb | 2024-09-25 04:45:49 | 2024-09-25 04:45:49 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout<<endl<<endl;
}
template<class T, class... Ts>
void err(T arg, Ts ... args) {
cout<<fixed<<setprecision(10)<<arg<< ' ';
err(args...);
}
std::set<std::pair<int, int>> E;
struct EBCC {
int n;
std::vector<std::vector<int>> adj;
std::vector<int> stk;
std::vector<int> dfn, low, bel;
int cur, cnt;
EBCC() {}
EBCC(int n) {
init(n);
}
void init(int n) {
this->n = n;
adj.assign(n, {});
dfn.assign(n, -1);
low.resize(n);
bel.assign(n, -1);
stk.clear();
cur = cnt = 0;
}
void addEdge(int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
void dfs(int x, int p) {
dfn[x] = low[x] = cur++;
stk.push_back(x);
for (auto y : adj[x]) {
if (y == p) {
continue;
}
if (dfn[y] == -1) {
E.emplace(x, y);
dfs(y, x);
low[x] = std::min(low[x], low[y]);
} else if (bel[y] == -1 && dfn[y] < dfn[x]) {
E.emplace(x, y);
low[x] = std::min(low[x], dfn[y]);
}
}
if (dfn[x] == low[x]) {
int y;
do {
y = stk.back();
bel[y] = cnt;
stk.pop_back();
} while (y != x);
cnt++;
}
}
std::vector<int> work() {
dfs(0,-1);
return bel;
}
struct Graph {
int n;
std::vector<std::pair<int, int>> edges;
std::vector<int> siz;
std::vector<int> cnte;
};
Graph compress() {
Graph g;
g.n = cnt;
g.siz.resize(cnt);
g.cnte.resize(cnt);
for (int i = 0; i < n; i++) {
g.siz[bel[i]]++;
for (auto j : adj[i]) {
if (bel[i] < bel[j]) {
g.edges.emplace_back(bel[i], bel[j]);
} else if (i < j) {
g.cnte[bel[i]]++;
}
}
}
return g;
}
} ebcc;
const int mod = 9982443353;
const int maxn = 10005;
vector<int>t[maxn];
int n,m;
int Siz[maxn],F[maxn][maxn],G[maxn],Cnte[maxn];
int qmi(int a,int b) {
if (b <= 0) return 1;
int res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res % mod;
}
int Add(int a,int b) {
return (a + b) % mod;
}
int Mul(int a,int b) {
return a * b % mod;
}
int Pow2[maxn], PPow2[maxn];
int pow2(long long b) {
return 1ll * Pow2[b % n] * PPow2[b / n] % mod;
}
void dfs(int u,int f) {
F[u][Siz[u]] = qmi(2,1ll * (Siz[u] - 1) * Siz[u] / 2 - Cnte[u]);
if (m == 10000) dbg(u,F[u][Siz[u]]);
for (auto i : t[u]) {
if (i == f) continue;
dfs(i,u);
for (int j = 0;j <= Siz[u] + Siz[i];j++) G[j] = 0;
for (int j = Siz[u];j >= 0;j--) {
if (!F[u][j]) continue;
for (int k = Siz[i];k >= 0;k--) {
if (!F[i][k]) continue;
G[k + j] = (G[k + j] + 1ll * F[u][j] * F[i][k] % mod * pow2(1ll * j * k - 1)) % mod;
G[j] = (G[j] - Mul(F[u][j],F[i][k]) + mod) % mod;
}
}
for (int j = 0;j <= Siz[u] + Siz[i];j++) F[u][j] = G[j];
Siz[u] += Siz[i];
}
}
void solve(){
cin >> n >> m;
Pow2[0] = PPow2[0] = 1;
for (int i = 1; i <= n; i++) {
Pow2[i] = 2ll * Pow2[i - 1] % mod;
}
for (int i = 1; i <= n; i++) {
PPow2[i] = 1ll * PPow2[i - 1] * Pow2[n] % mod;
}
ebcc.init(n);
for (int i = 1;i <= m;i++) {
int u,v;cin >> u >> v;
u--,v--;
ebcc.addEdge(u,v);
}
vector<int> bel = ebcc.work();
EBCC::Graph g = ebcc.compress();
n = g.n;
for (int i = 1;i <= n;i++) {
Siz[i] = g.siz[i - 1];
Cnte[i] = g.cnte[i - 1];
//dbg(i,Siz[i],Cnte[i]);
}
for (auto [u,v] : g.edges) {
//dbg(u,v);
//if (bel[u] == bel[v]) Cnte[bel[u]]++;
t[u + 1].push_back(v + 1);
t[v + 1].push_back(u + 1);
}
//dbg(n);
dfs(1,0);
int ans = 0;
for (int i = 0;i <= Siz[1];i++) {
ans = Add(ans,F[1][i]);
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3916kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3868kb
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: 0ms
memory: 3876kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 3 1 2 2 3 3 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
4 3 1 2 2 3 3 4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 4128kb
input:
4 3 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3836kb
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: 0ms
memory: 3800kb
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: 0
Accepted
time: 0ms
memory: 8728kb
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:
1
result:
ok 1 number(s): "1"
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 4828kb
input:
142 10000 19 3 4 86 36 122 36 88 130 86 107 59 3 119 132 90 80 124 122 95 75 66 70 123 63 119 8 44 114 9 81 19 106 77 96 93 79 141 104 50 117 66 30 48 128 109 56 73 106 116 70 8 72 130 59 110 140 20 40 11 134 71 27 51 33 93 82 96 133 118 50 14 32 64 71 12 48 33 22 32 116 17 104 45 66 71 111 142 131 ...
output:
u,F[u][Siz[u]] -> 1 2048 2048
result:
wrong output format Expected integer, but "u,F[u][Siz[u]]" found