import java.io.*;
import java.util.*;

public class Relation
{
	/**
	 * Empty an existing relation, allocates memory for a relation 
	 * on a set of size n
	 */
	private void init_relation(int n)
	{
	
	}
	
	/**
	 * The default constructor.  Constructs a relation on the empty set.
	 */
	public Relation()
	{
	
	}
	
	/**
	 * Constructor that generates an empty relation on a set of size n
	 * A = {a_0, a_1, ..., a_n-1}
	 * Note that we will be indexing from 0 to n-1
	 */
	public Relation(int n)
	{
	
	}
	
	/**
	 * The copy constructor.
	 */
	public Relation(Relation S)
	{
		if(this != S)
		{
			
		}
	}
	
	/**
	 * This should return n, the number of elements in the set the relation
	 * is defined on (i.e. *not* the number of valid relations)
	 */
	public int setSize()
	{
		return 0;
	}
	
	public boolean isReflexive()
	{
		return false;
	}
	
	public boolean isSymmetric()
	{
		return false;
	}
	
	public boolean isAsymmetric()
	{
		return false;
	}
	
	public boolean isAntisymmetric()
	{
		return false;
	}
	
	public boolean isTransitive()
	{
		return false;
	}
	
	public boolean isPartialOrder()
	{
		return false;
	}
	
	public boolean isEquivalenceRelation()
	{
		return false;
	}
	
	/**
	 * This should return true if a_i is related to a_j and false otherwise
	 * including if it is out of range.
	 * 0 <= i,j <= n-1
	 */
	public boolean isRelated(int i, int j)
	{
		return false;
	}
	
	/**
	 * This makes a_i related to a_j they are not already
	 * 0 <= i,j <= n-1
	 */
	public void addRelation(int i, int j)
	{
		
	}
	
	/**
	 * This takes away the relation between a_i and a_j if they are
	 */
	public void deleteRelation(int i, int j)
	{
		
	}
	
	/**
	 * This prints the relation to stdout
	 *
	 * This function has been implemented for you                
	 * this function uses row-major form, you may change it if you wish, but
	 * it looks pretty already.
	 */
	public void print()
	{
		System.out.println("");
		if(setSize() == 0)
		{
			System.out.println("[empty]");
		}
		else
		{
			for(int i=0; i < setSize(); i++)
			{
				System.out.print("[ ");
				for(int j=0; j < setSize(); j++)
				{
					System.out.print(isRelated(i,j) + " ");
				}
				System.out.println("]");
			}
		}
	}
	
	/**
	 *-----------------------------------------------------------------------
	 * This method has been done for you, but you will need to implement    
	 * a similar method for an output function
	 * The format of the flat file is:                      
	 *      n                           
	 *      0 (list)
	 *      1 (list)
	 *       ...
	 *      n-1 (list)
	 *
	 * where :
	 * 'n' is the size of the set (number of elements) which is followed by n lines
	 * each line starts with an integer a representing a unique element in the set, 
	 * {a_0, a_1, a_2, ..., a_n-1}
	 * which is followed by a list of integers between 0 and n-1 that a_i is related to
	 *
	 * Example: the file
	 * 5
	 * 0 0 1 2
	 * 1 3 1
	 * 2 3 4
	 * 3 3 4
	 * 4  
	 * represents the relation {(0,0), (0,1), (0,2), (1,1), (1,3), (2,3), (2,4), (3,3), (3,4)}
	 *
	 * This function has been implemented for you
	 *
	 * @param in The input to read from (Pass System.in if you want to read from the console)
	 */
	public void readIn(java.io.InputStream in)
	{
		Scanner scanner = new Scanner(in);
		
		int n;
		int temp_1;
		int temp_2;

		String lineText = scanner.nextLine();
		Scanner line = new Scanner(lineText);
		
		n = line.nextInt();
		this.init_relation(n);	//empties any pervious relation, allocates enough memory

		while(scanner.hasNext())
		{
			lineText = scanner.nextLine();
			line = new Scanner(lineText);
			
			temp_1 = line.nextInt();
			//now we read the rest of the line
			while (line.hasNext())
			{
				temp_2 = line.nextInt();
				this.addRelation(temp_1, temp_2);
			}
		}
	}
	
	/**
	 *-----------------------------------------------------------------------
	 * Similar to the read method above, but it takes an argument:
	 * the filename, so the details, like the filestreams, etc,         
	 * are left to the class.                       
	 * So if R is of type relation, a user can do:               
	 *      R.read("blah").                         
	 * and it will read a relation in from file "blah". 
	 *
	 * This function has been implemented for you
	 */
	public void read(String thefile) throws IOException
	{
		File infile = new File(thefile);
		FileInputStream infileStream = new FileInputStream(infile);
		this.readIn(infileStream);
		infileStream.close();
	}
	
	/**
	 *-----------------------------------------------------------------------
	 * Write a relation to a file in the same format as 'read' above.
	 *
	 * @param out Where to output to (Pass System.out if you want to print to the console)
	 */
	public void writeOut(java.io.PrintStream out)
	{
	
	}
	
	/**
	 *-----------------------------------------------------------------------
	 * the filename, so the details, like the filestreams, etc,         
	 * are left to the class. 
	 */
	public void write(String thefile) throws IOException
	{
		File out = new File(thefile);
		PrintStream outStream = new PrintStream(out);
		this.writeOut(outStream);
		outStream.close();
	}

	/**
	 *-----------------------------------------------------------------------
	 * The next three functions return a relation that is the 
         * closure of THIS relation
	 */
	public Relation ReflexiveClosure()
	{
		Relation R = new Relation(0);
		return R;
	}
	public Relation SymmetricClosure()
	{
		Relation R = new Relation(0);
		return R;
	}
	public Relation TransitiveClosure()
	{
		Relation R = new Relation(0);
		return R;
	}
	/**
	 *-----------------------------------------------------------------------
	 * The next two functions return a relation that is the 
         * union/intersection of THIS and relation B
	 */
	public Relation Union(Relation B)
	{
		Relation R = new Relation(0);
		return R;
	}
	public Relation Intersection(Relation B)
	{
		Relation R = new Relation(0);
		return R;
	}
}
