Submission #170315

# Submission time Handle Problem Language Result Execution time Memory
170315 2019-12-24T19:50:30 Z ngmh Pipes (CEOI15_pipes) C++11
40 / 100
473 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pi;

#define dep par1
#define low par2

int n, m, a, b, co, par1[100001], par2[100001];
vector<int> adj[100001];

inline int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) read_int() {
	int x = 0;
	char ch = getchar_unlocked();
	while (ch < '0' || ch > '9') ch = getchar_unlocked();
	while (ch >= '0' && ch <= '9'){
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
	return x;
}

int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) root(int *array, int x){
	if(array[x] == -1) return x;
	return array[x] = root(array, array[x]);
}

void __attribute__((optimize("Ofast"), target("arch=sandybridge"))) connect(int *array, int x, int y){
	array[root(array, x)] = root(array, y);
	adj[x].push_back(y);
	adj[y].push_back(x);
}

void __attribute__((optimize("Ofast"), target("arch=sandybridge"))) bridges(int x, int par){
	if(dep[x] != -1) return;
	dep[x] = low[x] = co++;
	int t = 0;
	for(auto it:adj[x]){
		if(it == par && t == 0){ t++; continue; }
		if(dep[it] != -1){
			if(low[it] > dep[x]) cout << x << " " << it << "\n";
			low[x] = min(low[x], low[it]);
			continue;
		}
		bridges(it, x);
		if(low[it] > dep[x]) cout << x << " " << it << "\n";
		low[x] = min(low[x], low[it]);
	}
}

int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	memset(par1, -1, sizeof(par1));
	memset(par2, -1, sizeof(par2));
	n = read_int(); m = read_int();
	for(int i = 0; i < m; i++){
		a = read_int(); b = read_int();
		if(a > b) swap(a, b);
		if(root(par1, a) != root(par1, b)) connect(par1, a, b);
		else if(root(par2, a) != root(par2, b)) connect(par2, a, b);
	}
	memset(par1, -1, sizeof(par1));
	memset(par2, -1, sizeof(par2));
	for(int i = 1; i <= n; i++) bridges(i, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3940 KB Output is correct
2 Correct 7 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 9208 KB Output is correct
2 Correct 34 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 13880 KB Output is correct
2 Correct 63 ms 15304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 21752 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 209 ms 30300 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 279 ms 43740 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 382 ms 56140 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 420 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 473 ms 65536 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -