답안 #454655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
454655 2021-08-05T07:03:39 Z AmirrezaM Pipes (CEOI15_pipes) C++17
40 / 100
1490 ms 56916 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));}
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] and 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);
  }
  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 2672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3276 KB Output is correct
2 Correct 6 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8484 KB Output is correct
2 Correct 123 ms 8240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 13500 KB Output is correct
2 Correct 260 ms 14572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 356 ms 21652 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 469 ms 31784 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 751 ms 26296 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 958 ms 34328 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1223 ms 44548 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1490 ms 56916 KB Memory limit exceeded
2 Halted 0 ms 0 KB -