Submission #1034723

# Submission time Handle Problem Language Result Execution time Memory
1034723 2024-07-25T17:12:19 Z vjudge1 Pipes (CEOI15_pipes) C++17
40 / 100
156 ms 19308 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 30'010;
struct dsu {
	int e[N];
	dsu() {
		memset(e, -1, sizeof e);
	}
	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) {
	bool ck=0;

	d1.e[at]=d2.e[at]=++timer;
	for(int to:g[at]) {
		if(to == par and ck==0) {
			ck=1;
			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(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 = 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);
		}
	}
	memset(d1.e, 0, sizeof d1.e);
	memset(d2.e, 0, sizeof d2.e);
	for(int i= 1;i<=n;i++) {
		if(!d1.e[i]) {
			dfs(i, i);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1832 KB Output is correct
2 Correct 3 ms 1640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7284 KB Output is correct
2 Correct 55 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 11604 KB Output is correct
2 Correct 116 ms 13004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 156 ms 19308 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2424 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 2396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 2396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 2436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -