#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>

using namespace std;
//usage color N M graph Output
int main(int argc, char *argv[])
{
	string Graph, LPGraph;
	string::size_type pos1, pos2, pos3;
	string src, des;
	ifstream graph;
	ofstream lpgraph;

	int Colors;
	int i,j;

	if (argc != 4)	
	{
		cout<<"Usage: " << argv[0] << " <ncolors>  <graphFile> <output>"<<endl;
		return 0;
	}
	Colors = atoi(argv[1]);
	Graph.assign(argv[2]);


	if(argc>3) 
		LPGraph.assign(argv[3]);
	// 
	graph.open(Graph.c_str(), ios::in);
	lpgraph.open(LPGraph.c_str(), ios::trunc);
	
	lpgraph << "##function (vertex) color clr." << endl;

	for(i=0;i<Colors;i++)
		lpgraph << "color(" << i << ")." << endl;

	while(getline(graph, Graph)) 
	{
		lpgraph << Graph.c_str() << endl;
		if (Graph.find("arc") == string::npos) continue;
		pos1 = Graph.find("(");
		pos2 = Graph.find(",");
		pos3 = Graph.find(")");
		lpgraph << ":- clr(" << Graph.substr(pos1+1, pos2-pos1-1) << ") == clr(" << Graph.substr(pos2+1,pos3-pos2-1) << ")." << endl;

	}

	graph.close();
	lpgraph.close();

	return 0;
}

