using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static SortedSet<SortedSet<int>> independentSets = new SortedSet<SortedSet<int>>(new ComparerForSets());
static SortedSet<SortedSet<int>> maximalIndependentSets = new SortedSet<SortedSet<int>>(new ComparerForSets());
static Dictionary<Tuple<int, int>, int> edges = new Dictionary<Tuple<int, int>, int>();
static List<int> vertices = new List<int>();
static void Main()
{
int V = 3, E = 0;
for (int i = 1; i <= V; i++)
vertices.Add(i);
List<Tuple<int, int>> inputEdges = new List<Tuple<int, int>>();
Tuple<int, int> edge;
for (int i = 0; i < E; i++)
{
Console.WriteLine(i);
edge = Tuple.Create(inputEdges[i].Item1, inputEdges[i].Item2);
edges[edge] = 1;
int t = edge.Item1;
edge = Tuple.Create(edge.Item2, t);
edges[edge] = 1;
}
SortedSet<int> tempSolutionSet = new SortedSet<int>();
findAllIndependentSets(1, V, tempSolutionSet);
printAllIndependentSets();
printMaximalIndependentSets();
}
static void printAllIndependentSets()
{
foreach (var iter in independentSets)
{
Console.Write("{ ");
foreach (var iter2 in iter)
{
Console.Write(iter2 + " ");
}
Console.Write("}");
}
Console.WriteLine();
}
static void printMaximalIndependentSets()
{
int maxCount = 0;
int localCount = 0;
foreach (var iter in independentSets)
{
localCount = 0;
foreach (var iter2 in iter)
{
localCount++;
}
if (localCount > maxCount)
maxCount = localCount;
}
foreach (var iter in independentSets)
{
localCount = 0;
SortedSet<int> tempMaximalSet = new SortedSet<int>();
foreach (var iter2 in iter)
{
localCount++;
tempMaximalSet.Add(iter2);
}
if (localCount == maxCount)
maximalIndependentSets.Add(tempMaximalSet);
}
foreach (var iter in maximalIndependentSets)
{
Console.Write("{ ");
foreach (var iter2 in iter)
{
Console.Write(iter2 + " ");
}
Console.Write("}");
}
Console.WriteLine();
}
static bool isSafeForIndependentSet(int vertex, SortedSet<int> tempSolutionSet)
{
foreach (var iter in tempSolutionSet)
{
if (edges.ContainsKey(Tuple.Create(iter, vertex)))
{
return false;
}
}
return true;
}
static void findAllIndependentSets(int currV, int setSize, SortedSet<int> tempSolutionSet)
{
for (int i = currV; i <= setSize; i++)
{
if (isSafeForIndependentSet(vertices[i - 1], tempSolutionSet))
{
tempSolutionSet.Add(vertices[i - 1]);
findAllIndependentSets(i + 1, setSize, new SortedSet<int>(tempSolutionSet));
tempSolutionSet.Remove(vertices[i - 1]);
}
}
independentSets.Add(new SortedSet<int>(tempSolutionSet));
}
}
public class ComparerForSets : IComparer<SortedSet<int>>
{
public int Compare(SortedSet<int> x, SortedSet<int> y)
{
if (x.Count != y.Count)
return x.Count.CompareTo(y.Count);
return String.Join(",", x).CompareTo(String.Join(",", y));
}
}