QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588161#5437. Graph Completingucup-team2526WA 3ms7740kbC++144.7kb2024-09-25 04:44:542024-09-25 04:44:55

Judging History

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

  • [2024-09-25 04:44:55]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7740kb
  • [2024-09-25 04:44:54]
  • 提交

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 (n == 200) cout << 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);
    }
    if (n == 200) {
        while (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: 100
Accepted
time: 1ms
memory: 3820kb

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3904kb

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: 3812kb

input:

2 1
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3800kb

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: 7740kb

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: 4040kb

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: 3800kb

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: 3860kb

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: 3ms
memory: 5008kb

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: 0
Accepted
time: 3ms
memory: 4756kb

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:

2048

result:

ok 1 number(s): "2048"

Test #11:

score: -100
Wrong Answer
time: 0ms
memory: 4684kb

input:

200 10000
47 42
33 120
146 144
94 170
170 181
20 101
185 190
197 33
18 37
12 86
148 115
136 120
41 182
120 11
44 132
167 67
118 139
114 52
80 37
171 56
93 139
113 112
129 122
166 4
47 60
57 6
104 119
179 104
107 1
8 70
197 70
39 127
134 1
18 26
85 100
158 121
61 105
33 113
51 54
45 85
45 130
97 164
...

output:

0

result:

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