3619 | 2023-03-01 11:17:31 | kdb | Forgalmas utak | cpp17 | Time limit exceeded 45/100 | 1.085s | 6800 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);
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1696 KiB | ||||
2 | Accepted | 3ms | 1928 KiB | ||||
subtask2 | 21/21 | ||||||
3 | Accepted | 4ms | 2288 KiB | ||||
4 | Accepted | 4ms | 2248 KiB | ||||
5 | Accepted | 4ms | 2376 KiB | ||||
6 | Accepted | 4ms | 2628 KiB | ||||
7 | Accepted | 4ms | 2768 KiB | ||||
8 | Accepted | 4ms | 3004 KiB | ||||
9 | Accepted | 4ms | 3244 KiB | ||||
subtask3 | 24/24 | ||||||
10 | Accepted | 3ms | 3272 KiB | ||||
11 | Accepted | 14ms | 3564 KiB | ||||
12 | Accepted | 39ms | 3932 KiB | ||||
13 | Accepted | 78ms | 3928 KiB | ||||
14 | Accepted | 116ms | 4132 KiB | ||||
15 | Accepted | 115ms | 4232 KiB | ||||
16 | Accepted | 115ms | 4256 KiB | ||||
17 | Accepted | 118ms | 4252 KiB | ||||
18 | Accepted | 115ms | 4292 KiB | ||||
subtask4 | 0/20 | ||||||
19 | Accepted | 108ms | 4220 KiB | ||||
20 | Accepted | 391ms | 4436 KiB | ||||
21 | Time limit exceeded | 1.069s | 3824 KiB | ||||
22 | Time limit exceeded | 1.057s | 4280 KiB | ||||
23 | Time limit exceeded | 1.06s | 4564 KiB | ||||
24 | Time limit exceeded | 1.062s | 4716 KiB | ||||
25 | Time limit exceeded | 1.072s | 5092 KiB | ||||
26 | Time limit exceeded | 1.044s | 5124 KiB | ||||
27 | Time limit exceeded | 1.085s | 5412 KiB | ||||
subtask5 | 0/35 | ||||||
28 | Accepted | 14ms | 5888 KiB | ||||
29 | Accepted | 405ms | 6304 KiB | ||||
30 | Time limit exceeded | 1.06s | 5548 KiB | ||||
31 | Time limit exceeded | 1.08s | 5760 KiB | ||||
32 | Time limit exceeded | 1.08s | 6036 KiB | ||||
33 | Time limit exceeded | 1.07s | 6208 KiB | ||||
34 | Time limit exceeded | 1.085s | 6484 KiB | ||||
35 | Time limit exceeded | 1.057s | 6560 KiB | ||||
36 | Time limit exceeded | 1.074s | 6800 KiB |