이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 n,m,dp[100001], lvl[100001];
pair<int,int> edges[2000001];
int getAdj(int u){
return lower_bound(edges,edges+2*m,make_pair(u,0)) - edges;
}
int dfs(int u,int p){
for(int i = getAdj(u);i<2*m&&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(){_
cin>>n>>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(edges,edges+2*m);
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... |