#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
const ll INF = 1e14;
/***********************CEOI 2015 D1 Pipes*****************************************/
template <int SZ> struct UnionFind {
int par[SZ];
void init(int NN) {
FOR(i, 0, NN) par[i] = i;
}
int find(int x) {
if (par[x] != x) par[x] = find(par[x]);
return par[x];
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
par[y] = x;
return true;
}
};
int n, m;
UnionFind<100001> uf1, uf2;
v<int> adj[100001];
int lo[100001], ind[100001], t = 0;
void tarjan(int cur, int par = -1) {
ind[cur] = lo[cur] = t++;
for (int nex : adj[cur]) if (nex != par) {
if (ind[nex] == -1) {
tarjan(nex, cur);
lo[cur] = min(lo[cur], lo[nex]);
if (lo[nex] > ind[cur]) {
cout << cur << " " << nex << "\n";
}
}
else lo[cur] = min(lo[cur], ind[nex]);
}
}
void findBridges() {
FOR(i, 0, n + 1)
ind[i] = -1, lo[i] = 0;
FOR(i, 0, n + 1) if (ind[i] == -1)
tarjan(i);
}
int main() {
io();
cin >> n >> m;
uf1.init(n + 1), uf2.init(n + 1);
FOR(i, 0, m) {
int a, b; cin >> a >> b;
if (uf1.unite(a, b) || uf2.unite(a, b)) {
adj[a].push_back(b), adj[b].push_back(a);
}
}
findBridges();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2688 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3200 KB |
Output is correct |
2 |
Incorrect |
7 ms |
3028 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
3036 KB |
Output is correct |
2 |
Incorrect |
94 ms |
2908 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
3724 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
289 ms |
5168 KB |
Output is correct |
2 |
Correct |
251 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
415 ms |
9952 KB |
Output is correct |
2 |
Incorrect |
394 ms |
7128 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
643 ms |
11100 KB |
Output is correct |
2 |
Incorrect |
608 ms |
8712 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
878 ms |
12964 KB |
Output is correct |
2 |
Incorrect |
779 ms |
8944 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1102 ms |
13016 KB |
Output is correct |
2 |
Incorrect |
1037 ms |
8940 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1200 ms |
12524 KB |
Output is correct |
2 |
Correct |
1218 ms |
10104 KB |
Output is correct |