# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
36020 |
2017-12-04T08:55:04 Z |
funcsr |
Pipes (CEOI15_pipes) |
C++14 |
|
1182 ms |
8340 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];
int R[100000];
void dfs(int x, int p, int r) {
R[x] = r;
for (int t : G[x]) {
if (t == p) continue;
dfs(t, x, r+1);
}
}
int T[100000];
void dfs2(int x, int p) {
for (int t : G[x]) {
if (t == p) continue;
dfs2(t, x);
T[x] += T[t];
}
if (p != -1 && T[x] == 0) cout << x+1 << " " << p+1 << "\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
UnionFind uf1(N), uf2(N);
vector<P> backwards;
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)) {
backwards.pb(P(u, v));
uf2.unite(u, v);
}
}
rep(i, N) if (uf1.find(i) == i) dfs(i, -1, 0);
for (P p : backwards) {
int u = p._1, v = p._2;
if (R[u] > R[v]) swap(u, v);
//cout<<"u="<<u<<","<<v<<"\n";
T[v]++, T[u]--;
}
rep(i, N) if (uf1.find(i) == i) dfs2(i, -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2704 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
2944 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
2936 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
156 ms |
3320 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
272 ms |
3996 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
385 ms |
6564 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
581 ms |
7196 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
797 ms |
8300 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
978 ms |
8340 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1182 ms |
7960 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |