# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
230367 |
2020-05-09T17:23:01 Z |
parsa_mobed |
Pipes (CEOI15_pipes) |
C++14 |
|
4743 ms |
14128 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1, M = 6e6, LOG = 17;
int h[N], val[N], par[N][LOG];
bitset <M> E;
vector <int> g[N];
int getpar(int v, int height) {
for (int i = 0; height; height>>=1, i++) if (height&1) v = par[v][i];
return v;
}
int LCA(int u, int v) {
if (h[u] > h[v]) swap(u, v);
v = getpar(v, h[v] - h[u]);
if (u == v) return v;
for (int i = LOG - 1; i >= 0; i--) if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
return par[v][0];
}
void init(int n) {for (int i = 1; i <= n; i++) par[i][0] = i; return ;}
int getroot(int u) {return par[u][0] = (par[u][0] == u ? u : getroot(par[u][0]));}
void Union(int u, int v, int id) {
int ru = getroot(u), rv = getroot(v);
if (ru == rv) {E[id] = 0; return ;}
par[ru][0] = rv, g[u].push_back(v), g[v].push_back(u);
}
void dfs(int v) {
for (int i = 1; i < LOG; i++) par[v][i] = par[par[v][i - 1]][i - 1];
for (int u : g[v]) if (!h[u]) h[u] = h[v] + 1, par[u][0] = v, dfs(u);
}
void Solve(int v) {
h[v] = 1;
for (int u : g[v]) if (!h[u]) Solve(u), val[v] += val[u];
if (par[v][0] && val[v] == 0) cout << v << " " << par[v][0] << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m; cin >> n >> m, init(n), E.set();
for (int i = 0; i < m; i++) {int u, v; cin >> u >> v, Union(u, v, i);}
for (int i = 1; i <= n; i++) if (!h[i]) par[i][0] = 0, h[i] = 1, dfs(i);
cin.seekg(0), cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
if (!E[i]) val[u]++, val[v]++, val[LCA(u, v)] -= 2;
}
memset(h, 0, sizeof h);
for (int i = 1; i <= n; i++) if (!h[i]) Solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3840 KB |
Output is correct |
2 |
Correct |
6 ms |
3840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4224 KB |
Output is correct |
2 |
Correct |
13 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
4196 KB |
Output is correct |
2 |
Correct |
247 ms |
4088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
482 ms |
4820 KB |
Output is correct |
2 |
Correct |
534 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
855 ms |
6332 KB |
Output is correct |
2 |
Correct |
696 ms |
6904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1310 ms |
10996 KB |
Output is correct |
2 |
Correct |
1133 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2183 ms |
12152 KB |
Output is correct |
2 |
Correct |
1825 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3260 ms |
13908 KB |
Output is correct |
2 |
Correct |
3157 ms |
14072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3999 ms |
13944 KB |
Output is correct |
2 |
Correct |
3856 ms |
14096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4743 ms |
13416 KB |
Output is correct |
2 |
Correct |
4006 ms |
14128 KB |
Output is correct |