# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
36026 |
2017-12-04T09:18:01 Z |
funcsr |
Pipes (CEOI15_pipes) |
C++14 |
|
1448 ms |
14180 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<P> G[100000];
bool used[100000];
int R[100000], T[100000];
void dfs(int x, int pe, int r) {
used[x] = true;
R[x] = r;
for (P pp : G[x]) {
int t = pp._1;
if (pp._2 == pe) continue;
if (used[t]) {
if (R[x] > R[t]) T[x]++, T[t]--;
continue;
}
dfs(t, pp._2, r+1);
}
}
void dfs2(int x, int p) {
used[x] = true;
for (P pp : G[x]) {
int t = pp._1;
if (t == p || used[t]) continue;
dfs2(t, x);
T[x] += T[t];
}
if (p != -1 && T[x] == 0) printf("%d %d\n", x+1, p+1);
}
signed main() {
scanf("%d %d", &N, &M);
UnionFind uf1(N), uf2(N);
rep(i, M) {
int u, v;
scanf("%d %d", &u, &v);
u--, v--;
if (!uf1.same(u, v)) {
G[u].pb(P(v, i)), G[v].pb(P(u, i));
uf1.unite(u, v);
}
else if (!uf2.same(u, v)) {
G[u].pb(P(v, i)), G[v].pb(P(u, i));
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;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3200 KB |
Output is correct |
2 |
Correct |
8 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
3108 KB |
Output is correct |
2 |
Correct |
110 ms |
2956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
3752 KB |
Output is correct |
2 |
Correct |
228 ms |
3500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
5376 KB |
Output is correct |
2 |
Correct |
282 ms |
5052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
527 ms |
10704 KB |
Output is correct |
2 |
Correct |
440 ms |
8368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
772 ms |
12016 KB |
Output is correct |
2 |
Correct |
722 ms |
9208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
998 ms |
14100 KB |
Output is correct |
2 |
Correct |
962 ms |
10904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1230 ms |
14180 KB |
Output is correct |
2 |
Correct |
1171 ms |
10904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1448 ms |
13600 KB |
Output is correct |
2 |
Correct |
1364 ms |
10748 KB |
Output is correct |