3623 | 2023-03-01 11:48:33 | kdb | Forgalmas utak | cpp17 | Time limit exceeded 45/100 | 1.082s | 5520 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();
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
subtask2 | 21/21 | ||||||
3 | Accepted | 4ms | 2248 KiB | ||||
4 | Accepted | 4ms | 2352 KiB | ||||
5 | Accepted | 4ms | 2556 KiB | ||||
6 | Accepted | 4ms | 2776 KiB | ||||
7 | Accepted | 4ms | 2988 KiB | ||||
8 | Accepted | 4ms | 3196 KiB | ||||
9 | Accepted | 4ms | 3284 KiB | ||||
subtask3 | 24/24 | ||||||
10 | Accepted | 3ms | 3576 KiB | ||||
11 | Accepted | 14ms | 3836 KiB | ||||
12 | Accepted | 41ms | 4048 KiB | ||||
13 | Accepted | 71ms | 4060 KiB | ||||
14 | Accepted | 104ms | 4228 KiB | ||||
15 | Accepted | 104ms | 4328 KiB | ||||
16 | Accepted | 105ms | 4624 KiB | ||||
17 | Accepted | 104ms | 4612 KiB | ||||
18 | Accepted | 104ms | 4736 KiB | ||||
subtask4 | 0/20 | ||||||
19 | Accepted | 97ms | 5220 KiB | ||||
20 | Accepted | 388ms | 5156 KiB | ||||
21 | Time limit exceeded | 1.06s | 4200 KiB | ||||
22 | Time limit exceeded | 1.062s | 4356 KiB | ||||
23 | Time limit exceeded | 1.069s | 4612 KiB | ||||
24 | Time limit exceeded | 1.065s | 4728 KiB | ||||
25 | Time limit exceeded | 1.065s | 4824 KiB | ||||
26 | Time limit exceeded | 1.052s | 4700 KiB | ||||
27 | Time limit exceeded | 1.082s | 4776 KiB | ||||
subtask5 | 0/35 | ||||||
28 | Accepted | 14ms | 5064 KiB | ||||
29 | Accepted | 404ms | 5520 KiB | ||||
30 | Time limit exceeded | 1.06s | 4440 KiB | ||||
31 | Time limit exceeded | 1.044s | 4660 KiB | ||||
32 | Time limit exceeded | 1.074s | 4716 KiB | ||||
33 | Time limit exceeded | 1.06s | 4832 KiB | ||||
34 | Time limit exceeded | 1.065s | 4892 KiB | ||||
35 | Time limit exceeded | 1.077s | 4952 KiB | ||||
36 | Time limit exceeded | 1.052s | 4840 KiB |