QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707353#8333. GiftwindStrider#WA 0ms3680kbC++201.6kb2024-11-03 15:36:492024-11-03 15:37:19

Judging History

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

  • [2024-11-03 15:37:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3680kb
  • [2024-11-03 15:36:49]
  • 提交

answer

#include <bits/stdc++.h>

using pii = std::pair<int, int>;

int main()
{
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> adj(n + 1);
    std::vector<int> deg(n + 1), tmp;
    int cnt4 = 0, ind = -1;
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        std::cin >> l >> r;
        adj[l].emplace_back(r);
        adj[r].emplace_back(l);
        ++deg[l], ++deg[r];
        if (deg[l] == 5) ind = l;
        if (deg[r] == 5) ind = r;
        if (deg[l] == 4) ++cnt4;
        if (deg[r] == 4) ++cnt4;
    }
    tmp = deg;
    std::vector<bool> vis;
    std::queue<int> q;
    for (int i = 1; i <= n; ++i) if (tmp[i] == 1) q.emplace(i);
    while (q.size())
    {
        int u = q.front();
        q.pop();
        for (int to : adj[u])
        {
            --tmp[to];
            if (tmp[to] == 1) q.emplace(to);
        }
        tmp[u] = 0;
    }
    std::vector<bool> loop(n + 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) if (tmp[i] != 0) loop[i] = 1;
    for (int i = 1; i <= n; ++i)
    {
        for (int u : adj[i])
        {
            if (loop[i] && loop[u])
            {
                if (ind != -1 && i != ind && i != ind) continue;
                // std::cout << cnt4 << "\n";
                if (deg[i] == 4) --cnt4;
                if (deg[u] == 4) --cnt4;
                --deg[i];
                --deg[u];
                ans += n - cnt4;
                ++deg[i];
                ++deg[u];
                if (deg[i] == 4) ++cnt4;
                if (deg[u] == 4) ++cnt4;
            }
        }
    }
    std::cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3680kb

input:

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

output:

10

result:

ok 1 number(s): "10"

Test #2:

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

input:

3
1 3
3 2
2 1

output:

18

result:

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