Artifact Content
Not logged in

Artifact f7dc591b0d55c29728f99af0c75711189ab30b2a


#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 CliqueGraph { public:
	long long calcSum(int N, vector <int> V, vector <int> sizes)
	{
		vector<vector<int>> v2c(N);
		vector<vector<int>> c2v(sizes.size());
		for(int s=0,i=0; i<sizes.size(); ++i) {
			int e = s+sizes[i];
			for(int k=s; k<e; ++k) {
				v2c[V[k]].push_back(i);
				c2v[i].push_back(V[k]);
			}
			s = e;
		}

		LL total = 0;
		for(int v=0; v<N; ++v)
			total += calc(v, v2c, c2v);
		return total / 2;
	}

	LL calc(int S, const vector<vector<int>>& v2c, const vector<vector<int>>& c2v)
	{
		const int V = v2c.size(), C = c2v.size();
		vector<int>  v_d(V, -1);
		vector<bool> c_visited(C, false);
		vector<int> q(1, S);
		v_d[S] = 0;
		for(int step=1; !q.empty(); step++) {
			vector<int> cq;
			for(int v: q)
				for(int c: v2c[v]) if(!c_visited[c])
					cq.push_back(c), c_visited[c]=true;
			vector<int> q2;
			for(int c: cq)
				for(int v: c2v[c]) if(v_d[v]<0)
					q2.push_back(v), v_d[v]=step;
			q = std::move(q2);
		}

		LL total = 0;
		for(int d: v_d)
			total += d;
		return total;
	}
};

// 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(_, CliqueGraph().calcSum(N, V, sizes));}
int main(){

CASE(0)
	int N = 4; 
	int V_[] = {0,1,2,0,3};
	  vector <int> V(V_, V_+sizeof(V_)/sizeof(*V_)); 
	int sizes_[] = {3,2};
	  vector <int> sizes(sizes_, sizes_+sizeof(sizes_)/sizeof(*sizes_)); 
	long long _ = 8LL; 
END
CASE(1)
	int N = 5; 
	int V_[] = {0,1,2,3,1,2,4};
	  vector <int> V(V_, V_+sizeof(V_)/sizeof(*V_)); 
	int sizes_[] = {4,3};
	  vector <int> sizes(sizes_, sizes_+sizeof(sizes_)/sizeof(*sizes_)); 
	long long _ = 12LL; 
END
CASE(2)
	int N = 15; 
	int V_[] = {1,3,5,7,9,11,13,0
,2,3,6,7,10,11,14,0
,4,5,6,7,12,13,14,0
,8,9,10,11,12,13,14,0};
	  vector <int> V(V_, V_+sizeof(V_)/sizeof(*V_)); 
	int sizes_[] = {8,8,8,8};
	  vector <int> sizes(sizes_, sizes_+sizeof(sizes_)/sizeof(*sizes_)); 
	long long _ = 130LL; 
END
/*
CASE(3)
	int N = ; 
	int V_[] = ;
	  vector <int> V(V_, V_+sizeof(V_)/sizeof(*V_)); 
	int sizes_[] = ;
	  vector <int> sizes(sizes_, sizes_+sizeof(sizes_)/sizeof(*sizes_)); 
	long long _ = LL; 
END
CASE(4)
	int N = ; 
	int V_[] = ;
	  vector <int> V(V_, V_+sizeof(V_)/sizeof(*V_)); 
	int sizes_[] = ;
	  vector <int> sizes(sizes_, sizes_+sizeof(sizes_)/sizeof(*sizes_)); 
	long long _ = LL; 
END
*/
}
// END CUT HERE