Submission #38192

# Submission time Handle Problem Language Result Execution time Memory
38192 2018-01-02T19:53:19 Z farmersrice Pipes (CEOI15_pipes) C++14
50 / 100
544 ms 13836 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 30013
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop

int n, m;
vector<short> adj[MAXN];
vector<pair<short, short>> answer;

short depth[MAXN], lowestAdjDepth[MAXN];

//returns subtree size
void solve(int current, int parent) {
	assert(depth[current] >= 1);

	lowestAdjDepth[current] = depth[current];

	//cout << "solving " << current << " lad dis " << lowestAdjDepth[current] << endl;
	bool t = false;
	for (int next : adj[current]) {
		if (next == parent && !t) {t = true; continue;}
 
		if (depth[next] >= 1) {
			lowestAdjDepth[current] = min(lowestAdjDepth[current], depth[next]);
		} else {
			//unvisited, let's go visit!
			depth[next] = depth[current] + 1;
 
			solve(next, current);
			lowestAdjDepth[current] = min(lowestAdjDepth[current], lowestAdjDepth[next]);

			//cout << "current is " << current << " lad next is " << lowestAdjDepth[next] << " depth current is " << depth[current] << endl;
			if (lowestAdjDepth[next] > depth[current]) {
				//the next node is in a biconnected component unaffected by current node
				answer.add(mp(current, next));
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;b--;

		adj[a].add(b);
		adj[b].add(a);
	}	

	for (int i = 0; i < n; i++) {
		if (depth[i] == 0) {
			depth[i] = 1;
			solve(i, -1);
		}
	}

	for (auto t : answer) {
		cout << t.first + 1 << ' ' << t.second + 1<< endl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1536 KB Output is correct
2 Correct 5 ms 1252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 5304 KB Output is correct
2 Correct 128 ms 4900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 7416 KB Output is correct
2 Correct 291 ms 9236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 544 ms 13836 KB Output is correct
2 Correct 388 ms 11780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -