#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
int ret[200005], dep[200005], vis[200005];
vector<pi>v[200005], adj[200005];
int n, m;
inline int read() {
int v = 0;
char ch = getchar_unlocked();
while ((ch & 16) == 0) ch = getchar_unlocked();
while (ch & 16){
v = (v * 10) + (ch & 15);
ch = getchar_unlocked();
}
return v;
}
vector<pi>ans;
void dfs(int x, int p, int d){
if(vis[x])return;
vis[x] = 1;
dep[x] = d;
ret[x] = dep[x];
for(auto [i, j] : v[x]){
if(j == p)continue;
if(vis[i]){
ret[x] = min(ret[x], dep[i]);
continue;
}
dfs(i, j, d + 1);
if(ret[i] > dep[x])ans.push_back({i, x});
ret[x] = min(ret[x], ret[i]);
}
}
void dfs2(int x, int p){
ret[x] = dep[x];
for(auto [i, j] : v[x])if(j != p)ret[x] = min(ret[x], dep[i]);
for(auto [i, j] : adj[x]){
if(j == p)continue;
dfs2(i, j);
if(ret[i] > dep[x])ans.push_back({i, x});
ret[x] = min(ret[x], ret[i]);
}
cerr << "VALUE " << x << " " << ret[x] << '\n';
}
int32_t main(){
//ios::sync_with_stdio(0);cin.tie(0);
n = read(), m = read();
for(int i=1;i<=m;i++){
int x = read(), y = read();
v[x].push_back({y, i});
v[y].push_back({x, i});
}
for(int i=1;i<=n;i++)if(!vis[i])dfs(i, -1, 1);
for(auto [i, j] : ans)cout << i << " " << j << '\n';
}
Compilation message
pipes.cpp: In function 'void dfs(long long int, long long int, long long int)':
pipes.cpp:32:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | for(auto [i, j] : v[x]){
| ^
pipes.cpp: In function 'void dfs2(long long int, long long int)':
pipes.cpp:46:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | for(auto [i, j] : v[x])if(j != p)ret[x] = min(ret[x], dep[i]);
| ^
pipes.cpp:47:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [i, j] : adj[x]){
| ^
pipes.cpp: In function 'int32_t main()':
pipes.cpp:66:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for(auto [i, j] : ans)cout << i << " " << j << '\n';
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10836 KB |
Output is correct |
2 |
Correct |
7 ms |
10452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
46508 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
62504 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
180 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
192 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
238 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
262 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
260 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
248 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |