QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682938#8333. Giftgoblin_team#WA 1ms5672kbC++142.0kb2024-10-27 18:01:152024-10-27 18:01:16

Judging History

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

  • [2024-10-27 18:01:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5672kb
  • [2024-10-27 18:01:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int ver[2 * N], nxt[2 * N], head[2 * N];
int deg[N], dg[N];
int tot = 0;
int n;
void add(int x, int y) {
    ver[++tot] = y;
    nxt[tot] = head[x];
    head[x] = tot;
    ++deg[x]; ++dg[x];
}
queue<int> q;
struct Info{
    int x, y;
} edge[N];
int vis[N], cnt = 0;
void dfs(int x, int loophead) {
    for (int i = head[x]; i; i = nxt[i]) {
        int y = ver[i];
        if (vis[y]) continue;
        vis[y] = 1;
        edge[++cnt] = {x, y};
        if (y == loophead) return;
        dfs(y, loophead);
        return;
    }
}
void findloop() {
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            q.push(i);
            vis[i] = 1;
            deg[i] = 0;
        }
    }
    while (q.size()) {
        int tp = q.front(); q.pop();
        for (int i = head[tp]; i; i = nxt[i]) {
            int y = ver[i];
            if (vis[y]) continue;
            deg[y]--;
            if (deg[y] == 1) q.push(y), vis[y] = 1, deg[y] = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        dfs(i, i);
        break;
    }
}
int deg5 = 0, deg4 = 0, deg3 = 0;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        add(x, y);
        add(y, x);
    }
    findloop();
    for (int i = 1; i <= n; i++) {
        if (dg[i] >= 5) deg5++;
        else if (dg[i] == 4) deg4++;
        else deg3++;
    }
    long long ans = 0;
    for (int i = 1; i <= cnt; i++) {
        int x = edge[i].x, y = edge[i].y;
        int newdg5 = deg5, newdg4 = deg4, newdg3 = deg3;
        if (dg[x] == 5) {newdg5--; newdg4++; }
        else if (dg[x] == 4) {newdg4--; newdg3++; }

        if (dg[y] == 5) {newdg5--; newdg4++; }
        else if (dg[y] == 4) {newdg4--; newdg3++; }

        if (newdg5) continue;
        ans += newdg3;
    }
    cout << ans << endl;
    return 0;
}

详细

Test #1:

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

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: 5616kb

input:

3
1 3
3 2
2 1

output:

6

result:

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