// Restart
// += O(logn) ; + = O(n)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz size()
#define FORN(i,j,n) for(int i=j; i<(int)n;i++)
#define FOR(i,n) FORN(i,0,n)
#define FORIT(i,x) for( auto i = x.begin() ; i != x.end() ; i++ )
#define MOD 998244353LL
#define MOD1 1000000007LL
#define LIM 262150
#define ones(x) __builtin_popcount(x)
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y,z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define INF 1000000000
#define in(x) cin>>x;
#define out(x) cout<<x;
#define MAXIMO 1LL<<60
#define loga2(x) __builtin_ctzll(x)
//SOLO PARA POTENCIAS DE 2
using namespace std;
using namespace __gnu_pbds;
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi;
typedef pair <int,int> ii;
typedef pair <int,ii> iii;
typedef vector <string> vs;
typedef vector <ii> vii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
vector<int> G[100005];
int g_low[100005];
int g_num[100005];
int P[2][100005];
int n,m;
int cont = 1;
void dsu(int z){
for(int i=1; i<=n;i++){
P[z][i] = i;
}
}
int dsu_find(int z, int x){
if(x==P[z][x]) return x;
P[z][x] = dsu_find(z,P[z][x]);
return P[z][x];
}
void dsu_uni(int z, int a , int b){
int x = dsu_find(z,a);
int y = dsu_find(z,b);
if(x==y) return ;
P[z][y] = x;
}
void dfs(int x ,int p = -1){ // p: parent
g_low[x]=g_num[x]=cont++; // low:component ; num:visit order
for(int v : G[x]){
if(g_num[v]==-1){
dfs(v,x);
/*if(g_low[v] >= g_num[x]){ // CUT-VERTEX
//cut[x] = true;
}*/
if(g_low[v] > g_num[x] && dsu_find(1,v) != dsu_find(1,x)){ // BRIDGE
//bridge.push_back({min(x,v),max(x,v)});
cout<< x << " " << v << "\n";
}
g_low[x]=min(g_low[x],g_low[v]);
}
if(v != p){
g_low[x]=min(g_low[x],g_num[v]);
}
}
}
void go(){
cin>>n>>m;
int x,y;
FORN(i,1,n+1){
g_low[i] = -1; g_num[i] = -1;
}
dsu(0);
dsu(1);
FOR(i,m){
cin>>x>>y;
if(dsu_find(0,x) != dsu_find(0,y)){
dsu_uni(0,x,y);
}
else{
if(dsu_find(1,x) != dsu_find(1,y)){
dsu_uni(1,x,y);
}
else continue;
}
G[x].push_back(y);
G[y].push_back(x);
}
for(int i=1;i<=n;i++){
if(g_num[i] == -1) dfs(i);
}
}
void timer(){
clock_t begin = clock();
go();
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%lf\n",time_spent);
}
int main() {
fastio;
go();
//timer();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3148 KB |
Output is correct |
2 |
Correct |
6 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
3012 KB |
Output is correct |
2 |
Correct |
110 ms |
2856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
3600 KB |
Output is correct |
2 |
Correct |
219 ms |
14660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
5120 KB |
Output is correct |
2 |
Runtime error |
304 ms |
18628 KB |
Memory limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
447 ms |
10020 KB |
Output is correct |
2 |
Runtime error |
403 ms |
25152 KB |
Memory limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
687 ms |
11004 KB |
Output is correct |
2 |
Runtime error |
723 ms |
42028 KB |
Memory limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
899 ms |
13028 KB |
Output is correct |
2 |
Runtime error |
875 ms |
50272 KB |
Memory limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1112 ms |
16904 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1340 ms |
29232 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |