# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484787 |
2021-11-05T13:25:09 Z |
Victor |
Pipes (CEOI15_pipes) |
C++17 |
|
220 ms |
15404 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
struct union_find {
int p[100001];
char rank[100001];
union_find(int n) {
rep(i, 0, n) p[i] = i;
memset(rank, 0, n * 4);
}
int find_set(int i) { return p[i] == i ? i : p[i] = find_set(p[i]); }
bool same(int i,int j) {return find_set(i)==find_set(j);}
void union_set(int i, int j) {
i = find_set(i);
j = find_set(j);
if (i == j) return;
if (rank[i] < rank[j]) swap(i, j);
if (rank[i] == rank[j]) ++rank[i];
p[j] = i;
}
};
int dfs_p[100001], dfs_num[100001], dfs_lo[100001], cnt = 0;
vi graph[100001];
void dfs(int u) {
dfs_num[u] = dfs_lo[u] = cnt++;
trav(v, graph[u]) if (v != dfs_p[u]) {
if (dfs_num[v] == -1) {
dfs_p[v] = u;
dfs(v);
if (dfs_num[u] < dfs_lo[v]) cout << u + 1 << ' ' << v + 1 << endl;
dfs_lo[u] = min(dfs_lo[u], dfs_lo[v]);
}
else
dfs_lo[u] = min(dfs_lo[u], dfs_num[v]);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
memset(dfs_num, -1, sizeof(dfs_num));
int n, m, u, v;
cin >> n >> m;
union_find uf1(n), uf2(n);
rep(i, 0, m) {
cin >> u >> v;
--u;
--v;
if(uf1.same(u,v))if(!uf2.same(u,v)){
uf2.union_set(u,v);
graph[u].pb(v);
graph[v].pb(u);
}
else {
uf2.union_set(u,v);
graph[u].pb(v);
graph[v].pb(u);
}
}
rep(i, 0, n) {
if (dfs_num[i] != -1) continue;
cnt = 0;
dfs_p[i] = i;
dfs(i);
}
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:84:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
84 | if(uf1.same(u,v))if(!uf2.same(u,v)){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3916 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3964 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
4028 KB |
Output is correct |
2 |
Incorrect |
71 ms |
4028 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
4028 KB |
Output is correct |
2 |
Incorrect |
145 ms |
15404 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
4156 KB |
Output is correct |
2 |
Runtime error |
5 ms |
7992 KB |
Execution killed with signal 11 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
8012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
7968 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
7932 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
8012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
7992 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |