36202023-03-01 11:23:40kdbForgalmas utakcpp17Time limit exceeded 45/1001.085s5284 KiB
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

struct edge {
    int u, v;
};

vector<vector<int>> graph;
vector<int> t;
vector<int> l;
vector<bool> done;
int tm;
int bs;

void dfs(int const cur, int const par) {
    done[cur] = true;

    t[cur] = tm;
    tm++;
    l[cur] = t[cur];

    for (int const& neigh : graph[cur]) {
        if (done[neigh]) {
            if (neigh != par)
                l[cur] = min(l[cur], t[neigh]);
            continue;
        }

        dfs(neigh, cur);

        l[cur] = min(l[cur], l[neigh]);
    }

    if (l[cur] == t[cur] && par != -1)
        bs++;
}

void busy() {
    for (int i = 0; i < graph.size(); i++) {
        t[i] = -1;
        l[i] = INT_MAX / 2;
        done[i] = false;
    }
    tm = 0;
    bs = 0;

    for (int i = 0; i < graph.size(); i++)
        if (!done[i])
            dfs(i, -1);

    /*for (int i = 0; i < graph.size(); i++) {
        cout << t[i] << " " << l[i] << "\n";
    }*/

    cout << bs << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, m;
    cin >> n >> m;

    graph.resize(n);
    t.resize(n);
    l.resize(n);
    done.resize(n);
    vector<edge> edges(m);

    for (auto& e : edges) {
        cin >> e.u >> e.v;
        e.u--; e.v--;

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

    for (auto& e : edges) {
        graph[e.u].erase(find(graph[e.u].begin(), graph[e.u].end(), e.v));
        graph[e.v].erase(find(graph[e.v].begin(), graph[e.v].end(), e.u));

        busy();

        graph[e.u].push_back(e.v);
        graph[e.v].push_back(e.u);
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2100 KiB
2Accepted3ms2160 KiB
subtask221/21
3Accepted4ms2292 KiB
4Accepted4ms2512 KiB
5Accepted4ms2592 KiB
6Accepted4ms2676 KiB
7Accepted4ms2720 KiB
8Accepted4ms2848 KiB
9Accepted4ms3068 KiB
subtask324/24
10Accepted3ms3296 KiB
11Accepted14ms3748 KiB
12Accepted41ms3948 KiB
13Accepted81ms3932 KiB
14Accepted119ms3852 KiB
15Accepted119ms3992 KiB
16Accepted119ms3956 KiB
17Accepted120ms4068 KiB
18Accepted119ms4080 KiB
subtask40/20
19Accepted112ms4280 KiB
20Accepted400ms4604 KiB
21Time limit exceeded1.052s3672 KiB
22Time limit exceeded1.06s3976 KiB
23Time limit exceeded1.083s4128 KiB
24Time limit exceeded1.062s4132 KiB
25Time limit exceeded1.057s4164 KiB
26Time limit exceeded1.085s4448 KiB
27Time limit exceeded1.082s4596 KiB
subtask50/35
28Accepted14ms4856 KiB
29Accepted414ms5284 KiB
30Time limit exceeded1.062s4396 KiB
31Time limit exceeded1.062s4732 KiB
32Time limit exceeded1.077s4732 KiB
33Time limit exceeded1.06s4796 KiB
34Time limit exceeded1.065s4824 KiB
35Time limit exceeded1.07s4684 KiB
36Time limit exceeded1.06s4956 KiB