QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415830#521. 防御网络Max_s_xaM70 0ms3696kbC++174.5kb2024-05-21 10:51:502024-05-21 10:51:50

Judging History

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

  • [2024-05-21 10:51:50]
  • 评测
  • 测评结果:70
  • 用时:0ms
  • 内存:3696kb
  • [2024-05-21 10:51:50]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 210, mod = 1e9 + 7;

ll pw[MAXN];
inline ll Qpow(ll a, int b) {ll res = 1; while (b) (b & 1) && (res = res * a % mod), a = a * a % mod, b >>= 1; return res;}

int n, m;
vector <int> e[MAXN];

int dfn[MAXN], low[MAXN], clk, bel[MAXN], bcc;
int st[MAXN], top;
vector <int> g[MAXN << 1];
void Tarjan(int u)
{
    dfn[u] = low[u] = ++clk, st[++top] = u;
    for (auto v : e[u])
        if (!dfn[v])
        {
            Tarjan(v), low[u] = min(low[u], low[v]);
            if (low[v] >= dfn[u])
            {
                bcc++;
                while (st[top] != v) g[bcc].push_back(st[top]), g[st[top]].push_back(bcc), bel[st[top]] = bcc, top--;
                g[bcc].push_back(v), g[v].push_back(bcc), bel[v] = bcc, top--;
                g[bcc].push_back(u), g[u].push_back(bcc);
            }
        }
        else low[u] = min(low[u], dfn[v]);
}

ll res1;
int sz[MAXN];
void DFS1(int u, int fa)
{
    int val = (u <= n ? 0 : (g[u].size() == 2 ? 1 : g[u].size()));
    sz[u] = (u <= n);
    ll sum = 0;
    for (auto v : g[u])
    {
        if (v == fa) continue;
        DFS1(v, u), sz[u] += sz[v];
        sum = (sum + pw[sz[v]] - 1) % mod;
    }
    sum = (sum + pw[n - sz[u]] - 1) % mod;
    if (val) res1 = (res1 + (pw[n] - 1 - sum) * val) % mod;
}

ll f[MAXN], fc[MAXN], fs[MAXN];

int main()
{
    // freopen("B.in", "r", stdin);
    // freopen("B.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    pw[0] = 1;
    for (int i = 1; i < MAXN; i++) pw[i] = pw[i - 1] * 2 % mod;
    Read(n), Read(m);
    for (int i = 1, u, v; i <= m; i++) Read(u), Read(v), e[u].push_back(v), e[v].push_back(u);
    bcc = n, Tarjan(1);
    DFS1(1, 0);
    ll res2 = 0;
    for (int s = n + 1; s <= bcc; s++)
    {
        if (g[s].size() == 2) continue;
        int len = g[s].size();
        for (int i = 1; i < len; i++) fs[i] = pw[sz[g[s][i - 1]]] - 1;
        fs[len] = pw[n - sz[s]] - 1;
        for (int i = 1; i < len; i++)
        {
            f[i] = 0;
            for (int bg = 1; bg <= i; bg++)
            {
                for (int j = 0; j <= len; j++) fc[j] = 0;
                fc[bg] = fs[bg];
                for (int j = bg + 1; j <= len; j++)
                    fc[j] = ((fc[j - 1] - fc[max(bg - 1, j - i - 1)]) * fs[j] % mod + fc[j - 1]) % mod;
                f[i] = (f[i] + fc[len] - fc[bg - i + len - 1]) % mod;
            }
            res2 = (res2 + (f[i] - f[i - 1]) * i) % mod;
        }
    }
    cout << ((res1 - res2) % mod + mod) % mod * Qpow(pw[n], mod - 2) % mod << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 0ms
memory: 3588kb

input:

8 7
1 2
2 3
4 5
5 6
3 4
1 7
6 8

output:

136718756

result:

ok single line: '136718756'

Test #2:

score: 10
Accepted
time: 0ms
memory: 3616kb

input:

8 9
1 2
2 3
3 1
4 5
5 6
6 4
5 8
5 1
5 7

output:

597656258

result:

ok single line: '597656258'

Test #3:

score: 10
Accepted
time: 0ms
memory: 3696kb

input:

20 24
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 11
11 12
12 10
13 14
14 15
15 13
16 20
1 7
20 18
14 2
17 12
7 17
20 5
19 16
16 3

output:

248231903

result:

ok single line: '248231903'

Test #4:

score: 10
Accepted
time: 0ms
memory: 3608kb

input:

20 20
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 1
11 12
12 13
13 14
15 16
16 17
17 18
19 20
2 16
5 12
13 20

output:

61252608

result:

ok single line: '61252608'

Test #5:

score: 10
Accepted
time: 0ms
memory: 3684kb

input:

50 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 1
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
47 48
46 47
48 42
49 50
26 42
10 37
44 45
6 41
50 47
48 43
20 45
37 46

output:

335044588

result:

ok single line: '335044588'

Test #6:

score: 10
Accepted
time: 0ms
memory: 3600kb

input:

99 128
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 11
11 12
12 10
13 14
14 15
15 13
16 17
17 18
18 16
19 20
20 21
21 19
22 23
23 24
24 22
25 26
26 27
27 25
28 29
29 30
30 28
31 32
32 33
33 31
34 35
35 36
36 34
37 38
38 39
39 37
40 41
41 42
42 40
43 44
44 45
45 43
46 47
47 48
48 46
49 50
50 51
51 49
52 53...

output:

880746920

result:

ok single line: '880746920'

Test #7:

score: 10
Accepted
time: 0ms
memory: 3596kb

input:

100 109
1 2
2 3
3 4
4 5
5 1
6 7
7 8
8 9
9 10
10 6
11 12
12 13
13 14
14 15
15 11
16 17
17 18
18 19
19 20
20 16
21 22
22 23
23 24
24 25
25 21
26 27
27 28
28 29
29 30
30 26
31 32
32 33
33 34
34 35
35 31
36 37
37 38
38 39
39 40
40 36
41 42
42 43
43 44
44 45
45 41
46 47
47 48
48 49
49 50
50 46
51 52
52 5...

output:

685727604

result:

ok single line: '685727604'

Test #8:

score: 0
Runtime Error

input:

180 199
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 11
11 12
12 10
13 14
14 15
15 13
16 17
17 18
18 16
19 20
20 21
21 19
22 23
23 24
24 22
25 26
26 27
27 25
28 29
29 30
30 28
31 32
32 33
33 34
34 35
35 31
36 37
37 38
38 39
39 40
40 36
41 42
42 43
43 44
44 45
45 41
46 47
47 48
48 49
49 50
50 46
51 52
52 5...

output:


result:


Test #9:

score: 0
Runtime Error

input:

199 200
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 ...

output:


result:


Test #10:

score: 0
Runtime Error

input:

200 210
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 1
51 52
52 5...

output:


result: