//radinr85
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef deque<int> dq;
typedef long double ld;
typedef pair<int , int> pii;
typedef priority_queue<int> pq;
const int maxn = 3e6;
const ll mod = 1e9+7;
#define F first
#define S second
#define endl "\n"
#define pb push_back
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
const int N = 1e5 + 1;
vector<int> ver[N];
int par[N][2];
bool mark[N];
int cnt[N];
int n , m;
int get_par(int u , int x) {
return par[u][x] == u ? u : par[u][x] = get_par(par[u][x] , x);
}
bool merge(int u , int v , int x) {
u = get_par(u , x);
v = get_par(v , x);
if(u == v)
return false;
par[u][x] = v;
return true;
}
int DFS(int u) {
mark[u] = true;
for(auto v : ver[u]) {
if(!mark[v]) {
par[v][0] = u;
par[v][1] = par[u][1] + 1;
cnt[u] += DFS(v);
}
else if(par[u][1] - par[v][1] > 1) {
cnt[u] ++;
cnt[v] --;
}
}
if(cnt[u] == 0 && par[u][0] != 0)
cout << u << " " << par[u][0] << endl;
return cnt[u];
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1 ; i <= n ; i ++)
par[i][0] = i , par[i][1] = i;
for(int i = 0 ; i < m ; i ++) {
int u , v;
cin >> u >> v;
if(merge(u , v , 0)) {
ver[u].pb(v);
ver[v].pb(u);
}
else if(merge(u , v , 1)) {
ver[u].pb(v);
ver[v].pb(u);
}
}
ms(par , 0);
for(int i = 1 ; i <= n ; i ++)
if(!mark[i])
DFS(i);
return 0;
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:83:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
83 | for(int i = 1 ; i <= n ; i ++)
| ^~~
pipes.cpp:87:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
87 | return 0;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3412 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3796 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3632 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
3788 KB |
Output is correct |
2 |
Incorrect |
84 ms |
3596 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
167 ms |
4296 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
5604 KB |
Output is correct |
2 |
Correct |
191 ms |
5280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
364 ms |
9872 KB |
Output is correct |
2 |
Runtime error |
291 ms |
25292 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
482 ms |
10884 KB |
Output is correct |
2 |
Runtime error |
529 ms |
24256 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
637 ms |
12748 KB |
Output is correct |
2 |
Runtime error |
672 ms |
18596 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
785 ms |
12688 KB |
Output is correct |
2 |
Runtime error |
842 ms |
16608 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
925 ms |
12192 KB |
Output is correct |
2 |
Runtime error |
919 ms |
23772 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |