QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645604#8333. Giftyihang_01#WA 1ms3688kbC++201.6kb2024-10-16 19:09:402024-10-16 19:09:42

Judging History

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

  • [2024-10-16 19:09:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3688kb
  • [2024-10-16 19:09:40]
  • 提交

answer

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::string;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
const int N = 1e5 + 10;

int n;
std::vector<int> g[N];
int d[N];
bool st[N];
int huan;
std::vector<int> path;
bool ok = false;
int cnt[N];

void dfs(int u, int fa) {
    if (ok) return;
    st[u] = true;
    for (auto v: g[u]) {
        if (v == fa) continue;
        if (st[v]) {
            huan = v;
            path.push_back(v);
            return;
        }
        dfs(v, u);
        if (huan) {
            path.push_back(v);
            if (u == huan) huan = 0;
            ok = true;
            return;
        }
    }
    st[u] = false;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i ++ ) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        d[a] ++, d[b] ++;
    }    

    for (int i = 1; i <= n; i ++ ) {
        cnt[d[i]] ++;
    }

    dfs(1, -1);

    long long ans = 0;
    for (int i = 1; i < path.size(); i ++ ) {
        int a = path[i - 1], b = path[i];
        cnt[d[a]] --, cnt[d[b]] --;
        cnt[d[a] - 1] ++, cnt[d[b] - 1] ++;
        int t = cnt[1] + cnt[2] + cnt[3];
        // cout << "t:" << t << "\n";
        ans += t;
        cnt[d[a]] ++, cnt[d[b]] ++;
        cnt[d[a] - 1] --, cnt[d[b] - 1] --;
    }

    cout << ans << "\n";
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T --)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

3
1 3
3 2
2 1

output:

6

result:

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