// ki bood ke goft Ghatinga?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppiii;
// vectors and Sets:
#define vc vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rend(), (c).rbegin
// pairs
#define mp make_pair
#define fr first
#define sc second
// loops
#define FOR(i , m , n) for(int (i) = (m) ; (i) < (n) ; (i)++)
#define ROF(i , n , m) for(int (i) = (n) ; (i) >= (m) ; (i)--)
//#define FOR(n) for(int (i) = (o) ; (i) < (n) ; (i)++)
//#define ROF(n) for(int (i) = (m) ; (i) >= (0) ; (i)--)
// execution time check and Debug
#define StartEX; clock_t startExeTime = clock();
#define EndEX; clock_t endExeTime = clock();
#define ExTime; cerr << "\nTotal Execution Time is: " << double(-double(startExeTime)+double(endExeTime)) / CLOCKS_PER_SEC;
#define debug(x) cerr << #x << " : " << x << '\n'
#define endl "\n"
// time optimization
#define Heh ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
//#pragma GCC option("tune=native") // f*ck
//#pragma GCC target("avx,avx2,fma")
// useful functions
#define BPT(n) (1 << floor(log2((n))));
#define LPT(n) (1 << ceil(log2((n))*1.0));
//Calculates b'th power of a
ll pw(ll a,ll b){
ll ret = 1;
ll mul = a;
while(b > 0){
if(b&1)
ret = (ret * mul);
mul = (mul * mul);
b /= 2;
}
return ret;
}
//Converts s string to int
ll to_int(string s){
ll ret = 0;
FOR(i,0,s.size()){
ret += pw(10,s.size()-i-1) * (ll)(s[i] - '0');
}
return ret;
}
const int MAXN = 1e5 + 15;
int n , m , par[2][MAXN] , rnk[2][MAXN] , mark[MAXN] , tin[MAXN] , tme;
vc<int> adj[MAXN];
int get(int v , int t){return par[t][v] = (par[t][v] == v ? v : get(par[t][v] , t));}
inline bool uni(int a , int b , int t){
a = get(a , t) , b = get(b , t);
if(a == b) return 0;
if(rnk[t][a] < rnk[t][b]) swap(a , b);
par[t][b] = a;
rnk[t][a] += (rnk[t][a] == rnk[t][b]);
return 1;
}
int dfs(int v , int p = -1){
mark[v] = 1;
tin[v] = tme++;
int low = MAXN;
bool fl = 0;
for(int u : adj[v]){
if(mark[u] == 0) low = min(low , dfs(u , v));
if(mark[u] == 1){
if(u == p){
if(fl) low = min(low , tin[u]);
else fl = 1;
}
else low = min(low , tin[u]);
}
}
mark[v] = 2;
if(low >= tin[v] && p != -1){
cout << v+1 << " " << p+1 << endl;
}
return low;
}
int main()
{
int ed = 0;
Heh;
cin >> n >> m;
iota(par[0] , par[0] + n , 0);
iota(par[1] , par[1] + n , 0);
for(int i = 0 ; i < m ; i++){
int s , e;
cin >> s >> e;
s-- , e--;
if(uni(s , e , 0) || uni(s , e , 1)){
adj[s].pb(e) , adj[e].pb(s) , ed++;
assert(ed <= 2*MAXN);
}
}
for(int v = 0 ; v < n ; v++){
if(!mark[v]) dfs(v);
}
}
// ki seda kard Patinga?
Compilation message
pipes.cpp:31:9: warning: ISO C++11 requires whitespace after the macro name
31 | #define StartEX; clock_t startExeTime = clock();
| ^~~~~~~
pipes.cpp:32:9: warning: ISO C++11 requires whitespace after the macro name
32 | #define EndEX; clock_t endExeTime = clock();
| ^~~~~
pipes.cpp:33:9: warning: ISO C++11 requires whitespace after the macro name
33 | #define ExTime; cerr << "\nTotal Execution Time is: " << double(-double(startExeTime)+double(endExeTime)) / CLOCKS_PER_SEC;
| ^~~~~~
pipes.cpp: In function 'll to_int(std::string)':
pipes.cpp:25:32: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
25 | #define FOR(i , m , n) for(int (i) = (m) ; (i) < (n) ; (i)++)
| ^
pipes.cpp:61:5: note: in expansion of macro 'FOR'
61 | FOR(i,0,s.size()){
| ^~~
pipes.cpp:25:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | #define FOR(i , m , n) for(int (i) = (m) ; (i) < (n) ; (i)++)
| ~~~~^~~~~
pipes.cpp:61:5: note: in expansion of macro 'FOR'
61 | FOR(i,0,s.size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3148 KB |
Output is correct |
2 |
Correct |
5 ms |
2892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
3088 KB |
Output is correct |
2 |
Correct |
120 ms |
2860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
3724 KB |
Output is correct |
2 |
Correct |
242 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
5472 KB |
Output is correct |
2 |
Correct |
293 ms |
5188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
464 ms |
11060 KB |
Output is correct |
2 |
Correct |
415 ms |
7620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
714 ms |
12416 KB |
Output is correct |
2 |
Correct |
732 ms |
9540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
958 ms |
14608 KB |
Output is correct |
2 |
Correct |
920 ms |
9784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1227 ms |
14740 KB |
Output is correct |
2 |
Correct |
1174 ms |
9920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1477 ms |
14072 KB |
Output is correct |
2 |
Correct |
1387 ms |
11320 KB |
Output is correct |