QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588172#5437. Graph Completingucup-team2526WA 1ms3860kbC++174.8kb2024-09-25 04:58:042024-09-25 04:58:05

Judging History

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

  • [2024-09-25 04:58:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2024-09-25 04:58:04]
  • 提交

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 pn;
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) {
    int val = 1ll * (Siz[u] - 1) * Siz[u] / 2 - Cnte[u];
    F[u][Siz[u]] = pow2(val);
    //if (pn == 200) dbg(u,F[u][Siz[u]],val);
    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;
    pn = n;
    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]);
        //if (pn == 200) 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;
} 

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3860kb

input:

3 2
1 2
2 3

output:

0

result:

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