Submission #527303

# Submission time Handle Problem Language Result Execution time Memory
527303 2022-02-17T05:49:25 Z siewjh Pipes (CEOI15_pipes) C++17
90 / 100
966 ms 18584 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
const int MAXN = 100'005;
vector<int> adjlist[MAXN];
int tvis[MAXN], lo[MAXN];
int cnt = 0;
void dfs(int x, int par) {
	tvis[x] = lo[x] = cnt++;
	bool vpar = 0;
	for (auto nxt : adjlist[x]) {
		if (nxt == par && !vpar) {
			vpar = 1;
			continue;
		}
		if (tvis[nxt] != INT_MAX) lo[x] = min(lo[x], tvis[nxt]);
		else {
			dfs(nxt, x);
			lo[x] = min(lo[x], lo[nxt]);
			if (lo[nxt] > tvis[x]) cout << nxt << ' ' << x << '\n';
		}
	}
}
int root(int a, vector<int>& par) {
	if (par[a] == -1) return a;
	else return par[a] = root(par[a], par);
}
void merge(int a, int b, vector<int>& par, vector<int> &rank) {
	if (rank[a] > rank[b]) swap(a, b); // b has higher rank
	par[a] = b;
	if (rank[a] == rank[b]) rank[b]++;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int nodes, edges; cin >> nodes >> edges;
	vector<int> par1(nodes + 1, -1), par2(nodes + 1, -1), rank1(nodes + 1, -1), rank2(nodes + 1, -1);
	for (int i = 0; i < edges; i++) {
		int a, b; cin >> a >> b;
		if (root(a, par1) != root(b, par1)) {
			merge(root(a, par1), root(b, par1), par1, rank1);
			adjlist[a].push_back(b);
			adjlist[b].push_back(a);
		}
		else if (root(a, par2) != root(b, par2)) {
			merge(root(a, par2), root(b, par2), par2, rank2);
			adjlist[a].push_back(b);
			adjlist[b].push_back(a);
		}
	}
	for (int i = 1; i <= nodes; i++) tvis[i] = INT_MAX;
	for (int i = 1; i <= nodes; i++)
		if (tvis[i] == INT_MAX)
			dfs(i, -1);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3148 KB Output is correct
2 Correct 4 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 3112 KB Output is correct
2 Correct 89 ms 2888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 3908 KB Output is correct
2 Correct 162 ms 3304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 6256 KB Output is correct
2 Correct 249 ms 11664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 319 ms 11924 KB Output is correct
2 Correct 283 ms 8220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 490 ms 13332 KB Output is correct
2 Correct 467 ms 10616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 697 ms 15800 KB Output is correct
2 Correct 614 ms 10564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 781 ms 15928 KB Output is correct
2 Correct 779 ms 10804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 966 ms 15776 KB Output is correct
2 Runtime error 938 ms 18584 KB Memory limit exceeded
3 Halted 0 ms 0 KB -