# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
454674 |
2021-08-05T07:11:03 Z |
AmirrezaM |
Pipes (CEOI15_pipes) |
C++17 |
|
1566 ms |
14744 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);
}
for(int v = 0 ; v < n ; v++){
if(!mark[v]) dfs(v);
}
}
// ki seda kard Patinga?
Compilation message
pipes.cpp:30:9: warning: ISO C++11 requires whitespace after the macro name
30 | #define StartEX; clock_t startExeTime = clock();
| ^~~~~~~
pipes.cpp:31:9: warning: ISO C++11 requires whitespace after the macro name
31 | #define EndEX; clock_t endExeTime = clock();
| ^~~~~
pipes.cpp:32:9: warning: ISO C++11 requires whitespace after the macro name
32 | #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:24:32: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
24 | #define FOR(i , m , n) for(int (i) = (m) ; (i) < (n) ; (i)++)
| ^
pipes.cpp:60:5: note: in expansion of macro 'FOR'
60 | FOR(i,0,s.size()){
| ^~~
pipes.cpp:24:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define FOR(i , m , n) for(int (i) = (m) ; (i) < (n) ; (i)++)
| ~~~~^~~~~
pipes.cpp:60:5: note: in expansion of macro 'FOR'
60 | FOR(i,0,s.size()){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3148 KB |
Output is correct |
2 |
Correct |
6 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
3004 KB |
Output is correct |
2 |
Correct |
121 ms |
2884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
3728 KB |
Output is correct |
2 |
Correct |
252 ms |
3316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
433 ms |
5496 KB |
Output is correct |
2 |
Correct |
290 ms |
5160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
553 ms |
11060 KB |
Output is correct |
2 |
Correct |
502 ms |
7600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
780 ms |
12356 KB |
Output is correct |
2 |
Correct |
818 ms |
9540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1070 ms |
14740 KB |
Output is correct |
2 |
Correct |
935 ms |
9780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1214 ms |
14744 KB |
Output is correct |
2 |
Correct |
1171 ms |
9796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1566 ms |
14072 KB |
Output is correct |
2 |
Correct |
1390 ms |
11232 KB |
Output is correct |