#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+5;
vector<int> adj[N];
int n, m, tin[N], tmp, par[2][N];
int get(int src, int t)
{
if(src == par[t][src]) return src;
return par[t][src] = get(par[t][src], t);
}
bool join(int u, int v, int t)
{
u = get(u, t), v = get(v, t);
if(u == v) return false;
par[t][u] = v;
return true;
}
int dfs(int src, int pa = -1)
{
int low, idx = 0;
tin[src] = low = ++tmp;
for(auto it : adj[src])
{
if(it == pa)
{
idx++;
continue;
}
if(tin[it])
{
low = min(low, tin[it]);
idx++;
continue;
}
int low_it = dfs(it, src);
low = min(low, low_it);
if(idx && adj[src][idx-1] == it)
{
idx++;
continue;
}
if(idx+1 < adj[src].size() && adj[src][idx+1] == it)
{
idx++;
continue;
}
if(low_it > tin[src])
{
cout << src << ' ' << it << endl;
}
idx++;
}
return low;
}
int main()
{
fastio;
cin >> n >> m;
for(int i = 1; i <= n; i++) par[0][i] = par[1][i] = i;
for(int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
if(join(u, v, 0) || join(u, v, 1))
{
adj[u].push_back(v), adj[v].push_back(u);
}
}
for(int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());
for(int i = 1; i <= n; i++)
{
if(!tin[i]) dfs(i);
}
return 0;
}
Compilation message
pipes.cpp: In function 'int dfs(int, int)':
pipes.cpp:50:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if(idx+1 < adj[src].size() && adj[src][idx+1] == it)
| ~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4188 KB |
Output is correct |
2 |
Correct |
4 ms |
3932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
3948 KB |
Output is correct |
2 |
Correct |
65 ms |
3932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
4720 KB |
Output is correct |
2 |
Correct |
133 ms |
4196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
6564 KB |
Output is correct |
2 |
Correct |
158 ms |
5972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
11392 KB |
Output is correct |
2 |
Runtime error |
242 ms |
25444 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
12584 KB |
Output is correct |
2 |
Runtime error |
392 ms |
42664 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
530 ms |
14864 KB |
Output is correct |
2 |
Runtime error |
505 ms |
50168 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
689 ms |
14888 KB |
Output is correct |
2 |
Runtime error |
681 ms |
61704 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
802 ms |
14400 KB |
Output is correct |
2 |
Runtime error |
783 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |