QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#654193#8333. GiftEliaukWA 1ms3640kbC++203.9kb2024-10-18 21:13:422024-10-18 21:13:43

Judging History

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

  • [2024-10-18 21:13:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-10-18 21:13:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const ll INF = 1ll << 60;
typedef pair<int, int> PI;
const int N = 1e5 + 10;
int t;
int n;
vector<int> a[N];
map<int, int> mp;
bool judge[N];
int cnt[6];
vector<int> h;
bool dfs(int g, int fa)
{
    for (int i = 0; i < a[g].size(); i++)
    {
        if (a[g][i] == fa)
            continue;

        if (judge[a[g][i]])
        {
            h.push_back(g);
            return true;
        }
        else
        {
            judge[a[g][i]] = 1;
            bool vis = dfs(a[g][i], g);
            if (vis)
            {
                h.push_back(g);
                return true;
            }
        }
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
        mp[x]++;
        mp[y]++;
    }
    judge[1] = 1;
    dfs(1, -1);

    for (auto it : mp)
    {
        cnt[it.second]++;
    }
    if (cnt[5] == 2)
    {
        cout << n - cnt[5] - cnt[4]<< endl;
    }
    else if (cnt[5] == 1)
    {
        ll ans = 2 * (n - cnt[5] - cnt[4]);
        int index = 0;
        for (int i = 0; i < h.size(); i++)
        {
            if (mp[h[i]] == 5)
            {
                index = i;
                if (index == 0)
                {
                    if (mp[h[1]] == 4)
                    {
                        ans++;
                    }
                    if (mp[h[h.size() - 1]] == 4)
                    {
                        ans++;
                    }
                }
                else if (index == h.size() - 1)
                {
                    if (mp[h[0]] == 4)
                    {
                        ans++;
                    }
                    if (mp[h[h.size() - 2]] == 4)
                    {
                        ans++;
                    }
                }
                else
                {
                    if (mp[h[index - 1]] == 4)
                    {
                        ans++;
                    }
                    if (mp[h[index + 1]] == 4)
                    {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    else
    {
        ll ans = 0;
        for (int i = 1; i < h.size(); i++)
        {
            // if (i == h.size())
            // {
            //     if (mp[h[0]] < 4)
            //     {
            //         ans += (n - cnt[4]);
            //         if (mp[h[h.size() - 1]] == 4)
            //         {
            //             ans++;
            //         }
            //     }
            //     else
            //     {
            //         ans += (n - cnt[4] + 1);
            //         if (mp[h[h.size() - 1]] == 4)
            //         {
            //             ans++;
            //         }
            //     }
            //     break;
            // }
            if (mp[h[i]] < 4)
            {
                ans += (n - cnt[4]);
                if (mp[h[i - 1]] == 4)
                {
                    ans++;
                }
            }
            else
            {
                ans += (n - cnt[4]);
                ans++;
                if (mp[h[i - 1]] == 4)
                {
                    ans++;
                }
            }
            if (i == h.size() - 1)
            {
                ans += (n - cnt[4]);
                if (mp[h[h.size() - 1]] >= 4)
                {
                        ans++;
                }
                if (mp[h[0]] >= 4)
                {
                    ans++;
                }
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3532kb

input:

3
1 3
3 2
2 1

output:

10

result:

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