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>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
int dp[2*maxn], lvl[2*maxn];
vector<ii>edges;
int getAdj(int u){
return lower_bound(all(edges),make_pair(u,0)) - begin(edges);
}
int dfs(int u,int p){
for(int i = getAdj(u);i<sz(edges)&&edges[i].first==u;++i){
int v = edges[i].second;
if(lvl[v]==0){
lvl[v] = lvl[u]+1;
dp[u] += dfs(v,u);
}else if(lvl[v]>lvl[u]){
dp[u]--;
}else{
dp[u]++;
}
}
dp[u]--;
if(dp[u]==0&&lvl[u]!=1)cout<<u<<" "<<p<<endl;
return dp[u];
}
int main(){_
int n,m;cin>>n>>m;
edges.resize(2*m);
for(int i=0;i<m;++i){
int a,b;cin>>a>>b;
edges[2*i] = {a,b};
edges[2*i+1] = {b,a};
}
sort(all(edges));
for(int i=0;i<2*m;++i){
if(!lvl[edges[i].first]){
lvl[edges[i].first] = 1;
dfs(edges[i].first,edges[i].first);
}
}
}
# | 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... |