Submission #450339

# Submission time Handle Problem Language Result Execution time Memory
450339 2021-08-02T14:46:47 Z mp007mp Pipes (CEOI15_pipes) C++14
40 / 100
1462 ms 29412 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;
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)cout<<u<<" "<<v<<"\n";
		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);
    }
    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 3224 KB Output is correct
2 Correct 6 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 3032 KB Output is correct
2 Correct 112 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 3816 KB Output is correct
2 Correct 272 ms 3400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 5560 KB Output is correct
2 Runtime error 302 ms 18964 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 468 ms 11060 KB Output is correct
2 Runtime error 427 ms 26320 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 715 ms 12392 KB Output is correct
2 Runtime error 702 ms 20112 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 926 ms 14492 KB Output is correct
2 Runtime error 938 ms 24892 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1133 ms 14568 KB Output is correct
2 Runtime error 1127 ms 29412 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1462 ms 13932 KB Output is correct
2 Runtime error 1417 ms 23532 KB Memory limit exceeded