Submission #1081736

# Submission time Handle Problem Language Result Execution time Memory
1081736 2024-08-30T09:49:17 Z Elias Pipes (CEOI15_pipes) C++17
50 / 100
759 ms 49208 KB
#include <bits/stdc++.h>

using namespace std;

struct UnionFind
{
	vector<int> parent;

	UnionFind(int n)
	{
		parent.resize(n);
		for (int i = 0; i < n; i++)
			parent[i] = i;
	}

	int find(int a)
	{
		if (parent[a] == a)
			return a;
		return parent[a] = find(parent[a]);
	}

	bool unite(int a, int b)
	{
		a = find(a);
		b = find(b);

		if (a == b)
			return false;

		parent[a] = b;
		return true;
	}
};

vector<vector<pair<int, int>>> adj;

vector<int> low, pre;

int timer = 0;

void dfs_bridges(int i, int p)
{
	pre[i] = low[i] = timer++;

	for (auto [c, j] : adj[i])
	{
		if (j == p)
			continue;

		if (pre[c] != -1)
		{
			low[i] = min(low[i], pre[c]);
		}
		else
		{
			dfs_bridges(c, j);

			if (low[c] > pre[i])
			{
				cout << i + 1 << " " << c + 1 << "\n";
			}

			low[i] = min(low[i], low[c]);
		}
	}
}

signed main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	adj.resize(n);
	pre = low = vector<int>(n, -1);

	UnionFind comp(n);
	UnionFind bridge(n);

	int edge_index = 0;

	while (m--)
	{
		int a, b;
		cin >> a >> b;

		a--, b--;

		if (comp.unite(a, b))
		{
			adj[a].push_back({b, edge_index});
			adj[b].push_back({a, edge_index});
			edge_index++;
		}
		else if (bridge.unite(a, b))
		{
			adj[a].push_back({b, edge_index});
			adj[b].push_back({a, edge_index});
			edge_index++;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (pre[i] == -1)
			dfs_bridges(i, -1);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1112 KB Output is correct
2 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 3884 KB Output is correct
2 Correct 59 ms 3484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 7252 KB Output is correct
2 Correct 135 ms 7236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 12372 KB Output is correct
2 Correct 188 ms 10552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 270 ms 21396 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 479 ms 29392 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 600 ms 37672 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 691 ms 43088 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 759 ms 49208 KB Memory limit exceeded
2 Halted 0 ms 0 KB -