답안 #27165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27165 2017-07-09T17:51:33 Z bill_kondo Pipes (CEOI15_pipes) C++14
100 / 100
1604 ms 15888 KB
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define debug(args...) fprintf(stderr,args)
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define REP(i,a,b) for(int i = a; i >= b; --i)

typedef long long ll;
typedef pair<int,int>pii;

const int maxn = 1e5 + 10;

int n, m;

struct dsu{
	vector<int>par,sz;

	void init(){
		par.resize(n+1);
		sz.resize(n+1);
		FOR(i,1,n)
			par[i] = i;
	}

	int root(int v){
		return par[v] = (par[v] == v ? v : root(par[v]));
	}

	void merge(int x, int y){
		x = root(x);
		y = root(y);
		if(x == y) return;
		par[y] = x;
	}

	void end(){
		par.clear();
		sz.clear();
	}

} T[2];

vector<pii>adj[maxn];

int cnt, cur;
vector<int>h, low;
vector<bool>mrk;

void dfs(int v, int par){
	mrk[v] = true;
	low[v] = h[v] = ++cur;
	for(int i = 0; i < adj[v].size(); ++i){
		int u = adj[v][i].first;
		int e = adj[v][i].second;
		if(e == par) continue;
		if(!mrk[u]){
			dfs(u,e);
			low[v] = min(low[v],low[u]);
			if(low[u] > h[v]) printf("%d %d\n",u,v);
		}
		else low[v] = min(low[v],h[u]);
	}
}

void tarjan(){
	h.resize(n+1);
	low.resize(n+1);
	mrk.resize(n+1);
	FOR(i,1,n)
		if(!mrk[i])
			dfs(i,-1);
}

int main(){
	scanf("%d%d",&n,&m);

	T[0].init();
	T[1].init();

	FOR(i,1,m){
		int a, b;
		scanf("%d%d",&a,&b);
		if(T[0].root(a) != T[0].root(b)){	
			++cnt;
			adj[a].pb(pii(b,cnt));
			adj[b].pb(pii(a,cnt));
			T[0].merge(a,b);
		}
		else if(T[1].root(a) != T[1].root(b)){
			++cnt;
			adj[a].pb(pii(b,cnt));
			adj[b].pb(pii(a,cnt));
			T[1].merge(a,b);
		}
	}

	T[0].end();
	T[1].end();

	tarjan();
	return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < adj[v].size(); ++i){
                 ~~^~~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:76: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:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3200 KB Output is correct
2 Correct 8 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 3132 KB Output is correct
2 Correct 115 ms 2988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 3952 KB Output is correct
2 Correct 233 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 344 ms 5804 KB Output is correct
2 Correct 309 ms 5348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 11860 KB Output is correct
2 Correct 475 ms 8952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 809 ms 13316 KB Output is correct
2 Correct 722 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1042 ms 15772 KB Output is correct
2 Correct 993 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1303 ms 15888 KB Output is correct
2 Correct 1216 ms 11696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1604 ms 15116 KB Output is correct
2 Correct 1529 ms 11788 KB Output is correct