82952024-01-14 11:45:12SzinAttilaMaximális kaktusz (45 pont)cpp17Wrong answer 9/4554ms13676 KiB
#include <iostream>
#include <vector>
using namespace std;

int n, m, a, b, ans = 0;
vector <vector <int>> g(1e5);
vector <int> p(1e5, 0);
vector <bool> fa(1e5, true);
vector <bool> szabad;

void dfs1(int x) {
    for (int i : g[x]) {
        if (i == p[x]) continue;
        if (p[i]) {
            a = x;
            if (fa[x]) while (a != p[i]) { fa[a] = false; a = p[a]; }
            continue;
        }
        p[i] = x;
        dfs1(i);
    }
}

void dfs2(int x) {
    fa[x] = false;
    int c = 0;
    for (int i : g[x]) {
        if (!fa[i]) continue;
        p[i] = x;
        dfs2(i);
        if (szabad[i]) c++;
    }
    if (!szabad[x]) return;
    if (c >= 2) {
        ans++;
        szabad[x] = false;
    }
    else if (c == 1 && p[x] > 0) {
        ans++;
        szabad[x] = false;
        szabad[p[x]] = false;
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    p[1] = -1;
    dfs1(1);
    fill(p.begin(), p.end(), 0);
    szabad = fa;
    for (int i = 1; i <= n; i++) {
        if (!fa[i]) continue;
        p[i] = -1;
        dfs2(i);
    }
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base9/45
1Accepted0/06ms7412 KiB
2Wrong answer0/04ms7464 KiB
3Accepted1/16ms7420 KiB
4Accepted1/14ms7668 KiB
5Accepted1/14ms7596 KiB
6Accepted2/24ms7740 KiB
7Wrong answer0/24ms7932 KiB
8Accepted2/24ms8120 KiB
9Wrong answer0/14ms8072 KiB
10Accepted1/14ms8344 KiB
11Wrong answer0/14ms8640 KiB
12Wrong answer0/14ms8520 KiB
13Wrong answer0/14ms8448 KiB
14Wrong answer0/14ms8476 KiB
15Wrong answer0/16ms8600 KiB
16Wrong answer0/14ms8732 KiB
17Wrong answer0/14ms8940 KiB
18Wrong answer0/152ms12460 KiB
19Wrong answer0/146ms12664 KiB
20Wrong answer0/154ms12400 KiB
21Wrong answer0/152ms12480 KiB
22Wrong answer0/239ms12708 KiB
23Wrong answer0/239ms12656 KiB
24Wrong answer0/239ms12504 KiB
25Wrong answer0/239ms12724 KiB
26Accepted1/14ms9088 KiB
27Wrong answer0/14ms9372 KiB
28Wrong answer0/16ms9368 KiB
29Wrong answer0/150ms12936 KiB
30Wrong answer0/150ms13084 KiB
31Wrong answer0/146ms13112 KiB
32Wrong answer0/148ms13196 KiB
33Wrong answer0/252ms13172 KiB
34Wrong answer0/250ms13308 KiB
35Wrong answer0/248ms13436 KiB
36Wrong answer0/248ms13676 KiB