#include <bits/stdc++.h>
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
#define F first
#define S second
#define pb push_back
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=5e5+10,LN=20,M=1e5+10,SQ=450,inf=1e9;
const ll INF=1e18;
const int MH=1000696969,MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
ll n,q,p[2][N],m,dp[N],h[N];
bool f[N];
vector<pll> adj[N];
ll gp(ll c, ll x){
return p[c][x]?p[c][x]=gp(c,p[c][x]):x;
}
bool uni(ll c, ll v, ll u){
v=gp(c,v);
u=gp(c,u);
if(v==u) return false;
p[c][u]=v;
return true;
}
void dfs(ll v, ll i, ll pr){
f[v]=1;
dp[v]=h[v];
for(auto [u,j] : adj[v]){
if(!f[u]) h[u]=h[v]+1,dfs(u,j,v),dp[v]=min(dp[u],dp[v]);
}
for(auto [u,j] : adj[v]){
if(j!=i) dp[v]=min(dp[v],h[u]);
}
if(dp[v]==h[v] && pr) cout << v << ' ' << pr << '\n';
}
int main(){
fast_io;
cin >> n >> q;
while(q--){
ll v,u;
cin >> v >> u;
if(uni(0,v,u) || uni(1,v,u)) adj[v].pb({u,m}),adj[u].pb({v,m++});
}
for(ll i=1; i<=n; i++) if(!f[i]) dfs(i,-1,0);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
13292 KB |
Output is correct |
2 |
Correct |
13 ms |
12780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
119 ms |
18412 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
200 ms |
23148 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
346 ms |
25452 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
485 ms |
39148 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
733 ms |
32684 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1055 ms |
42132 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1222 ms |
33864 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1398 ms |
38236 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |