{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Unicyclic graph iterator -- arbitrary cycle size\n",
    "\n",
    "This code functions to produce all unicyclic graphs on $n$ vertices with a $c$-cycle using the function \"uni_c_graphs(n,c)\".\n",
    "\n",
    "It works by generating combinations of $c$ many rooted trees (which Sage already has code for -- see https://doc.sagemath.org/html/en/reference/combinat/sage/combinat/rooted_tree.html), connecting the roots in a cycle, and then eliminating duplicates of isomorphic graphs by the dihedral symmetry of a connected unicyclic graph. \n",
    "\n",
    "In conjunction with code for the DNC-algorithm of Aliste Prieto, De Mier, Orellana, and Zamora (which I did not write, so it is not included here), this code was useful for generating pairs of bipartite unicyclic graphs with the same chromatic symmetric function (CSF), described in my article with Johnston, Lawson, Orellana, Pan, and Sato. However, these examples are not so large that they could not be found with Sage's included CSF calculator."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[[[]]]], [[[], []]], [[], [[]]], [[], [], []]]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 5216 characters]",
      "text/plain": [
       "Graphics object consisting of 8 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 15172 characters]",
      "text/plain": [
       "Graphics object consisting of 8 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 5412 characters]",
      "text/plain": [
       "Graphics object consisting of 8 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 14816 characters]",
      "text/plain": [
       "Graphics object consisting of 8 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "## START BY GENERATING ROOTED TREES FROM SAGE's BUILT IN BRACKET REPRESENTATION\n",
    "\n",
    "import itertools\n",
    "\n",
    "def parse_brace_tree(tree_str):\n",
    "    #Parse the bracket representation of a rooted tree built into sage and return a Graph object.\n",
    "    G = Graph()\n",
    "    current_node = 0\n",
    "    node_stack = [current_node]\n",
    "    next_node = 1\n",
    "\n",
    "    # The trivial rooted tree gets handled separately\n",
    "    if len(str(tree_str))==2:\n",
    "        G.add_vertex(current_node)\n",
    "        return G\n",
    "\n",
    "    #skip the first and last symbol, a pair of matched brackets which represents the root\n",
    "    for char in tree_str[1:-1]:\n",
    "        if char == '[':\n",
    "            child_node = next_node\n",
    "            G.add_edge(node_stack[-1], child_node)\n",
    "            node_stack.append(child_node)\n",
    "            #\n",
    "            next_node += 1\n",
    "        elif char == ']':\n",
    "            node_stack.pop()\n",
    "        elif char == ',':\n",
    "            continue\n",
    "\n",
    "    return G\n",
    "\n",
    "# Get the collection of graphs associated to rooted tree strings\n",
    "def RootedTreeGraphs(n):\n",
    "    for rt in RootedTrees(n):\n",
    "        tree_st=str(rt)\n",
    "        graph=parse_brace_tree(tree_st)\n",
    "        graph.show()\n",
    "\n",
    "print([x for x in RootedTrees(4)])\n",
    "RootedTreeGraphs(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Optimization by avoiding graph isomorphism checking\n",
    "\n",
    "We can use the trick of taking unique tree size sequences up to dihedral symmetry on the actual sequences of trees as well. This way we know we only construct the same graph once and avoid having to do isomorphism checking!\n",
    "\n",
    "Interesting bit!: Python's min function can be called on the comma sequences of matched braces and sorts them lexicographically according to the values in unicode of the symbols '[', ',' and ']', allowing us to take a unique representative for each sequence of rooted trees which is equivalent to another by a cyclic rotation or a flip. This should speed up the code some, though as n gets large, CSF computation becomes by far the most expensive step."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[([[], []], [[], []]), ([[], []], [[[]]]), ([[[]]], [[[]]])]\n"
     ]
    }
   ],
   "source": [
    "# Function to generate all cyclic rotations of a given vector\n",
    "def cyclic_rotations(vector):\n",
    "    return [vector[i:] + vector[:i] for i in range(len(vector))]\n",
    "\n",
    "#\n",
    "def rotated_reflections(vector):\n",
    "    # Return the rotated reflections to get the rest of the D_4 group action on the unicyclic graph\n",
    "    return cyclic_rotations(vector[::-1])\n",
    "\n",
    "\n",
    "def uniq_reps(comps):\n",
    "    # Return unique representatives under cyclic rotation equivalence.\n",
    "    unique = set()\n",
    "    for vector in comps:\n",
    "        # Generate all cyclic rotations\n",
    "        equiv_class = cyclic_rotations(vector)+rotated_reflections(vector)\n",
    "        # Convert each rotation to a tuple and find the smallest rotation in lex order\n",
    "        min_rotation = min(tuple(rep) for rep in equiv_class)\n",
    "        # Add the smallest rotation to the set\n",
    "        unique.add(min_rotation)\n",
    "    return sorted(list(unique))\n",
    "\n",
    "def cyc_c_comps(n,c):\n",
    "    return uniq_reps(IntegerVectors(n,c))\n",
    "\n",
    "# make all the sequences of rooted trees with a specified number of vertices given by a weak composition alpha\n",
    "def bracket_tree_combos(alf):\n",
    "    tree_list=[list(RootedTrees(part+1)) for part in alf]\n",
    "    tcs=list(itertools.product(*tree_list))\n",
    "    return tcs\n",
    "\n",
    "print(uniq_reps((bracket_tree_combos([2,2]))))\n",
    "\n",
    "def tree_combos(alf):\n",
    "    return [[parse_brace_tree(str(tree)) for tree in tc ] for tc in uniq_reps(bracket_tree_combos(alf))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Need some helper functions to wedge product (i.e. disjoint union except for identification of a pair of vertices -- in this case, roots to cycle vertices) rooted trees onto a cycle in an orderly way."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 55692 characters]",
      "text/plain": [
       "Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 3 vertices dj_union Graph on 2 vertices: Graph on 11 vertices"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def dj_union(self, other,  immutable=None):  \n",
    "    '''improved graph disjoint union (modified from sage source)'''     \n",
    "    if (self._directed and not other._directed) or (not self._directed and other._directed):\n",
    "        raise TypeError('both arguments must be of the same class')\n",
    "\n",
    "    else:\n",
    "        if self.connected_components_number()==1:\n",
    "            r_self = {v: (0,v) for v in self}\n",
    "            r_other = {v: (self.connected_components_number(), v) for v in other}\n",
    "        else:\n",
    "            r_self = {v: v for v in self}\n",
    "            r_other = {v: (self.connected_components_number(), v) for v in other}\n",
    "    G = self.relabel(r_self, inplace=False).union(other.relabel(r_other, inplace=False), immutable=immutable)\n",
    "\n",
    "    a = self.name()\n",
    "    if not a:\n",
    "        a = self._repr_()\n",
    "    b = other.name()\n",
    "    if not b:\n",
    "        b = other._repr_()\n",
    "    G._name = '{} dj_union {}'.format(a, b)\n",
    "    return G\n",
    "\n",
    "# construct the unicyclic graph from a rooted tree sequence -- now graph vertices will be labelled as ordered pairs (i,j)\n",
    "def uni_c(tup):\n",
    "    djg=dj_union(tup[0],tup[1])\n",
    "    for i in range(2,len(tup)):\n",
    "        djg=dj_union(djg,tup[i])\n",
    "    #djg.show()\n",
    "    for i in range(len(tup)-1):\n",
    "        djg.add_edge([(i,0),(i+1,0)])#,(0,(0,(0,0)))])\n",
    "    djg.add_edge([(0,0),(len(tup)-1,0)])\n",
    "    return djg\n",
    "\n",
    "uni_c(tree_combos([2,2,1,0,1])[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ojo! The printout description is a little misleading above. There are a bunch of disjoint unions, but then they are all connected in a cycle.\n",
    "\n",
    "And now the final function that gen's isomorphism class representatives of unicyclic graphs with a 4-cycle "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 5 vertices,\n",
       " Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 5 vertices,\n",
       " Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices: Graph on 5 vertices,\n",
       " Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices: Graph on 5 vertices,\n",
       " Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex: Graph on 5 vertices]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# here we get all the isomorphism classes of unicyclic graphs with a c-cycle\n",
    "def uni_c_graphs(n,c,total=False):\n",
    "    #num of vertices among the trees\n",
    "    nv=n-c\n",
    "    gen_graphs = []     \n",
    "       \n",
    "    counter=0\n",
    "    for alf in cyc_c_comps(nv,c):\n",
    "        #print(alf)\n",
    "        new_graphs = [] \n",
    "        \n",
    "        for tc in tree_combos(alf):\n",
    "            counter+=1\n",
    "            g = uni_c(tc) \n",
    "            new_graphs.append( g ) \n",
    "        gen_graphs.extend( [Graph(gee) for gee in new_graphs] ) \n",
    "    if total:\n",
    "        print(f'{counter} graphs seen in generation process')\n",
    "    return gen_graphs\n",
    "\n",
    "#in case we just want all graphs as a list, regardless of cycle size\n",
    "def uni_graphs(n, total=False):\n",
    "    counter=0\n",
    "    graphs=[]\n",
    "    for c in range(3,n+1):\n",
    "        c_unis=uni_c_graphs(n,c)\n",
    "        graphs.extend(c_unis)\n",
    "        counter+=len(c_unis)\n",
    "    if total:\n",
    "        print(f'{counter} graphs seen in generation process')\n",
    "    return graphs\n",
    "\n",
    "uni_graphs(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Now the check for duplicates\n",
    "\n",
    "We create dictionaries that store the coefficient vectors output by CSF_tree as keys, and the graphs with the same coefficient vectors as values.\n",
    "If one of the key vectors has more than one associated graph, we print those graphs, else the CSF distinguishes the family of graphs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "\n",
    "def csf_DNC_classes(graphs):\n",
    "    # we make a dictionary CSFS and associated graphs\n",
    "    CSF_dict = defaultdict(list)\n",
    "\n",
    "    for gr in graphs:\n",
    "        # Get the set CSF\n",
    "        csf = gr.chromatic_symmetric_function()\n",
    "        #optional: show as you find \n",
    "        # (show graphs if we've already seen this csf)\n",
    "        #if csf in CSF_dict:\n",
    "        #    CSF_dict[csf][0].show()\n",
    "        #    gr.show()\n",
    "        #    print(csf)\n",
    "        CSF_dict[csf].append(gr)\n",
    "\n",
    "    return CSF_dict\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OK seems to be working, sample usage below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "Graph generation took 0.003259897232055664 seconds for 13 graphs\n",
      "CSF p[1, 1, 1, 1, 1, 1] - 6*p[2, 1, 1, 1, 1] + 6*p[2, 2, 1, 1] - p[2, 2, 2] + 8*p[3, 1, 1, 1] - 6*p[3, 2, 1] - 9*p[4, 1, 1] + 3*p[4, 2] + 6*p[5, 1] - 2*p[6]: [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 6 vertices, Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 2 vertices: Graph on 6 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 19288 characters]",
      "text/plain": [
       "Graphics object consisting of 13 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21000 characters]",
      "text/plain": [
       "Graphics object consisting of 13 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CSF checking took 0.04609990119934082 seconds\n"
     ]
    }
   ],
   "source": [
    "import time \n",
    "\n",
    "def uni_CSF_check(n,c=0,display=False):\n",
    "    start=time.time()\n",
    "    if c:\n",
    "        gc=uni_c_graphs(n,c)\n",
    "    else:\n",
    "        gc=uni_graphs(n)\n",
    "    gent=time.time()\n",
    "    print(f'Graph generation took {gent-start} seconds for {len(gc)} graphs')\n",
    "    grouped_graphs = csf_DNC_classes(gc)  \n",
    "\n",
    "    # Print the results\n",
    "    example=False\n",
    "    for fun, graphs in grouped_graphs.items():\n",
    "        if display:\n",
    "            for g in graphs:\n",
    "                g.show()\n",
    "                print(CSF_tree(g,display=True))\n",
    "        if len(graphs)>1:\n",
    "            example=True\n",
    "            print(f\"CSF {fun}: {graphs}\")\n",
    "            for g in graphs:\n",
    "                g.show()\n",
    "    dett=time.time()\n",
    "    print(f'CSF checking took {dett-gent} seconds')\n",
    "\n",
    "def uni_counter(n,c=0,display=False):\n",
    "    start=time.time()\n",
    "    if c:\n",
    "        gc=uni_c_graphs(n,c)\n",
    "    else:\n",
    "        gc=uni_graphs(n)\n",
    "    gent=time.time()\n",
    "    print(f'Graph generation took {gent-start} seconds for {len(gc)} graphs')\n",
    "#for n in range(12,16):\n",
    "#    print(f'n={n}')\n",
    "for n in range(6,7):\n",
    "    print(n)\n",
    "    uni_CSF_check(n)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generating unicyclic graphs with the same degree sequence\n",
    "\n",
    "In case anyone wanted to play with this...\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=5\n",
      "Graph generation took 0.0005044937133789062 seconds\n",
      "Deg sqce distinguishes uni-4-cyclic graphs on 5 vertices\n",
      "n=6\n",
      "Graph generation took 0.0010101795196533203 seconds\n",
      "Deg. Seq. (3, 3, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices: Graph on 6 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 2 vertices: Graph on 6 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23272 characters]",
      "text/plain": [
       "Graphics object consisting of 13 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 12636 characters]",
      "text/plain": [
       "Graphics object consisting of 13 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=7\n",
      "Graph generation took 0.0021936893463134766 seconds\n",
      "Deg. Seq. (3, 3, 2, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 7 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 7 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 7 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 16896 characters]",
      "text/plain": [
       "Graphics object consisting of 15 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19628 characters]",
      "text/plain": [
       "Graphics object consisting of 15 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 12932 characters]",
      "text/plain": [
       "Graphics object consisting of 15 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 3, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 7 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 7 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 22352 characters]",
      "text/plain": [
       "Graphics object consisting of 15 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22996 characters]",
      "text/plain": [
       "Graphics object consisting of 15 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=8\n",
      "Graph generation took 0.006197452545166016 seconds\n",
      "Deg. Seq. (4, 3, 2, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23172 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19956 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21936 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17788 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20660 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17316 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 2, 2, 2, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 18540 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24400 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (3, 3, 2, 2, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 20500 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22116 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 18452 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 14516 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 12948 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 10976 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (5, 3, 2, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28120 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21576 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (3, 3, 3, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 2 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 21260 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 18492 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21980 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23196 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 4, 2, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27208 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22556 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 3, 3, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 8 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 2 vertices: Graph on 8 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23792 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23468 characters]",
      "text/plain": [
       "Graphics object consisting of 17 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=9\n",
      "Graph generation took 0.015527725219726562 seconds\n",
      "Deg. Seq. (5, 3, 2, 2, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 4 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 4 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 21944 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 27528 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24680 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 18600 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 25220 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21496 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (5, 2, 2, 2, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 21424 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26920 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 4, 2, 2, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28520 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23748 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24988 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 3, 2, 2, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 4 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 4 vertices dj_union Graph on 1 vertex dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 25680 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17576 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 27104 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20916 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24780 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19584 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 30140 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17528 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19076 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24372 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21064 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 14624 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17376 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 2, 2, 2, 2, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 18644 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21064 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (3, 3, 3, 2, 2, 2, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices dj_union Graph on 2 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 19888 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17044 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23020 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24876 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24720 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17588 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26428 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22692 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19200 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 19036 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21888 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (3, 3, 2, 2, 2, 2, 2, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 6 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 17232 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20800 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24688 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22824 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 15208 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17496 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 14584 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 22560 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (6, 3, 2, 2, 1, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 31312 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21112 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 3, 3, 2, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 1 vertex dj_union Graph on 5 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices dj_union Graph on 2 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23732 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21736 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21144 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20344 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21024 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 23108 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 17884 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26204 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 20480 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 21344 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24680 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (5, 4, 2, 2, 1, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 1 vertex dj_union Graph on 4 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 25004 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 25356 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (5, 3, 3, 2, 1, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices dj_union Graph on 2 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23348 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 29876 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (3, 3, 3, 3, 2, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 4 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 4 vertices dj_union Graph on 2 vertices: Graph on 9 vertices, Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23184 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26188 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 24224 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deg. Seq. (4, 4, 3, 2, 1, 1, 1, 1, 1): [Graph on 1 vertex dj_union Graph on 2 vertices dj_union Graph on 3 vertices dj_union Graph on 3 vertices: Graph on 9 vertices, Graph on 1 vertex dj_union Graph on 3 vertices dj_union Graph on 2 vertices dj_union Graph on 3 vertices: Graph on 9 vertices]\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 24944 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 26172 characters]",
      "text/plain": [
       "Graphics object consisting of 19 graphics primitives"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from collections import defaultdict\n",
    "import time\n",
    "\n",
    "def DS_classes(graphs):\n",
    "    # we make a dictionary DS and associated graphs\n",
    "    DS_dict = defaultdict(list)\n",
    "\n",
    "    for gr in graphs:\n",
    "        # Get the set of DS's\n",
    "        ds = tuple(gr.degree_sequence())\n",
    "        #print(ds)\n",
    "        DS_dict[ds].append(gr)\n",
    "\n",
    "    return DS_dict\n",
    "\n",
    "import time \n",
    "\n",
    "def DS_check(n,c):\n",
    "    start=time.time()\n",
    "    gc=uni_c_graphs(n,c)\n",
    "    print(f'Graph generation took {time.time()-start} seconds')\n",
    "    grouped_graphs = DS_classes(gc)\n",
    "\n",
    "    # Print the results\n",
    "    example=False\n",
    "    for ds, graphs in grouped_graphs.items():\n",
    "        if len(graphs)>1:\n",
    "            example=True\n",
    "            print(f\"Deg. Seq. {ds}: {graphs}\")\n",
    "            for g in graphs:\n",
    "                g.show()\n",
    "\n",
    "    if not example:\n",
    "        print(f'Deg sqce distinguishes uni-{c}-cyclic graphs on {n} vertices')              \n",
    "\n",
    "for n in range(5,10):\n",
    "    print(f'n={n}')\n",
    "    DS_check(n,4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath 10.8",
   "language": "sage",
   "name": "sagemath"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
