Submission #1034673

# Submission time Handle Problem Language Result Execution time Memory
1034673 2024-07-25T16:34:13 Z vjudge1 Pipes (CEOI15_pipes) C++17
0 / 100
759 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define vt vector
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T> bool chmin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool chmax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());


/**
 * Author: Lukas Polacek
 * Date: 2009-10-26
 * License: CC0
 * Source: folklore
 * Description: Disjoint-set data structure.
 * Time: $O(\alpha(N))$
 */

struct UF {
	vi e;
	UF(int n) : e(n, -1) {}
	bool sameSet(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	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;
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	int n, m;
	cin >> n >> m;
	vt<pii> e;
	int u, v;
	UF d1(n+1), d2(n+1);
	vt<vt<int>> g(n+1);
	rep(i, 0, m) {
		cin >> u >> v;
		if(d1.join(u, v)) {
			g[u].pb(v);
			g[v].pb(u);
		} else if(d2.join(u, v)) {
			g[u].pb(v);
			g[v].pb(u);
		}
	}
	vt<int> low(n+1), id(n+1);
	int timer=0;
	bool ck=0;
	auto dfs = [&](int at, int par, auto &&self) -> void {
		ck=0;
		id[at]=low[at]=++timer;
		for(auto to:g[at]) {
			if(to == par and ck==0) {
				ck=1;
				continue;
			}
			if(id[to]) {
				low[at]=min(low[at], id[to]);		
			} else {
				self(to, at, self);
				low[at]=min(low[at], low[to]);
			}
		}
		if(low[at] == id[at] and at!=par) {
			cout << at << " " << par << "\n";
		}
	};
	for(int i= 1;i<=n;i++) {
		if(!id[i])
			dfs(i, i, dfs);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1116 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6208 KB Output is correct
2 Incorrect 60 ms 6052 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 11344 KB Output is correct
2 Incorrect 115 ms 12400 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 169 ms 19796 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 30556 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 361 ms 44652 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 502 ms 57964 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 676 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 759 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -