QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78090#5437. Graph Completingmagicduck#WA 0ms3828kbC++142.6kb2023-02-16 18:15:502023-02-16 18:15:51

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-16 18:15:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2023-02-16 18:15:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &F) {
    int R = 1; F = 0; char CH = getchar();
    for(; !isdigit(CH); CH = getchar()) if(CH == '-') R = -1;
    for(; isdigit(CH); CH = getchar()) F = F * 10 + CH - 48;
    F *= R;
}
inline void file(string str) {
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}
const LL mod = 998244353, iv = (mod + 1) / 2; 
const int N = 1e4 + 10;
int n, m, dfn[N], low[N], d, co[N], c; vector<int> edge[N]; stack<int> s;
int ui[N], vi[N], siz[N], cnt[N]; LL ans = 1;
LL Qpow(LL x, LL k) {
    if(k <= 1) return k ? x : 1;
    LL h = Qpow(x, k / 2); h = h * h % mod;
    return k & 1 ? h * x % mod : h;
}
void tarjan(int x, int y) {
    dfn[x] = low[x] = ++d; s.push(x);
    for(int i : edge[x]) {
        if(i == y) continue;
        if(!dfn[i]) tarjan(i, x), low[x] = min(low[x], low[i]);
        else low[x] = min(low[x], dfn[i]);
    }
    if(low[x] == dfn[x]) {
        c++; cnt[c] = 1;
        while(s.top() != x) {
            co[s.top()] = c;
            s.pop(); cnt[c]++;
        }
        co[x] = c; s.pop();
        ans = ans * Qpow(2, 1LL * cnt[c] * (cnt[c] - 1) / 2) % mod;
    }
}
vector<int> e[N]; LL f[N / 2][N / 2], g[N];
void dfs(int x, int fa) {
    f[x][cnt[x]] = 1; siz[x] = cnt[x];
    for(int i : e[x])
        if(i != fa) {
            dfs(x, i);
            for(int j = 1; j <= siz[x]; j++)
                g[j] = f[i][j], f[i][j] = 0;
            for(int a = 1; a <= siz[x]; a++)
                for(int b = 1; b <= siz[i]; b++) {
                    ((f[x][a + b] += g[a] * f[i][b] % mod * Qpow(2, 1LL * a * b - 1))) %= mod;
                    (f[x][a] += mod - g[a] * f[i][b] % mod) %= mod;
                }
            siz[x] += siz[i];
        }
}
int main() {
    //file("");
    read(n), read(m);
    for(int i = 1; i <= m; i++) {
        read(ui[i]), read(vi[i]);
        edge[ui[i]].emplace_back(vi[i]);
        edge[vi[i]].emplace_back(ui[i]);
    }
    tarjan(1, 0);
    for(int i = 1; i <= m; i++)
        if(co[ui[i]] == co[vi[i]]) ans = ans * iv % mod;
        else e[co[ui[i]]].emplace_back(co[vi[i]]), e[co[vi[i]]].emplace_back(co[ui[i]]), cout << co[ui[i]] << ' ' << co[vi[i]] << '\n';
    LL res = 0; dfs(1, 0);
    for(int i = 1; i <= n; i++)
        res = (res + f[1][i]) % mod;
    cout << ans * res % mod << '\n';
    #ifdef _MagicDuck
        fprintf(stderr, "# Time: %.3lf s", (double)clock() / CLOCKS_PER_SEC);
    #endif
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3828kb

input:

3 2
1 2
2 3

output:

3 2
2 1
1

result:

wrong answer 1st numbers differ - expected: '1', found: '3'