답안 #24677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24677 2017-06-11T15:47:18 Z Bruteforceman Pipes (CEOI15_pipes) C++11
100 / 100
1478 ms 13984 KB
#include "bits/stdc++.h"
using namespace std;

int *par;
int *bic;
vector <int> *g;
int *low, *disc;
bitset <100005> vis;
vector <int> l, r;

int root(int x, int *a) {
	if(a[x] == x) return x;
	return a[x] = root(a[x], a);
}
void join(int x, int y, int *a) {
	x = root(x, a);
	y = root(y, a);
	if(x != y) {
		a[x] = y;
	}
}

int tym;
void dfs(int x, int parent) {
	vis[x] = 1;
	low[x] = disc[x] = ++tym;
	bool see = false;
	for(auto i : g[x]) {
		if (!see && i == parent) {
			see = true;
			continue;
		}
		if(vis[i] == 0) {
			dfs(i, x);
			low[x] = min(low[x], low[i]);
			if(disc[x] < low[i]) {
				l.push_back(x);
				r.push_back(i);
			}
		} else if (vis[i] == 1) {
			low[x] = min(low[x], disc[i]);
		}
	}
}

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);

	par = new int [n + 5];
	bic = new int [n + 5];

	for(int i = 1; i <= n; i++) {
		par[i] = i;
		bic[i] = i;
	}
	for(int i = 1; i <= m; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		if(root(p, par) != root(q, par)) {
			join(p, q, par);
			l.push_back(p);
			r.push_back(q);
		} else if (root(q, bic) != root(p, bic)) {
			join(p, q, bic);
			l.push_back(p);
			r.push_back(q);
		}
	}
	delete par;
	delete bic;

	g = new vector <int> [n + 5];
	for(size_t i = 0; i < l.size(); i++) {
		g[l[i]].push_back(r[i]);
		g[r[i]].push_back(l[i]);
	}
	l.clear();
	r.clear();

	low = new int [n + 5];
	disc = new int [n + 5];

	for(int i = 1; i <= n; i++) {
		if(vis[i] == 0) {
			dfs(i, 0);
		}
	}	
	for(size_t i = 0; i < l.size(); i++) {
		printf("%d %d\n", l[i], r[i]);
	}
	delete low;
	delete disc;
	return 0;
}

Compilation message

pipes.cpp: In function 'int main(int, const char**)':
pipes.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p, &q);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 916 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 740 KB Output is correct
2 Correct 110 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 1632 KB Output is correct
2 Correct 229 ms 1252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 3552 KB Output is correct
2 Correct 274 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 468 ms 9868 KB Output is correct
2 Correct 428 ms 6920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 730 ms 11196 KB Output is correct
2 Correct 698 ms 8448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 986 ms 13872 KB Output is correct
2 Correct 961 ms 9988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1269 ms 13984 KB Output is correct
2 Correct 1166 ms 9904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1478 ms 13148 KB Output is correct
2 Correct 1374 ms 10596 KB Output is correct