QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101861#6379. LaLa and Monster Hunting (Part 2)lonytreeWA 4ms11772kbC++143.7kb2023-05-01 14:45:502023-05-01 14:45:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 14:45:53]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:11772kb
  • [2023-05-01 14:45:50]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 1e5 + 5, mod = 998244353; typedef long long ll;

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

int N, M, su[maxn], sv[maxn];

int deg[maxn];

int to[maxn << 1], sy[maxn << 1], tt = 1;

vector<int> G[maxn], g[maxn];

inline void add(int u, int v) { to[++tt] = v, G[u].push_back(tt); }

int F1[maxn], F2[maxn], F3[maxn];

inline void get(int &x, int y) { if ((x += y) >= mod) x -= mod; }

int H[maxn], P[maxn];

int id[maxn];

int S0[maxn], S1[maxn];

int main()
{
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= M; i++) scanf("%d%d", su + i, sv + i), su[i]++, sv[i]++, deg[su[i]]++, deg[sv[i]]++;
    for (int i = 1; i <= M; i++)
    {
        if (make_pair(deg[su[i]], su[i]) > make_pair(deg[sv[i]], sv[i]))
        {
            add(su[i], sv[i]);
            g[su[i]].push_back(tt);
            add(sv[i], su[i]);
        }
        else
        {
            add(sv[i], su[i]);
            g[sv[i]].push_back(tt);
            add(su[i], sv[i]);
        }
    }
    for (int i = 1; i <= N; i++) F1[i] = deg[i];
    for (int i = 1; i <= N; i++) for (int j : G[i]) get(F2[to[j]], F1[i]);
    for (int i = 1; i <= N; i++) for (int j : G[i]) get(F3[to[j]], F2[i]);
    for (int i = 1; i <= N; i++)
        H[i] = (((ll)F3[i] - 2ll * F2[i] - (ll)deg[i] * (deg[i] - 2) - F2[i] + 2ll * (deg[i]) + deg[i] - 2) % mod + mod) % mod;
    // for (int i = 1; i <= N; i++) cerr << F1[i] << ' '; cerr << endl;
    // for (int i = 1; i <= N; i++) cerr << F2[i] << ' '; cerr << endl;
    // for (int i = 1; i <= N; i++) cerr << F3[i] << ' '; cerr << endl;
    // for (int i = 1; i <= N; i++) cerr << H[i] << ' '; cerr << endl;
    int ans = 0;
    for (int x = 1; x <= N; x++)
    {
        for (int y : g[x]) id[to[y]] = y;
        for (int y : g[x]) for (int z : g[to[y]]) if (id[to[z]])
        {
            ans = ((ll)ans + H[x] + H[to[y]] + H[to[z]]) % mod;
            int h = id[to[z]];
            sy[y >> 1]++, sy[z >> 1]++, sy[h >> 1]++;
            P[x]++, P[to[y]]++, P[to[z]]++;
        }
        // for (int y : g[x]) ans = (ans + (ll)S0[y] * (H[x] + H[to[y]]) + S1[to[y]]) % mod;
        for (int y : g[x]) id[to[y]] = 0;
        // for (int y : g[x]) ans += S0[y];
    }
    // cerr << ans << endl;
    ans = 0;
    for (int i = 1; i <= M; i++)
    {
        // cerr << su[i] << ' ' << sv[i] << ' ' << sy[i] << endl;
        ans = (ans - (ll)sy[i] * (sy[i] - 1) / 2 % mod * (2 * ((deg[su[i]] - 1) + (deg[sv[i]] - 1)) - 10)) % mod;
        // ans = (ans - (ll)sy[i] * (sy[i] - 1) / 2 % mod * ( - 2)) % mod;
    }
    for (int i = 1; i <= N; i++)
    {
        // cerr << P[i] << endl;
        ans = (ans - (ll)P[i] * (P[i] - 1) / 2 % mod * 2) % mod;
    }
    // cerr << ans << endl;
    // ans = 0;
    for (int x = 1; x <= N; x++)
    {
        for (int Y : g[x])
        {
            int y = to[Y];
            for (int Z : G[y])
            {
                int z = to[Z];
                if (make_pair(deg[x], x) > make_pair(deg[z], z))
                {
                    int ad = sy[Y >> 1] + sy[Z >> 1];
                    ans = (ans - (ll)ad * S0[z] * 2 - S1[z] * 2ll) % mod;
                    // ans += S0[z];
                    S0[z]++;
                    S1[z] = (S1[z] + ad) % mod;
                }
            }
        }
        for (int Y : g[x])
        {
            int y = to[Y];
            for (int Z : G[y])
            {
                int z = to[Z];
                S0[z] = S1[z] = 0;
            }
        }
    }
    return 0 * printf("%d\n", (ans + mod) % mod);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 11772kb

input:

6 7
0 1
1 2
0 2
2 3
3 4
4 5
3 5

output:

0

result:

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