#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5 + 7, mod = 1e9 + 7;
const ll inf = 2e18;
// How interesting!
int n, m, t;
vector<int> adj[N];
int low[N], tim[N];
void dfs(int x, int p)
{
low[x] = tim[x] = ++t;
for (auto u : adj[x])
{
if (u == p)
continue;
if (low[u])
{
low[x] = min(low[x], tim[u]);
}
else
{
dfs(u, x);
low[x] = min(low[x], low[u]);
}
if (low[u] > tim[x])
{
cout << x << " " << u << "\n";
}
}
}
struct dsu
{
int fat[N];
dsu()
{
for (int i = 0; i < N; ++i)
fat[i] = i;
}
int find(int x) { return (x == fat[x] ? x : find(fat[x])); }
void link(int u, int v)
{
u = find(u);
v = find(v);
if (u != v)
{
fat[u] = v;
}
}
bool same(int u, int v)
{
return find(u) == find(v);
}
} d1, d2;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.in", "r", stdin);
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
int u, v;
cin >> u >> v;
if (!d1.same(u, v))
{
d1.link(u, v);
}
else if (!d2.same(u, v))
{
d2.link(u, v);
}
else
continue;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; ++i)
{
if (!tim[i])
dfs(i, i);
}
return 0;
}
/*
- bounds sir (segtree = 4N, eulerTour = 2N, ...)
- a variable defined twice?
- will overflow?
- is it a good complexity?
- don't mess up indices (0-indexed vs 1-indexed)
- reset everything between testcases.
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3456 KB |
Output is correct |
2 |
Incorrect |
3 ms |
3456 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3832 KB |
Output is correct |
2 |
Incorrect |
14 ms |
3712 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3049 ms |
3792 KB |
Output is correct |
2 |
Incorrect |
614 ms |
3704 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5040 ms |
3960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5066 ms |
4624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5012 ms |
6244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5040 ms |
6700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5057 ms |
6680 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5060 ms |
6832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5043 ms |
6784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |