# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
539091 |
2022-03-18T11:48:47 Z |
alextodoran |
Pipes (CEOI15_pipes) |
C++17 |
|
1147 ms |
65536 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;
bool seen[N_MAX + 2];
int level[N_MAX + 2];
int dfs (int u, int parent = -1) {
int minLevel = level[u];
seen[u] = true;
bool par = false;
for (int v : adj[u]) {
if (seen[v] == false) {
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 () {
for (int u = 1; u <= N; u++) {
if (seen[u] == false) {
dfs(u);
}
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
A.init(); B.init();
while (M--) {
int u, v;
cin >> u >> v;
if (A.join(u, v) == true) {
addEdge(u, v);
} else if (B.join(u, v) == true) {
addEdge(u, v);
}
}
dfs();
cout << (int) bridges.size() << "\n";
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 |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
114 ms |
8464 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
165 ms |
13372 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
269 ms |
21464 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
356 ms |
31116 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
613 ms |
44728 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
775 ms |
57624 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1014 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1147 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |