# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539097 |
2022-03-18T11:55:16 Z |
alextodoran |
Pipes (CEOI15_pipes) |
C++17 |
|
1250 ms |
62524 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) {
level[u] = 0;
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 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3156 KB |
Output is correct |
2 |
Correct |
5 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
2964 KB |
Output is correct |
2 |
Correct |
83 ms |
2840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
3660 KB |
Output is correct |
2 |
Correct |
173 ms |
3112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
5212 KB |
Output is correct |
2 |
Correct |
224 ms |
4836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
10316 KB |
Output is correct |
2 |
Correct |
379 ms |
6808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
791 ms |
11528 KB |
Output is correct |
2 |
Correct |
557 ms |
8704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
809 ms |
13552 KB |
Output is correct |
2 |
Correct |
801 ms |
8672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
997 ms |
13460 KB |
Output is correct |
2 |
Runtime error |
1113 ms |
53708 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1250 ms |
12948 KB |
Output is correct |
2 |
Runtime error |
1078 ms |
62524 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |