Submission #1021704

# Submission time Handle Problem Language Result Execution time Memory
1021704 2024-07-13T02:59:08 Z idiotcomputer Pipes (CEOI15_pipes) C++11
40 / 100
687 ms 65536 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size 
 
const int mxN = 1e5;
vector<int> adj[mxN];
int d[mxN];
int low[mxN];
 
void dfs(int c, int depth, int p){
	d[c] = depth;
	low[c] = d[c];
	int op = p;
	for (int i : adj[c]){
		if (i == p){p = -1; continue;}
		if (d[i] != -1){ low[c] = min(low[c],d[i]); continue;}
		dfs(i,depth+1,c);
		low[c] = min(low[c], low[i]);
	}
	if (low[c] >= depth && op != -1) cout << c+1 << " " << op+1 << '\n';
}
 
int p[mxN][2];
int ssize[mxN][2];
 
int gpar(int c, int w){
	if (p[c][w] == c) return c;
	p[c][w] = gpar(p[c][w],w);
	return p[c][w];
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	int n,m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) {p[i][j] = i; ssize[i][j] = 1;}
 
	int a,b;
	int x,y;
	for (int i = 0; i < m; i++){
		cin >> a >> b;
		a -= 1;
		b -= 1;
		x = gpar(a,0);
		y = gpar(b,0);
		if (x != y){
			adj[a].pb(b);
			adj[b].pb(a);
			if (ssize[x][0] < ssize[y][0]) swap(x,y);
			ssize[x][0] += ssize[y][0];
			p[y][0] = x;
			continue;
		}
		x = gpar(a,1);
		y = gpar(b,1);
		if (x == y) continue;
		if (ssize[x][1] < ssize[y][1]) swap(x,y);
		ssize[x][1] += ssize[y][1];
		p[y][1] = x;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	for (int i = 0; i < n; i++) d[i] = -1;
	for (int i = 0; i < n; i++) if (d[i] == -1) dfs(i,0,-1);
	
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3416 KB Output is correct
2 Correct 4 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3264 KB Output is correct
2 Correct 67 ms 8236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 3920 KB Output is correct
2 Correct 117 ms 14960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 5676 KB Output is correct
2 Runtime error 172 ms 19280 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 225 ms 11772 KB Output is correct
2 Runtime error 220 ms 26056 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 337 ms 13180 KB Output is correct
2 Runtime error 361 ms 43200 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 436 ms 15700 KB Output is correct
2 Runtime error 445 ms 51236 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 582 ms 15952 KB Output is correct
2 Runtime error 579 ms 62800 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 687 ms 14932 KB Output is correct
2 Runtime error 684 ms 65536 KB Memory limit exceeded
3 Halted 0 ms 0 KB -