제출 #102190

#제출 시각아이디문제언어결과실행 시간메모리
102190rubenvdBall Machine (BOI13_ballmachine)C++14
0 / 100
1089 ms11456 KiB
#include <bits/stdc++.h>
using namespace std;
int par[100005], val[100005];
bool filled[100005];
vector<int> child[100005];


int dfs( int u ){
	int mini = 1e9;
	for( auto v : child[u] ){
		//cout << u << " " << v << endl;
		mini = min(dfs(v), mini);
	}
	val[u] = min(u, mini);
	
	if( mini != 1e9 )
		return mini;
	else
		return u;
}

int add( int u ){
	int in, mini = 1e9;
	for( auto v : child[u] ){
		if( val[v] < mini && !filled[v] ){
			in = v;
			mini = val[v];
		}
	}


	if( mini == 1e9 ){
		filled[u] = true;
		return u;
	}
	else
		return add(in);
}

int del( int u ){
	int in = par[u], cnt = 0;

	filled[u] = false;
	while( filled[in] ){
		filled[u] = true;
		u = par[u];
		cnt++;
		filled[in] = false;
		in = par[in];
	}
	return cnt;
}

int main(){
	int n, q, root, type, k;
	cin >> n >> q;
	memset(filled, false, sizeof filled);

	for( int i = 1; i <= n; ++i ){
		cin >> par[i];
		child[par[i]].push_back(i);
		if( par[i] == 0 )
			root = i;
	}
	child[0].push_back(1);
	par[1]=0;

	dfs(root);

	for( int i= 0; i < q; ++i ){
		cin >> type >> k;
		if( type == 1 ){
			int out;
			for( int i = 0; i < k; ++i ){
				out = add(root);
			}
			cout << out << endl;
		} else {
			cout << del(k) << endl;
		}
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

ballmachine.cpp: In function 'int add(int)':
ballmachine.cpp:33:13: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   filled[u] = true;
   ~~~~~~~~~~^~~~~~
ballmachine.cpp: In function 'int main()':
ballmachine.cpp:33:13: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   filled[u] = true;
   ~~~~~~~~~~^~~~~~
ballmachine.cpp:23:6: note: 'in' was declared here
  int in, mini = 1e9;
      ^~
ballmachine.cpp:68:5: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
  dfs(root);
  ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...