Submission #1034687

# Submission time Handle Problem Language Result Execution time Memory
1034687 2024-07-25T16:45:08 Z vjudge1 Pipes (CEOI15_pipes) C++17
40 / 100
703 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());


#pragma GCC optimize("O3,unroll-loops")


/**
 * Author: Lukas Polacek
 * Date: 2009-10-26
 * License: CC0
 * Source: folklore
 * Description: Disjoint-set data structure.
 * Time: $O(\alpha(N))$
 */
const int N = 100'010;
struct UF {
	int e[N];
	UF(int n)  {memset(e, -1, sizeof e);}
	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;
	}
};
UF d1(N+1), d2(N+1);
vt<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(auto 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;
	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);
		}
	}
	for(int i= 1;i<=n;i++) {
		if(!id[i])
			dfs(i, i);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3928 KB Output is correct
2 Correct 3 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 9220 KB Output is correct
2 Correct 72 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 13908 KB Output is correct
2 Correct 119 ms 15352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 179 ms 21844 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 223 ms 30800 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 369 ms 44304 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 474 ms 56916 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 586 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 703 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -