#include <stdio.h>
#include <vector>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 1e5+5;
int N, M;
int E[2*mxN], ne;
vector<int> al[mxN];
struct UFDS {
int p[mxN], s[mxN];
UFDS() { FOR(i,1,N) p[i] = i, s[i] = 1; }
int finds(int i) { return (p[i] == i) ? i : (p[i] = finds(p[i])); }
bool unions(int i, int j) {
int x = finds(i), y = finds(j);
if (x == y) return 0;
if (s[x] < s[y]) swap(x,y);
p[y] = x, s[x] += s[y];
return 1;
}
};
int num[mxN], low[mxN], cnt;
void dfs(int u, int p) {
num[u] = low[u] = cnt++;
for (int e : al[u]) {
if (e == p) continue;
int v = E[e]^u;
if (num[v] == -1) {
dfs(v,e);
low[u] = min(low[u],low[v]);
if (low[v] > num[u]) printf("%d %d\n", u, v);
} else low[u] = min(low[u],num[v]);
}
}
int main() {
scanf("%d %d", &N, &M);
UFDS UF[2];
ne = 0;
FOR(i,1,M){
int U, V; scanf("%d %d", &U, &V);
FOR(j,0,1){
if (UF[j].unions(U,V)) {
al[U].push_back(ne);
al[V].push_back(ne);
E[ne++] = U^V;
break;
}
}
}
FOR(i,1,N) num[i] = -1;
cnt = 0;
FOR(i,1,N) if (num[i] == -1) dfs(i,-1);
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:49:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int U, V; scanf("%d %d", &U, &V);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3328 KB |
Output is correct |
2 |
Correct |
10 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
4600 KB |
Output is correct |
2 |
Correct |
156 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
262 ms |
5360 KB |
Output is correct |
2 |
Correct |
334 ms |
6776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
8652 KB |
Output is correct |
2 |
Correct |
369 ms |
8660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
567 ms |
12616 KB |
Output is correct |
2 |
Correct |
534 ms |
11372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
928 ms |
13432 KB |
Output is correct |
2 |
Correct |
872 ms |
11356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1213 ms |
16148 KB |
Output is correct |
2 |
Correct |
1104 ms |
13908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1455 ms |
16292 KB |
Output is correct |
2 |
Correct |
1475 ms |
12108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1845 ms |
15864 KB |
Output is correct |
2 |
Correct |
1723 ms |
13048 KB |
Output is correct |