QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680748#8333. GiftAuroraKelseyWA 0ms8488kbC++141.7kb2024-10-26 22:29:432024-10-26 22:29:44

Judging History

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

  • [2024-10-26 22:29:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8488kb
  • [2024-10-26 22:29:43]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
const int N = 2e5;
int du[N];
vector<int> G[N];
#define LL long long

bool vis[N];
int cnt;
int n;
vector<int> huan;
void tuopu()
{
    queue<int> q;
    for (int i = 1; i <= n; i++)
    {
        if (du[i] == 1)
        {
            q.push(i);
            vis[i] = 1;
        }
    }
    while (!q.empty())
    {
        int x = q.front();
        q.pop();
        for (auto y : G[x])
        {
            du[y]--;
            if (du[y] == 1)
            {
                q.push(y);
                vis[y] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
        {
            huan.push_back(i);
        }
    }
}

int main()
{
    scanf("%d", &n);
    int spe = 0;
    for (int i = 1, x, y; i <= n; i++)
    {
        scanf("%d %d", &x, &y);
        du[x]++;
        du[y]++;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
        if (du[x] > 4)
        {
            spe = x;
        }
        if (du[y] > 4)
        {
            spe = y;
        }
    }
    // 无度数大于4的点
    tuopu();
    if (!spe)
    {
        // 找环
        tuopu();
        printf("%lld", (LL)huan.size() * (LL)n);
    }
    else
    {
        cout << spe << endl;
        LL ans_cir = 0;
        for (auto y : G[spe])
        {
            if (!vis[y])
            {
                ans_cir++;
                // cout << y << endl;
            }
        }
        printf("%lld", ans_cir * (LL)(n - 1));
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8488kb

input:

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

output:

1
10

result:

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