# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
230359 |
2020-05-09T17:05:07 Z |
parsa_mobed |
Pipes (CEOI15_pipes) |
C++14 |
|
4264 ms |
25464 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 6e6 + 5, LOG = 17;
int h[N], val[N], root[N], par[N][LOG];
bool mark[N];
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++) root[i] = i; return ;}
int getroot(int u) {return root[u] = (root[u] == u ? u : getroot(root[u]));}
void Union(int u, int v, int id) {
int ru = getroot(u), rv = getroot(v);
if (ru == rv) {E[id] = 0; return ;}
root[ru] = rv, g[u].push_back(v), g[v].push_back(u);
}
void dfs(int v) {
mark[v] = 1;
for (int i = 1; i < LOG; i++) par[v][i] = par[par[v][i - 1]][i - 1];
for (int u : g[v]) if (!mark[u]) h[u] = h[v] + 1, par[u][0] = v, dfs(u);
}
void Solve(int v, int p = 0) {
mark[v] = 1;
for (int u : g[v]) if (!mark[u]) Solve(u, v), val[v] += val[u];
if (p && val[v]) cout << v << " " << p << "\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 (!mark[i]) dfs(i);
memset(mark, 0, sizeof mark), 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;
}
for (int i = 1; i <= n; i++) if (!mark[i]) Solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
3584 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
4224 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
286 ms |
9468 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
477 ms |
14296 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
798 ms |
22648 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1274 ms |
12848 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2083 ms |
14692 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2920 ms |
17364 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3582 ms |
25464 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4264 ms |
17520 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |