Submission #1034754

# Submission time Handle Problem Language Result Execution time Memory
1034754 2024-07-25T17:30:34 Z vjudge1 Pipes (CEOI15_pipes) C++17
40 / 100
697 ms 60944 KB
#include <iostream>
#include <vector>
using namespace std;

const int N = 1e5+2;
struct dsu {
	int e[N];
	int find(int &x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
		return true;
	}
} d1, d2;
vector<int> g[N];
int timer=0;
void dfs(int &at, int &par) {
	d1.e[at]=d2.e[at]=++timer;
	for(int &to:g[at]) {
		if(to == par) {
			par+=N;
			continue;
		}
		if(d2.e[to]) {
			d1.e[at]=min(d1.e[at], d2.e[to]);		
		} else {
			dfs(to, at);
			d1.e[at]=min(d1.e[at], d1.e[to]);
		}
	}
	if(par>N)par-=N;
	if(d1.e[at] == d2.e[at] and at!=par) {
		cout << at << " " << par << "\n";
	}
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	int n, m;
	cin >> n >> m;
	int u, v;
	for(int i = 1;i<N;i++)d1.e[i]=d2.e[i]=-1;
	for(int i = 0;i<m;i++) {
		cin >> u >> v;
		if(d1.join(u, v) || d2.join(u, v)) {
			g[u].push_back(v);
			g[v].push_back(u);
		}
	}
	for(int i = 1;i<N;i++)d1.e[i]=d2.e[i]=0;
	for(int i= 1;i<=n;i++) {
		if(!d1.e[i]) {
			dfs(i, i);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3932 KB Output is correct
2 Correct 3 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 3676 KB Output is correct
2 Correct 53 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 4232 KB Output is correct
2 Correct 120 ms 3952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 5200 KB Output is correct
2 Runtime error 137 ms 16468 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 9044 KB Output is correct
2 Runtime error 195 ms 23956 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 324 ms 10064 KB Output is correct
2 Runtime error 355 ms 41044 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 480 ms 11344 KB Output is correct
2 Runtime error 435 ms 49232 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 587 ms 11156 KB Output is correct
2 Runtime error 576 ms 60944 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 697 ms 17852 KB Memory limit exceeded
2 Halted 0 ms 0 KB -