This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
bool vis[N];
ll hi[N];
ll ma[N];
void 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);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |