#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e5+10;
ll par1[N],par2[N];
ll get1(ll v){
if (par1[v]==v) return v;
return par1[v]=get1(par1[v]);
}
ll get2(ll v){
if (par2[v]==v) return v;
return par2[v]=get2(par2[v]);
}
vector <int> g[N];
ll vis[N];
ll hi[N];
ll ma[N];
ll dfs(ll v,ll p,ll h){
vis[v]=1;
hi[v]=h;
ll p1=0;
ma[v]=h-1;
for (auto u : g[v]){
if (u==p){
p1++;
continue;
}
if (vis[u]==0){
dfs(u,v,h+1);
ma[v]=min(ma[v],ma[u]);
if (ma[u]<=h-1) p1+=2;
}
else if (hi[u]<hi[v]){
p1+=2;
ma[v]=min(ma[v],hi[u]);
}
}
// cout << v << " jn " << ma[v] << endl;
if (p1<2 && p!=0){
cout << p << " " << v << endl;
}
}
int32_t main(){
sync;
ll n,m;
cin >> n >> m;
for (int i=0;i<N;i++) par1[i]=i,par2[i]=i;
for (int i=0;i<m;i++){
ll u,v;
cin >> u >> v;
ll u1=get1(u),v1=get1(v);
if (u1!=v1){
g[u].pb(v);
g[v].pb(u);
par1[u1]=v1;
continue;
}
u1=get2(u),v1=get2(v);
if (u1!=v1){
g[u].pb(v);
g[v].pb(u);
par2[u1]=v1;
}
}
for (int i=1;i<=n;i++) if (!vis[i]) dfs(i,0,0);
}
Compilation message
pipes.cpp: In function 'll dfs(ll, ll, ll)':
pipes.cpp:54:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3456 KB |
Output is correct |
2 |
Correct |
6 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4096 KB |
Output is correct |
2 |
Correct |
10 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
8312 KB |
Output is correct |
2 |
Correct |
116 ms |
8184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
9024 KB |
Output is correct |
2 |
Correct |
227 ms |
6848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
318 ms |
10488 KB |
Output is correct |
2 |
Correct |
312 ms |
11104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
503 ms |
12024 KB |
Output is correct |
2 |
Correct |
439 ms |
8060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
806 ms |
17528 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
985 ms |
19960 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1189 ms |
15604 KB |
Output is correct |
2 |
Correct |
1154 ms |
15096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1446 ms |
15096 KB |
Output is correct |
2 |
Correct |
1709 ms |
11844 KB |
Output is correct |