# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539094 |
2022-03-18T11:53:46 Z |
alextodoran |
Pipes (CEOI15_pipes) |
C++17 |
|
1101 ms |
13584 KB |
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = (int) 1e5;
int N, M;
struct DSU {
int root[N_MAX + 2];
void init () {
iota(root + 1, root + N + 1, 1);
}
int findRoot (int u) {
return (root[u] == u ? u : root[u] = findRoot(root[u]));
}
bool join (int u, int v) {
u = findRoot(u);
v = findRoot(v);
root[u] = v;
return u != v;
}
};
DSU A, B;
vector <int> adj[N_MAX + 2];
void addEdge (int u, int v) {
adj[u].push_back(v);
adj[v].push_back(u);
}
vector <pair <int, int>> bridges;
int level[N_MAX + 2];
int dfs (int u, int parent = -1) {
int minLevel = level[u];
bool par = false;
for (int v : adj[u]) {
if (level[v] == -1) {
level[v] = level[u] + 1;
minLevel = min(minLevel, dfs(v, u));
} else if (v == parent && par == false) {
par = true;
} else {
minLevel = min(minLevel, level[v]);
}
}
if (parent != -1 && minLevel == level[u]) {
bridges.push_back(make_pair(parent, u));
}
return minLevel;
}
void dfs () {
fill(level + 1, level + N + 1, -1);
for (int u = 1; u <= N; u++) {
if (level[u] == -1) {
dfs(u);
}
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
A.init(); B.init();
int cnt = 0;
while (M--) {
int u, v;
cin >> u >> v;
if (A.join(u, v) == true) {
addEdge(u, v); cnt++;
} else if (B.join(u, v) == true) {
addEdge(u, v); cnt++;
}
}
assert(cnt <= (N - 1) * 2);
dfs();
for (pair <int, int> e : bridges) {
cout << e.first << " " << e.second << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
3156 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
2980 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
3640 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
271 ms |
5212 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
381 ms |
10256 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
544 ms |
11404 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
766 ms |
13460 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
919 ms |
13584 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1101 ms |
13000 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |