QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708623#8333. GiftxggxWA 0ms3660kbC++201.3kb2024-11-04 01:04:142024-11-04 01:04:16

Judging History

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

  • [2024-11-04 01:04:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-11-04 01:04:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 10;

int n;
vector<vector<int>> adj;
bool vis[N];
int fa[N];
vector<int> huan;
bool flag = 0;

void dfs(int x) {
    if (vis[x] || flag) return;
    vis[x] = 1;
    for (auto v : adj[x]) {
        if (!vis[v]){
            fa[v] = x;
            dfs(v);
        }    
        else {
            flag = 1;
            int cur = fa[v];
            while (v != cur) {
                huan.push_back(cur);
                cur = fa[cur];
            }
            huan.push_back(v);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    // #ifndef ONLINE_JUDGE
    // freopen("in.in", "r", stdin);
    // #endif

    cin >> n;
    adj.resize(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(0);

    ll ans = 0;
    bool flag = 0;
    for (auto u : huan) {
        if ((int)adj[u].size() == 5) {
            flag = 1;
            break;
        } 
    }
    if (flag) {
        ans = 2 * (n - 1);
    } else {
        ans = (int)huan.size() * n;
    }
    cout << ans;
    return 0;
}
/*
6
 1 2
 1 3
 1 4
 1 5
 1 6
 2 3
*/

詳細信息

Test #1:

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

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

input:

3
1 3
3 2
2 1

output:

3

result:

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