Submission #27167

# Submission time Handle Problem Language Result Execution time Memory
27167 2017-07-09T17:55:00 Z bill_kondo Pipes (CEOI15_pipes) C++14
100 / 100
1566 ms 14432 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;

	void init(){
		par.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();
		par.shrink_to_fit();
	}

} T[2];

vector<pii>adj[maxn];

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

void dfs(int v, int par){
	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(h[u] == -1){
			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);
	FOR(i,1,n) h[i] = -1;
	FOR(i,1,n)
		if(h[i] == -1)
			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:50: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:73: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:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3200 KB Output is correct
2 Correct 8 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 3108 KB Output is correct
2 Correct 118 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 3832 KB Output is correct
2 Correct 246 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 5364 KB Output is correct
2 Correct 315 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 10824 KB Output is correct
2 Correct 450 ms 8020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 818 ms 12048 KB Output is correct
2 Correct 785 ms 8804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1130 ms 14432 KB Output is correct
2 Correct 1012 ms 10152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1281 ms 14224 KB Output is correct
2 Correct 1303 ms 10196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1566 ms 13632 KB Output is correct
2 Correct 1492 ms 10404 KB Output is correct