Artifact Content
Not logged in

Artifact 1342371824ba4cfe1c135afe573238347c913269


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

LL comb(LL n, LL k)
{
	k = min(k, n-k);

	LL c = 1;
	for(LL i=0; i<k; ++i)
		c *= n-i, c /= i+1;
	return c;
}

class PenguinSledding { public:
	long long countDesigns(int numCheckpoints, vector <int> checkpoint1, vector <int> checkpoint2)
	{
		LL zero = 1;
		LL one = checkpoint1.size();
		LL star = 0;
		LL triangle = 0;

		for(int center=1; center<=numCheckpoints; ++center) {
			int leaf = 0;
			for(int i=0; i<checkpoint1.size(); ++i)
				if(checkpoint1[i] == center)
					++leaf;
				else if(checkpoint2[i] == center)
					++leaf;
			for(int k=2; k<=leaf; ++k)
				star += comb(leaf, k);
		}

		set< pair<int,int> > conn;
		for(int i=0; i<checkpoint1.size(); ++i) {
			conn.insert(make_pair(checkpoint1[i], checkpoint2[i]));
			conn.insert(make_pair(checkpoint2[i], checkpoint1[i]));
		}
		for(int a=1; a<=numCheckpoints; ++a)
		for(int b=a+1; b<=numCheckpoints; ++b)
		for(int c=b+1; c<=numCheckpoints; ++c)
			if(conn.count(make_pair(a,b)) && conn.count(make_pair(b,c)) && conn.count(make_pair(c,a)))
				++triangle;

		return zero + one + star + triangle;
	}
};

// 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> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, PenguinSledding().countDesigns(numCheckpoints, checkpoint1, checkpoint2));}
int main(){

CASE(0)
	int numCheckpoints = 2; 
	int checkpoint1_[] = {1};
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = {2};
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = 2LL; 
END
CASE(1)
	int numCheckpoints = 4; 
	int checkpoint1_[] = {1,2,3};
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = {2,3,4};
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = 6LL; 
END
CASE(2)
	int numCheckpoints = 6; 
	int checkpoint1_[] = {1,3,6};
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = {2,4,4};
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = 5LL; 
END
CASE(3)
	int numCheckpoints = 50; 
	int checkpoint1_[] = {40, 40, 40, 40, 40, 40, 40, 40, 
 40, 40, 40, 40, 50, 40, 40, 40, 
 23, 4, 24, 40, 22, 40, 8, 40, 40,
 40, 34, 21, 40, 40, 38, 40, 40, 
 40, 40, 40, 28, 40, 40, 40, 40, 
 46, 13, 40, 40, 40, 47, 40, 40};
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = {45, 42, 20, 48, 12, 32, 25, 10, 
 26, 39, 16, 2, 19, 43, 37, 17, 
 19, 19, 19, 18, 19, 27, 19, 29, 
 11, 36, 19, 19, 1, 41, 19, 35, 
 14, 33, 49, 3, 19, 7, 5, 19, 31, 
 19, 19, 6, 9, 15, 19, 44, 30};
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = 68719493118LL; 
END
CASE(4)
	int numCheckpoints = 36; 
	int checkpoint1_[] = {13, 24, 24, 20, 31, 16, 10, 36, 34, 32, 
 28, 5, 20, 29, 23, 2, 14, 4, 9, 5, 19, 
 21, 8, 1, 26, 27, 25, 15, 22, 30, 30, 
 6, 11, 7, 2, 35, 13, 29, 4, 12, 33, 18, 
 13, 14, 17, 35, 3};
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = {10, 15, 27, 1, 29, 11, 5, 18, 33, 1, 9,
 2, 31, 6, 19, 10, 33, 18, 6, 27, 3, 22,
 4, 12, 31, 30, 34, 16, 7, 24, 3, 28, 15,
 21, 22, 8, 26, 20, 14, 32, 25, 17, 35,
 8, 36, 26, 23};
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = 162LL; 
END
/*
CASE(5)
	int numCheckpoints = ; 
	int checkpoint1_[] = ;
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = ;
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = LL; 
END
CASE(6)
	int numCheckpoints = ; 
	int checkpoint1_[] = ;
	  vector <int> checkpoint1(checkpoint1_, checkpoint1_+sizeof(checkpoint1_)/sizeof(*checkpoint1_)); 
	int checkpoint2_[] = ;
	  vector <int> checkpoint2(checkpoint2_, checkpoint2_+sizeof(checkpoint2_)/sizeof(*checkpoint2_)); 
	long long _ = LL; 
END
*/
}
// END CUT HERE