답안 #97542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97542 2019-02-16T21:56:17 Z jasony123123 Pipes (CEOI15_pipes) C++11
20 / 100
1202 ms 11616 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <array>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}

const ll INF = 1e14;
/***********************CEOI 2015 D1 Pipes*****************************************/

template<int NSZ, int ESZ> struct BCC {
	int NN;
	v<int> adj[NSZ];
	int lo[NSZ], ind[NSZ], t = 0;

	void init(int n) {
		NN = n;
	}

	void addEdge(int a, int b) {
		adj[a].push_back(b), adj[b].push_back(a);
	}

	void findBridges() {
		fill(ind, ind + NN, -1);
		fill(lo, lo + NN, 0);
		FOR(i, 0, NN) if (ind[i] == -1)
			tarjan(i);
	}




	void tarjan(int cur, int par = -1) {
		ind[cur] = lo[cur] = t++;

		for (int nex : adj[cur]) {
			if (nex == par) continue;
			if (ind[nex] == -1) {
				tarjan(nex, cur);
				minn(lo[cur], lo[nex]);
				if (lo[nex] > ind[cur]) {
					cout << cur << " " << nex << "\n";
				}
			}
			else minn(lo[cur], ind[nex]);
		}
	}


};

template <int SZ> struct UnionFind {
	int par[SZ];

	void init(int NN) {
		FOR(i, 0, NN) par[i] = i;
	}

	int find(int x) {
		if (par[x] != x) par[x] = find(par[x]);
		return par[x];
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		par[y] = x;
		return true;
	}
};

int n, m;
UnionFind<100001> uf1, uf2;
BCC<100001, 200001> bcc;

int main() {
	io();
	cin >> n >> m;

	uf1.init(n + 1), uf2.init(n + 1);
	bcc.init(n + 1);
	FOR(i, 0, m) {
		int a, b; cin >> a >> b;
		if (uf1.unite(a, b) || uf2.unite(a, b)) {
			bcc.addEdge(a, b);
		}
	}
	bcc.findBridges();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Incorrect 4 ms 2688 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3072 KB Output is correct
2 Incorrect 8 ms 2944 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 3044 KB Output is correct
2 Incorrect 93 ms 2936 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 3592 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 4784 KB Output is correct
2 Correct 246 ms 4604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 432 ms 8992 KB Output is correct
2 Incorrect 355 ms 6904 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 9956 KB Output is correct
2 Incorrect 605 ms 8008 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 11608 KB Output is correct
2 Incorrect 821 ms 8692 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 1016 ms 11616 KB Output is correct
2 Incorrect 984 ms 8688 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 1202 ms 11112 KB Output is correct
2 Correct 1182 ms 9388 KB Output is correct