Artifact Content
Not logged in

Artifact 90be7959357bf00ff62979d2a9adf17f7c37f728


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;

class CellRemoval {
public:
	int cellsLeft(vector <int> parent, int deletedCell) 
	{
		vector<bool> dead(parent.size(), false);

		for(int i=0; i<parent.size(); ++i)
		{
			for(int p=i; p!=-1; p=parent[p], (p!=-1 ? dead[p]=true : 0) )
				if( p == deletedCell )
					dead[i] = true;
		}
		int cnt = 0;
		for(int i=0; i<dead.size(); ++i)
			if( !dead[i] )
				++cnt;
		return cnt;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }

template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
int verify_case(const int &Expected, const int &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } return 0;}

template<int N> struct Case_ { Case_(){start_time=clock();} };
char Test_(...);
int Test_(Case_<0>) {
	int parent_[] = {-1,0,0,1,1};
	  vector <int> parent(parent_, parent_+sizeof(parent_)/sizeof(*parent_)); 
	int deletedCell = 2; 
	int RetVal = 2; 
	return verify_case(RetVal, CellRemoval().cellsLeft(parent, deletedCell)); }
int Test_(Case_<1>) {
	int parent_[] = {-1,0,0,1,1};
	  vector <int> parent(parent_, parent_+sizeof(parent_)/sizeof(*parent_)); 
	int deletedCell = 1; 
	int RetVal = 1; 
	return verify_case(RetVal, CellRemoval().cellsLeft(parent, deletedCell)); }
int Test_(Case_<2>) {
	int parent_[] = {-1,0,0,1,1};
	  vector <int> parent(parent_, parent_+sizeof(parent_)/sizeof(*parent_)); 
	int deletedCell = 0; 
	int RetVal = 0; 
	return verify_case(RetVal, CellRemoval().cellsLeft(parent, deletedCell)); }
int Test_(Case_<3>) {
	int parent_[] = {-1,0,0,2,2,4,4,6,6};
	  vector <int> parent(parent_, parent_+sizeof(parent_)/sizeof(*parent_)); 
	int deletedCell = 4; 
	int RetVal = 2; 
	return verify_case(RetVal, CellRemoval().cellsLeft(parent, deletedCell)); }
int Test_(Case_<4>) {
	int parent_[] = {26,2,32,36,40,19,43,24,30,13,21,14,24,21,19,4,30,10,44,12,7,32,17,43,
 35,18,7,36,10,16,5,38,35,4,13,-1,16,26,1,12,2,5,18,40,1,17,38,44,14};
	  vector <int> parent(parent_, parent_+sizeof(parent_)/sizeof(*parent_)); 
	int deletedCell = 24; 
	int RetVal = 14; 
	return verify_case(RetVal, CellRemoval().cellsLeft(parent, deletedCell)); }

template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); }
template<>      void Run_<-1>() {}
int main() { Run_<0>(); }
// END CUT HERE