답안 #54897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54897 2018-07-05T09:11:33 Z 김세빈(#1509) Pipes (CEOI15_pipes) C++11
100 / 100
1788 ms 8132 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;
	bool f2;
	
	D[p] = D[r] + 1; R[p] = x;
	c = K[p], K[p] = r;
	
	if(c != r) f2 = chk[p], chk[p] = f;
	
	if(chk[p]) P[p] = P[r];
	else P[p] = p;
	
	for(auto t: V[p]){
		if(t != r){
			if(t == c) reorder(x, t, p, f2);
			else reorder(x, t, p, 0);
		}
	}
	
	if(P[p] == p) P[p] = r;
}

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:41:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
pipes.cpp: In function 'int main()':
pipes.cpp:47: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:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp: In function 'void reorder(int, int, int, bool)':
pipes.cpp:28:22: warning: 'f2' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(t == c) reorder(x, t, p, f2);
               ~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2988 KB Output is correct
2 Correct 7 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 2944 KB Output is correct
2 Correct 118 ms 2932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 3200 KB Output is correct
2 Correct 243 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 348 ms 3888 KB Output is correct
2 Correct 307 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 6368 KB Output is correct
2 Correct 441 ms 6392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 769 ms 6896 KB Output is correct
2 Correct 768 ms 6912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1012 ms 7908 KB Output is correct
2 Correct 1008 ms 7936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1275 ms 7880 KB Output is correct
2 Correct 1226 ms 7928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1788 ms 7672 KB Output is correct
2 Correct 1552 ms 8132 KB Output is correct