QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637764#8332. Two in OneNanamiWA 0ms6068kbC++171.9kb2024-10-13 14:02:182024-10-13 14:02:19

Judging History

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

  • [2024-10-13 14:02:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6068kb
  • [2024-10-13 14:02:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n;
int ans;
int d[N];
bool b[N];
int sum, p;
int a[N], cnt, cntfin;

vector <int> e[N];
map <pair <int, int>, bool> edge;

void dfs(int u, int x) {
    b[u] = 1;
    a[++ cnt] = u;
    // cout << cnt << " " << u << endl;

    for(auto v : e[u]) {
        if(edge[{u, v}] || edge[{v, u}]) continue;

        if(p) return;

        if(b[v]) {
            // sum = x;
            // cout << sum << endl;

            p = 1;
            a[++ cnt] = v;
            // cout << cnt << endl;
            cntfin = cnt;
            // for(int i = 1; i <= cntfin; i ++) cout << a[i] << " ";
            return;
        }

        // cout << v << " " << x + 1 << endl;

        edge[{u, v}] = 1;
        edge[{v, u}] = 1;
        dfs(v, x + 1);
        edge[{u, v}] = 0;
        edge[{v, u}] = 0;

        if(p) return;

        b[v] = 0;
        cnt --;
    }

    return;
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        int u, v;
        cin >> u >> v;
        // b[i] = 0;
        // sum += 2;
        d[u] ++;
        d[v] ++;

        e[u].push_back(v);
        e[v].push_back(u);
    }

    // a[1] = 1;
    dfs(1, 1);
    // cout << sum << endl;
    int sta = a[cntfin];
    int cancut = 0;
    int howmany = 0;
    int du = 0;
    for(int i = cntfin; i >= 1; i --) {
        if(i != cntfin && sta == a[i]) break;

        if(d[a[i]] >= 5) {
            du ++;
            if(du == 1)
                cancut = 2;
            else if(du > 1)
                cancut = 1;
        }
        howmany ++;
    }

    // cout << howmany << endl;
    if(cancut == 0) cancut = howmany;

    int ans = 0;
    for(int i = 1; i <= n; i ++) {
        if(d[i] >= 4) continue;
        else ans += cancut;
    }
    cout << ans << endl;
    // cout << sum << endl;
}

詳細信息

Test #1:

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

input:

1
7
1 2 3 4 3 2 1

output:

0

result:

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