36232023-03-01 11:48:33kdbForgalmas utakcpp17Time limit exceeded 45/1001.082s5520 KiB
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

struct edge {
    int u, v;

    bool operator ==(edge const& rhs) const {
        return (u == rhs.u && v == rhs.v) || (u == rhs.v && v == rhs.u);
    }
};

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

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 (removed == edge{ cur, neigh })
            continue;

        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) {
        removed = e;

        busy();
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2020 KiB
subtask221/21
3Accepted4ms2248 KiB
4Accepted4ms2352 KiB
5Accepted4ms2556 KiB
6Accepted4ms2776 KiB
7Accepted4ms2988 KiB
8Accepted4ms3196 KiB
9Accepted4ms3284 KiB
subtask324/24
10Accepted3ms3576 KiB
11Accepted14ms3836 KiB
12Accepted41ms4048 KiB
13Accepted71ms4060 KiB
14Accepted104ms4228 KiB
15Accepted104ms4328 KiB
16Accepted105ms4624 KiB
17Accepted104ms4612 KiB
18Accepted104ms4736 KiB
subtask40/20
19Accepted97ms5220 KiB
20Accepted388ms5156 KiB
21Time limit exceeded1.06s4200 KiB
22Time limit exceeded1.062s4356 KiB
23Time limit exceeded1.069s4612 KiB
24Time limit exceeded1.065s4728 KiB
25Time limit exceeded1.065s4824 KiB
26Time limit exceeded1.052s4700 KiB
27Time limit exceeded1.082s4776 KiB
subtask50/35
28Accepted14ms5064 KiB
29Accepted404ms5520 KiB
30Time limit exceeded1.06s4440 KiB
31Time limit exceeded1.044s4660 KiB
32Time limit exceeded1.074s4716 KiB
33Time limit exceeded1.06s4832 KiB
34Time limit exceeded1.065s4892 KiB
35Time limit exceeded1.077s4952 KiB
36Time limit exceeded1.052s4840 KiB