Artifact Content
Not logged in

Artifact ab7535f57aeca7371958307bde892b72a2ca49db


#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 <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class GogoXReimuHakurai { public:
	int solve(vector <string> choices)
	{
		set<int> fromSrc;
		{
			queue<int> q;
			q.push(0);
			fromSrc.insert(0);
			while( !q.empty() ) {
				int v = q.front();
				q.pop();
				for(int u=0; u<choices[v].size(); ++u)
					if( choices[v][u] == 'Y' && !fromSrc.count(u) )
						q.push(u), fromSrc.insert(u);
			}
		}
		set<int> toDest;
		{
			queue<int> q;
			q.push(choices.size()-1);
			toDest.insert(choices.size()-1);
			while( !q.empty() ) {
				int v = q.front();
				q.pop();
				for(int u=0; u<choices[v].size(); ++u)
					if( choices[u][v] == 'Y' && !toDest.count(u) )
						q.push(u), toDest.insert(u);
			}
		}
		set<int> valid;
		set_intersection(fromSrc.begin(), fromSrc.end(),
		                 toDest.begin(), toDest.end(),
						 inserter(valid, valid.begin()));
		int N = valid.size();
		int E = 0;
		for(int v=0; v<choices.size(); ++v) if(valid.count(v))
		for(int u=0; u<choices.size(); ++u) if(v!=u && valid.count(u))
			if( choices[v][u]=='Y' )
				++E;
		return N ? E - (N-2) : 0;
	}
};

// 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 int& Expected, const 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(_, GogoXReimuHakurai().solve(choices));}
int main(){

CASE(0)
	string choices_[] = {
"NYY",
"NNY",
"NNN"};
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = 2; 
END
CASE(1)
	string choices_[] = {
"NYNY",
"NNYY",
"NNNY",
"NNNN"};
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = 3; 
END
CASE(2)
	string choices_[] = {"NNY"
,"NNY"
,"NNN"};
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = 1; 
END
CASE(3)
	string choices_[] = {"NN"
,"NN"};
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = 0; 
END
/*
CASE(4)
	string choices_[] = ;
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = ; 
END
CASE(5)
	string choices_[] = ;
	  vector <string> choices(choices_, choices_+sizeof(choices_)/sizeof(*choices_)); 
	int _ = ; 
END
*/
}
// END CUT HERE