# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
36023 |
2017-12-04T09:13:23 Z |
funcsr |
Pipes (CEOI15_pipes) |
C++14 |
|
3682 ms |
12108 KB |
#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define pb push_back
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;
struct UnionFind {
int U[100000];
UnionFind(int N) {
rep(i, N) U[i] = i;
}
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return;
U[x] = y;
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
int N, M;
vector<int> G[100000];
bool used[100000];
int R[100000], T[100000];
void dfs(int x, int p, int r) {
used[x] = true;
R[x] = r;
for (int t : G[x]) {
if (t == p) continue;
if (used[t]) {
if (R[x] > R[t]) T[x]++, T[t]--;
continue;
}
dfs(t, x, r+1);
}
}
void dfs2(int x, int p) {
used[x] = true;
for (int t : G[x]) {
if (t == p || used[t]) continue;
dfs2(t, x);
T[x] += T[t];
}
if (p != -1 && T[x] == 0) cout << x+1 << " " << p+1 << "\n";
}
signed main() {
cin >> N >> M;
UnionFind uf1(N), uf2(N);
rep(_, M) {
int u, v;
cin >> u >> v;
u--, v--;
if (!uf1.same(u, v)) {
G[u].pb(v), G[v].pb(u);
uf1.unite(u, v);
}
else if (!uf2.same(u, v)) {
G[u].pb(v), G[v].pb(u);
uf2.unite(u, v);
}
}
rep(i, N) used[i] = false;
rep(i, N) if (!used[i]) dfs(i, -1, 0);
rep(i, N) used[i] = false;
rep(i, N) if (!used[i]) dfs2(i, -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2688 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3072 KB |
Output is correct |
2 |
Incorrect |
11 ms |
2944 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
3024 KB |
Output is correct |
2 |
Incorrect |
304 ms |
2936 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
511 ms |
3676 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
848 ms |
4896 KB |
Output is correct |
2 |
Correct |
727 ms |
4716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1171 ms |
9288 KB |
Output is correct |
2 |
Incorrect |
1047 ms |
6988 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1915 ms |
10288 KB |
Output is correct |
2 |
Incorrect |
1805 ms |
8356 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2423 ms |
12100 KB |
Output is correct |
2 |
Incorrect |
2254 ms |
9040 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3078 ms |
12108 KB |
Output is correct |
2 |
Incorrect |
2936 ms |
8916 KB |
Wrong number of edges |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3682 ms |
11600 KB |
Output is correct |
2 |
Correct |
3536 ms |
9764 KB |
Output is correct |