3620 | 2023-03-01 11:23:40 | kdb | Forgalmas utak | cpp17 | Time limit exceeded 45/100 | 1.085s | 5284 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);
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2100 KiB | ||||
2 | Accepted | 3ms | 2160 KiB | ||||
subtask2 | 21/21 | ||||||
3 | Accepted | 4ms | 2292 KiB | ||||
4 | Accepted | 4ms | 2512 KiB | ||||
5 | Accepted | 4ms | 2592 KiB | ||||
6 | Accepted | 4ms | 2676 KiB | ||||
7 | Accepted | 4ms | 2720 KiB | ||||
8 | Accepted | 4ms | 2848 KiB | ||||
9 | Accepted | 4ms | 3068 KiB | ||||
subtask3 | 24/24 | ||||||
10 | Accepted | 3ms | 3296 KiB | ||||
11 | Accepted | 14ms | 3748 KiB | ||||
12 | Accepted | 41ms | 3948 KiB | ||||
13 | Accepted | 81ms | 3932 KiB | ||||
14 | Accepted | 119ms | 3852 KiB | ||||
15 | Accepted | 119ms | 3992 KiB | ||||
16 | Accepted | 119ms | 3956 KiB | ||||
17 | Accepted | 120ms | 4068 KiB | ||||
18 | Accepted | 119ms | 4080 KiB | ||||
subtask4 | 0/20 | ||||||
19 | Accepted | 112ms | 4280 KiB | ||||
20 | Accepted | 400ms | 4604 KiB | ||||
21 | Time limit exceeded | 1.052s | 3672 KiB | ||||
22 | Time limit exceeded | 1.06s | 3976 KiB | ||||
23 | Time limit exceeded | 1.083s | 4128 KiB | ||||
24 | Time limit exceeded | 1.062s | 4132 KiB | ||||
25 | Time limit exceeded | 1.057s | 4164 KiB | ||||
26 | Time limit exceeded | 1.085s | 4448 KiB | ||||
27 | Time limit exceeded | 1.082s | 4596 KiB | ||||
subtask5 | 0/35 | ||||||
28 | Accepted | 14ms | 4856 KiB | ||||
29 | Accepted | 414ms | 5284 KiB | ||||
30 | Time limit exceeded | 1.062s | 4396 KiB | ||||
31 | Time limit exceeded | 1.062s | 4732 KiB | ||||
32 | Time limit exceeded | 1.077s | 4732 KiB | ||||
33 | Time limit exceeded | 1.06s | 4796 KiB | ||||
34 | Time limit exceeded | 1.065s | 4824 KiB | ||||
35 | Time limit exceeded | 1.07s | 4684 KiB | ||||
36 | Time limit exceeded | 1.06s | 4956 KiB |