# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527262 |
2022-02-17T04:34:12 Z |
hmm789 |
Pipes (CEOI15_pipes) |
C++14 |
|
826 ms |
65540 KB |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100000];
int p[100000], sz[100000];
bool v[100000], v1[100000];
vector<int> tmp, tmp2;
int root(int x) {
if(p[x] == x) return x;
else return p[x] = root(p[x]);
}
void merge(int a, int b) {
int x = root(a), y = root(b);
if(x == y) return;
if(sz[x] < sz[y]) swap(x, y);
p[y] = x;
sz[x] += sz[y];
}
bool dfs(int x, int par) {
v1[x] = 1;
tmp2.push_back(x);
if(v[x]) {
while(tmp[tmp.size()-1] != x) {
merge(tmp[tmp.size()-1], x);
tmp.erase(--tmp.end());
}
return false;
}
v[x] = 1;
tmp.push_back(x);
for(int i : adj[x]) {
if(i == par) continue;
if(root(i) == root(x)) continue;
bool tp2 = dfs(i, x);
if(!tp2 && tmp[tmp.size()-1] != x) return false;
}
v[x] = 0;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, e, a, b;
cin >> n >> e;
pair<int, int> edg[e];
for(int i = 0; i < e; i++) {
cin >> a >> b;
a--; b--;
adj[a].push_back(b);
adj[b].push_back(a);
edg[i] = make_pair(a, b);
}
for(int i = 0; i < n; i++) p[i] = i, sz[i] = 1;
for(int i = 0; i < n; i++) {
if(!v1[i]) {
for(int i : tmp2) v[i] = 0;
tmp2.clear();
dfs(i, -1);
}
tmp.clear();
}
for(int i = 0; i < e; i++) {
if(root(edg[i].first) != root(edg[i].second)) cout << edg[i].first+1 << " " << edg[i].second+1 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2636 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
5972 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
118 ms |
30620 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
210 ms |
43104 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
345 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
546 ms |
65536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
801 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
826 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
576 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
432 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |