Submission #784225

# Submission time Handle Problem Language Result Execution time Memory
784225 2023-07-15T21:36:13 Z NK_ Pipes (CEOI15_pipes) C++17
100 / 100
308 ms 14876 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back

template<class T> using V = vector<T>;

int d[10];
int read() {
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		ch = getchar();
	}
	int v = 0;
	while ('0' <= ch && ch <= '9') {
		v = v * 10 + (int) (ch - '0');
		ch = getchar();
	}
	return v;
}
 
void write(int x) {
	int len = 0;
	while (x > 0) {
		d[len++] = x % 10;
		x /= 10;
	}
	for (int i = len - 1; i >= 0; i--) {
		putchar('0' + d[i]);
	}
	if (len == 0) {
		putchar('0');
	}
	putchar('\n');
}

const int nax = 1e5+5;

struct DSU {
	int e[nax]; void init() { memset(e, -1, sizeof e); };
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
	bool unite(int x, int y) {
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y]; e[y] = x; return 1;
	}
};

V<int> adj[nax];
int low[nax], disc[nax], t = 0;
bitset<nax> vis;

void dfs(int u, int p = -1) {
	vis[u] = 1;
	disc[u] = low[u] = t++;
	bool twi = 0;
	for(auto &v : adj[u]) if (v != p || twi) {
		if (vis[v]) low[u] = min(low[u], disc[v]);
		else {
			dfs(v, u);
			low[u] = min(low[u], low[v]);
			if (low[v] > disc[u]) {
				cout << u + 1 << " " << v + 1 << nl;
			}
		}
	} else twi = 1;
}


int main() {
	cin.tie(0)->sync_with_stdio(0);

	int N = read(), M = read();
	DSU F, S; F.init(), S.init();

	int u, v;
	for(int e = 0; e < M; e++) {
		u = read() - 1, v = read() - 1;
		if (F.unite(u, v) || S.unite(u, v)) {
			// cout << u << " " << v << endl;
			adj[u].pb(v);
			adj[v].pb(u);
		}
	}

	for(int i = 0; i < N; i++) if (!vis[i]) dfs(i);

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3924 KB Output is correct
2 Correct 3 ms 3668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3840 KB Output is correct
2 Correct 24 ms 3600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 4480 KB Output is correct
2 Correct 45 ms 3944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 6076 KB Output is correct
2 Correct 74 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 11520 KB Output is correct
2 Correct 89 ms 7412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 12712 KB Output is correct
2 Correct 156 ms 9424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 214 ms 14876 KB Output is correct
2 Correct 200 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 14868 KB Output is correct
2 Correct 234 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 14272 KB Output is correct
2 Correct 292 ms 10960 KB Output is correct