Submission #454669

# Submission time Handle Problem Language Result Execution time Memory
454669 2021-08-05T07:10:22 Z AmirrezaM Pipes (CEOI15_pipes) C++17
Compilation error
0 ms 0 KB
// 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()
{
  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++;
  }
  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()){
      |     ^~~
pipes.cpp: In function 'int main()':
pipes.cpp:113:69: error: 'ed' was not declared in this scope; did you mean 'e'?
  113 |  if(uni(s , e , 0) || uni(s , e , 1)) adj[s].pb(e) , adj[e].pb(s) , ed++;
      |                                                                     ^~
      |                                                                     e