# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
230361 |
2020-05-09T17:10:57 Z |
parsa_mobed |
Pipes (CEOI15_pipes) |
C++14 |
|
4565 ms |
31616 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] == 0) 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 |
Correct |
6 ms |
3584 KB |
Output is correct |
2 |
Correct |
6 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
4096 KB |
Output is correct |
2 |
Correct |
13 ms |
4096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
3960 KB |
Output is correct |
2 |
Correct |
254 ms |
9336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
469 ms |
4600 KB |
Output is correct |
2 |
Correct |
544 ms |
15864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
804 ms |
6208 KB |
Output is correct |
2 |
Runtime error |
694 ms |
20780 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1188 ms |
11256 KB |
Output is correct |
2 |
Correct |
1039 ms |
11980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1979 ms |
12480 KB |
Output is correct |
2 |
Correct |
1752 ms |
13560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2856 ms |
14476 KB |
Output is correct |
2 |
Correct |
2687 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3769 ms |
14572 KB |
Output is correct |
2 |
Runtime error |
3695 ms |
16788 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4565 ms |
13900 KB |
Output is correct |
2 |
Runtime error |
3623 ms |
31616 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |