Artifact Content
Not logged in

Artifact a79c22b01124d1da364062ae5b13b2db92a06439


#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>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class TreeAndPathLength3 { public:
	vector <int> construct(int s)
	{
		if(s == 1) {
			int ans[] = {0, 1, 1, 2, 2, 3};
			return vector<int>(ans+0, ans+6);
		}

		// . - . - . - . -.-.
		//     n nodes   -.-.
		//               -.-.
		//               -.-.   k branches
		// =
		// (n-3) + k + k + k(k-1)

		int k=0;
		for(; k+k+k*(k-1)<=s; ++k) {}
		--k;
		int n = s - k - k - k*(k-1) + 3;

		vector<int> edges;
		for(int v=0; v<n-1; ++v) {
			edges.emplace_back(v);
			edges.emplace_back(v+1);
		}
		for(int u=0; u<k; ++u) {
			edges.emplace_back(n-1);
			edges.emplace_back(n+u);
			edges.emplace_back(n+u);
			edges.emplace_back(n+u+k);
		}
		return edges;
	}
};

// 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 vector <int>& Expected, const vector <int>& 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(_, TreeAndPathLength3().construct(s));}
int main(){

CASE(0)
	int s = 1; 
	int __[] = {0, 1, 1, 2, 2, 3 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int s = 2; 
	int __[] = {0, 1, 1, 2, 2, 3, 3, 4 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int s = 6; 
	int __[] = {0, 1, 1, 2, 0, 3, 3, 4, 0, 5, 5, 6 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int s = 8; 
	int __[] = {0, 1, 1, 2, 1, 3, 3, 4, 3, 5, 5, 6, 5, 7 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int s = 10000; 
	int __[] = {1};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(5)
	int s = ; 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE