이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of god
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << "\n"
#define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef string str;
const ll maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
ll n, m, par[maxn], p2[maxn], h[maxn], mn[maxn];
vector <ll> adj[maxn];
bool mrk[maxn];
ll get_par(ll v){
if(par[v] == v)return v;
par[v] = get_par(par[v]);
return par[v];
}
bool merge(ll v, ll u){
u = get_par(u);
v = get_par(v);
if(u == v)return 0;
par[v] = u;
return 1;
}
ll get_p2(ll v){
if(p2[v] == v)return v;
p2[v] = get_p2(p2[v]);
return p2[v];
}
bool merge2(ll v, ll u){
u = get_p2(u);
v = get_p2(v);
if(u == v)return 0;
p2[v] = u;
return 1;
}
void dfs(ll v){
mrk[v] = 1;
bool b = 0;
mn[v] = h[v];
for(ll j : adj[v]){
if(mrk[j]){
if(j == par[v]){
if(!b)b = 1;
else mn[v] = min(mn[v], h[j]);
}
else mn[v] = min(mn[v], h[j]);
continue;
}
h[j] = h[v] + 1;
par[j] = v;
dfs(j);
mn[v] = min(mn[v], mn[j]);
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for(ll i = 1; i <= n; i ++){
par[i] = i;
p2[i] = i;
}
for(ll i = 0; i < m; i ++){
ll u, v; cin >> u >> v;
if(merge(u, v)){
adj[u].pb(v);
adj[v].pb(u);
continue;
}
else if(merge2(u, v)){
adj[u].pb(v);
adj[v].pb(u);
}
}
for(ll i = 1; i <= n; i ++)par[i] = 0;
for(ll i = 1; i <= n; i ++){
if(!mrk[i])dfs(i);
if(mn[i] == h[i] && (par[i])){
cout << i << ' ' << par[i] << '\n';
}
}
}
# | 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... |