36192023-03-01 11:17:31kdbForgalmas utakcpp17Time limit exceeded 45/1001.085s6800 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() {
    t.assign(graph.size(), -1);
    l.assign(graph.size(), INT_MAX / 2);
    done.assign(graph.size(), 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);
    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
1Accepted3ms1696 KiB
2Accepted3ms1928 KiB
subtask221/21
3Accepted4ms2288 KiB
4Accepted4ms2248 KiB
5Accepted4ms2376 KiB
6Accepted4ms2628 KiB
7Accepted4ms2768 KiB
8Accepted4ms3004 KiB
9Accepted4ms3244 KiB
subtask324/24
10Accepted3ms3272 KiB
11Accepted14ms3564 KiB
12Accepted39ms3932 KiB
13Accepted78ms3928 KiB
14Accepted116ms4132 KiB
15Accepted115ms4232 KiB
16Accepted115ms4256 KiB
17Accepted118ms4252 KiB
18Accepted115ms4292 KiB
subtask40/20
19Accepted108ms4220 KiB
20Accepted391ms4436 KiB
21Time limit exceeded1.069s3824 KiB
22Time limit exceeded1.057s4280 KiB
23Time limit exceeded1.06s4564 KiB
24Time limit exceeded1.062s4716 KiB
25Time limit exceeded1.072s5092 KiB
26Time limit exceeded1.044s5124 KiB
27Time limit exceeded1.085s5412 KiB
subtask50/35
28Accepted14ms5888 KiB
29Accepted405ms6304 KiB
30Time limit exceeded1.06s5548 KiB
31Time limit exceeded1.08s5760 KiB
32Time limit exceeded1.08s6036 KiB
33Time limit exceeded1.07s6208 KiB
34Time limit exceeded1.085s6484 KiB
35Time limit exceeded1.057s6560 KiB
36Time limit exceeded1.074s6800 KiB