Submission #1034714

# Submission time Handle Problem Language Result Execution time Memory
1034714 2024-07-25T17:06:17 Z vjudge1 Pipes (CEOI15_pipes) C++17
40 / 100
166 ms 19796 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 sameSet(int a, int b) { return find(a) == find(b); }
	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+1];
int low[N+1], id[N+1];
int timer=0;
void dfs(int at, int par) {
	bool ck=0;
	id[at]=low[at]=++timer;
	for(int to:g[at]) {
		if(to == par and ck==0) {
			ck=1;
			continue;
		}
		if(id[to]) {
			low[at]=min(low[at], id[to]);		
		} else {
			dfs(to, at);
			low[at]=min(low[at], low[to]);
		}
	}
	if(low[at] == id[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;
	int cnt=0;
	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++) {
		if(!id[i]) {
			dfs(i, i);
		}
	}
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:48:6: warning: unused variable 'cnt' [-Wunused-variable]
   48 |  int cnt=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 6996 KB Output is correct
2 Correct 59 ms 6752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 11860 KB Output is correct
2 Correct 125 ms 13136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 19796 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2392 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 2384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 2652 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 -