Artifact Content
Not logged in

Artifact 9236182d8721831100803e0a6efa6467256df5cf


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

class NetworkXMessageRecovery { public:
	string recover(vector <string> messages)
	{
		map< char, set<char> > prev;
		for(int i=0; i<messages.size(); ++i) {
			prev[messages[i][0]];
			for(int j=0; j+1<messages[i].size(); ++j)
				prev[messages[i][j+1]].insert(messages[i][j]);
		}

		string result;
		while( !prev.empty() )
		{
			set<char> cand;
			for(map< char,set<char> >::iterator it=prev.begin(); it!=prev.end(); ++it)
				if( it->second.empty() )
					cand.insert(it->first);
			char c = *cand.begin();
			result += c;
			for(map< char,set<char> >::iterator it=prev.begin(); it!=prev.end(); ++it)
				it->second.erase(c);
			prev.erase(c);
		}
		return result;
	}
};

// 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 string& Expected, const string& 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(_, NetworkXMessageRecovery().recover(messages));}
int main(){

CASE(0)
	string messages_[] = {"acd", "bce"};
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = "abcde"; 
END
CASE(1)
	string messages_[] = {"ed", "dc", "cb", "ba"};
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = "edcba"; 
END
CASE(2)
	string messages_[] = {"Fox", "Ciel", "FoxCiel"};
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = "FoxCiel"; 
END
CASE(3)
	string messages_[] = {"a", "A"};
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = "Aa"; 
END
/*
CASE(4)
	string messages_[] = ;
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = ; 
END
CASE(5)
	string messages_[] = ;
	  vector <string> messages(messages_, messages_+sizeof(messages_)/sizeof(*messages_)); 
	string _ = ; 
END
*/
}
// END CUT HERE