QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#611167#7040. Connected Subgraphsucup-team4906#WA 1135ms15700kbC++202.7kb2024-10-04 19:43:102024-10-04 19:43:13

Judging History

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

  • [2024-10-04 19:43:13]
  • 评测
  • 测评结果:WA
  • 用时:1135ms
  • 内存:15700kb
  • [2024-10-04 19:43:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
const int mod = 1e9 + 7;

ll qpow(ll x, ll k)
{
    ll res = 1;
    while (k)
    {
        if (k & 1) res = res * x % mod;
        k >>= 1;
        x = x * x % mod;
    }
    return res;
}

void add(ll &a, ll b)
{
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

void solve(void)
{
    int n, m;
    cin >> n >> m;
    ll cnt3 = 0, cnt4 = 0;
    vi deg(n + 2), vis(n + 2);
    vii pre(n + 2), nxt(n + 2);

    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        pre[u].pb(v), deg[u]++;
        pre[v].pb(u), deg[v]++;
    }

    for (int u = 1; u <= n; u++)
        for (auto v : pre[u])
            if (deg[u] < deg[v] || deg[u] == deg[v] && u < v)
                nxt[u].pb(v);
    
    ll ce = 0;
    ll ans = 0;
    for (int u = 1; u <= n; u++)
    {
        for (int v : nxt[u])
            vis[v] = 1;
        for (int v : nxt[u])
            for (int w : nxt[v])
            {
                add(cnt3, vis[w]);
                if (vis[w])
                {
                    assert(deg[u] >= 2);
                    add(ce, deg[u] - 2);
                    assert(deg[v] >= 2);
                    add(ce, deg[v] - 2);
                    assert(deg[w] >= 2);
                    add(ce, deg[w] - 2);
                }
            }
        for (int v : nxt[u])
            vis[v] = 0;  
    }

    for (int u = 1; u <= n; u++)
    {
        for (int v : pre[u])
            for (int w : nxt[v])
                if (deg[u] < deg[w] || deg[u] == deg[w] && u < w)
                    add(cnt4, vis[w]++);
        for (int v : pre[u])
            for (int w : nxt[v])
                vis[w] = 0;
    }

    ll sum = 0;
    for (int u = 1; u <= n; u++)
    {
        ll s1 = 0, s2 = 0;
        for (auto v : pre[u])
        {
            s1 += deg[v] - 1;
            s2 += 1LL * (deg[v] - 1) * (deg[v] - 1);
        }

        if (deg[u] >= 4)
        {
            ll c = deg[u];
            add(ans, c * (c - 1) % mod * (c - 2) % mod * (c - 3) % mod * qpow(2, mod - 2) % mod
                * qpow(3, mod - 2) % mod * qpow(4, mod - 2) % mod);
        }
        add(sum, (s1 * s1 - s2) / 2 % mod);
    }
    
    add(sum, - 3 * cnt3 % mod);
    add(sum, - 4 * cnt4 % mod);
    add(sum, - 2 * ce % mod);
    add(ans, sum);
    add(ans, cnt4);
    add(ans, ce);

    cout << ans << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
        solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

2
4 4
1 2
2 3
3 4
4 1
4 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

1
15

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1135ms
memory: 15700kb

input:

10
3296 174079
484 736
80 3275
914 1609
611 2069
1111 3027
749 1443
568 1878
1180 2788
1072 2156
171 797
106 1226
1749 2331
758 3080
772 2017
1381 2393
1945 2943
269 1431
1640 1805
1924 2161
1720 2123
1551 2940
286 1226
460 1462
1807 1823
40 638
18 707
589 849
1857 1987
914 2360
2446 3129
24 910
113...

output:

153317701
70501661
316115278
1293594
211022166
12354585
22909021
24606401
419368998
462948480

result:

wrong answer 1st lines differ - expected: '192810800', found: '153317701'