Submission #450337

# Submission time Handle Problem Language Result Execution time Memory
450337 2021-08-02T14:45:27 Z mp007mp Pipes (CEOI15_pipes) C++14
0 / 100
1404 ms 15740 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);
		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 Incorrect 2 ms 2636 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3276 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 135 ms 3040 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 204 ms 3928 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 373 ms 5716 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 491 ms 11884 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 719 ms 13224 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 956 ms 15740 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1242 ms 15644 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1404 ms 15064 KB Wrong number of edges
2 Halted 0 ms 0 KB -