Submission #54893

# Submission time Handle Problem Language Result Execution time Memory
54893 2018-07-05T09:08:23 Z 김세빈(#1509) Pipes (CEOI15_pipes) C++11
30 / 100
1789 ms 7948 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;

vector <int> V[101010];
int P[101010], K[101010];
int R[101010], D[101010], S[101010];
bool chk[101010];
int n, m;

void reorder(int x, int p, int r, bool f)
{
	int i, c;
	
	D[p] = D[r] + 1; R[p] = x;
	c = K[p], K[p] = r;
	
	if(c != r) swap(f, chk[p]);
	
	if(chk[p]) P[p] = P[r];
	else P[p] = r;
	
	for(auto t: V[p]){
		if(t != r){
			if(t == c) reorder(x, t, p, f);
			else reorder(x, t, p, 0);
		}
	}
}

int color(int a, int b)
{
	if(a == b) return a;
	if(D[a] > D[b]) chk[a] = 1, P[a] = color(P[a], b);
	else chk[b] = 1, P[b] = color(a, P[b]);
}

int main()
{
	int i, a, b;
	
	scanf("%d%d", &n, &m);
	
	for(i=1;i<=n;i++){
		S[i] = 1;
		R[i] = i;
	}
	
	for(i=1;i<=m;i++){
		scanf("%d%d", &a, &b);
		if(R[a] != R[b]){
			if(S[R[a]] > S[R[b]]) swap(a, b);
			
			V[a].push_back(b);
			V[b].push_back(a);
			
			S[R[b]] += S[R[a]];
			reorder(R[b], a, b, 0);
		}
		else color(a, b);
	}
	
	for(i=1;i<=n;i++){
		if(R[i] != i && !chk[i]) printf("%d %d\n", i, K[i]);
	}
	
	return 0;
}

Compilation message

pipes.cpp: In function 'void reorder(int, int, int, bool)':
pipes.cpp:15:6: warning: unused variable 'i' [-Wunused-variable]
  int i, c;
      ^
pipes.cpp: In function 'int color(int, int)':
pipes.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
pipes.cpp: In function 'int main()':
pipes.cpp:44: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:52: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 4 ms 2688 KB Output is correct
2 Incorrect 4 ms 2688 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2944 KB Output is correct
2 Incorrect 8 ms 2944 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 134 ms 2816 KB Output is correct
2 Incorrect 120 ms 2816 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 214 ms 3200 KB Output is correct
2 Incorrect 249 ms 3240 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 383 ms 4008 KB Output is correct
2 Correct 308 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 6388 KB Output is correct
2 Incorrect 490 ms 6264 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 868 ms 6832 KB Output is correct
2 Correct 794 ms 6876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1121 ms 7892 KB Output is correct
2 Incorrect 1152 ms 7944 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1409 ms 7800 KB Output is correct
2 Incorrect 1287 ms 7948 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1789 ms 7524 KB Output is correct
2 Correct 1661 ms 7920 KB Output is correct