Submission #450336

# Submission time Handle Problem Language Result Execution time Memory
450336 2021-08-02T14:43:16 Z mp007mp Pipes (CEOI15_pipes) C++14
40 / 100
1369 ms 30968 KB
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define S second 
#define F first
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<x<<"\n";
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
int mod = 1e9+7;
int inf = 2e9;
ll linf = 1000000ll*10000*10000;
const int maxn = 1e5+20;
int ldr[2][maxn],cnt[maxn],h[maxn];
bitset<maxn> mark;
vector<int> adj[maxn];
vector<pii> E,CE;
int dgt(int v,int det){
	return (ldr[det][v] == v)?v:ldr[det][v] = dgt(ldr[det][v],det);
}
inline bool uni(int u,int v,int det){
	u = dgt(u,det);
	v = dgt(v,det);
	if(u == v)return false;
	ldr[det][v] = u;
	return true;
}
void dfs(int v){
	mark[v] = 1;
	for(int u:adj[v]){
		if(mark[u])continue;
		h[u] = h[v]+1;
		dfs(u);
	}
}
void sec_dfs(int v){
	mark[v] = 1;
	for(int u:adj[v]){
		if(mark[u])continue;
		sec_dfs(u);
		if(cnt[u]<=1)CE.push_back({u,v});
		cnt[v] += cnt[u];
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
    	ldr[0][i] = ldr[1][i] = i;
    }
    for(int i=0;i<m;i++){
    	int u,v;
    	cin>>u>>v;
    	if(!uni(u,v,0) && !uni(u,v,1)){
    		continue;
    	}
    	E.push_back({u,v});
    	adj[v].push_back(u);
    	adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
    	if(!mark[i])dfs(i);
    }
    mark.reset();
    for(pii e:E){
    	if(h[e.F]>h[e.S])swap(e.F,e.S);
    	cnt[e.S]++;
    	cnt[e.F]--;
    }
    for(int i=1;i<=n;i++){
    	if(!mark[i])sec_dfs(i);
    }
    for(pii e:CE){
    	cout<<e.F<<" "<<e.S<<"\n";
    }
    return 0;
}

Compilation message

pipes.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("O3")
      | 
pipes.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("unroll-loops")
      |
# 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 3320 KB Output is correct
2 Correct 6 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 8516 KB Output is correct
2 Correct 118 ms 8244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 13528 KB Output is correct
2 Correct 256 ms 14648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 333 ms 21832 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 465 ms 19276 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 714 ms 23384 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 939 ms 30968 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1158 ms 24068 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1369 ms 26808 KB Memory limit exceeded
2 Halted 0 ms 0 KB -