Index: src/dgp/dgp1.cc
===================================================================
--- src/dgp/dgp1.cc	(revision a15e59b825ae3aa1d5f3555afaf4cdbf22beda62)
+++ src/dgp/dgp1.cc	(revision 3b02b04ff9c7c3446ca477cd84c2bc7f737c38b4)
@@ -10,4 +10,8 @@
 list<int> nodelist;
 list<int>::iterator processed;
+
+
+void print_sets(int n);
+
 
 //====================================================================================================
@@ -44,5 +48,5 @@
   ret.forbidden |= grammar.constr_exclude(link.role);
 
-  ret.boubbles=bs;
+  ret.boubbles.merge(bs); //DOBRZE
   ret.flags |= ( depflags & grammar.pass_flags(link.role) );
 
@@ -58,5 +62,5 @@
 {
   NodeProp ret=depprop;
-  ret.boubbles=bs;
+  ret.boubbles.merge(bs); //DOBRZE
   return ret;
 }
@@ -67,7 +71,22 @@
 {
   MNode& mnode = mgraph[mnodeind];
+  int ret=-1;
   for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps)
-    if(sgraph[*ps].prop==p && sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV)      return *ps;
-  return -1;
+    {
+      if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps);
+      if(sgraph[*ps].prop==p)
+	if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV)
+	  {
+	    ret = *ps;
+	    // fprintf(stderr,"FIND EXISTING NODE SUCCEEDED BEACAUSE OF LH/LV equality ()\n");
+	  }
+	else
+	  {
+	    // fprintf(stderr,"FIND EXISTING NODE FAILED BEACAUSE OF LH/LV inequality\n");
+	  }
+    }
+
+  if(debug) fprintf(stderr,"\n");
+  return ret;
 }
 
@@ -83,4 +102,5 @@
 	ret.push_back(new_boubble);
     }
+
   return ret;
 }
@@ -120,39 +140,67 @@
 //====================================================================================================
 
-int create_new_head_node_left(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV)
-{
-  int newheadind = sgraph.clone(*h,newheadprop);
-  list<int>::iterator nextit=h; ++nextit;
-  nodelist.insert(nextit,newheadind);
+void copy_links(int i, int j)
+{
+  sgraph[j].heads = sgraph[i].heads;
+  sgraph[j].deps = sgraph[i].deps;
+}
+
+
+void create_reverse_links(int n)
+{
+  for(vector<Arc>::iterator a=sgraph[n].heads.begin(); a != sgraph[n].heads.end(); a++)
+    sgraph[a->dst].deps.push_back(Arc(n,a->role,a->headanc,a->depanc));
+
+  for(vector<Arc>::iterator a=sgraph[n].deps.begin(); a != sgraph[n].deps.end(); a++)
+    sgraph[a->dst].heads.push_back(Arc(n,a->role,a->headanc,a->depanc));
+}
+
+//====================================================================================================
+
+int create_new_head_node_left(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV)
+{
+  int newheadind = sgraph.clone(h,newheadprop);
+  // list<int>::iterator nextit=h; ++nextit;
+  // nodelist.insert(nextit,newheadind);
+  nodelist.push_back(newheadind);
   sgraph[newheadind].LH=newheadLH;
   sgraph[newheadind].LD = newheadLD;
   sgraph[newheadind].in_LH=true;
   sgraph[newheadind].LV.reset();
-  
-  if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h);
-  
+
+  copy_links(h,newheadind);
+  create_reverse_links(newheadind);
+  
+  if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h);
+  if(debug) print_sets(newheadind);
   return newheadind;
 }
 
-int create_new_dep_node_left(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)
-{
-  int newind = sgraph.clone(*d,prop);
-  list<int>::iterator nextit=d; ++nextit;
-  nodelist.insert(nextit,newind);
+int create_new_dep_node_left(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)
+{
+  int newind = sgraph.clone(d,prop);
+  // list<int>::iterator nextit=d; ++nextit;
+  // nodelist.insert(nextit,newind);
+  nodelist.push_back(newind);
   sgraph[newind].LH.reset();
   sgraph[newind].LD=LD;
   sgraph[newind].in_LH=false; //???????
   sgraph[newind].LV.reset();
-  
-  if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d);
+
+  copy_links(d,newind);
+  create_reverse_links(newind);
+  
+  if(debug) sgraph.print_node_debug(stderr,"C ",newind,d);
+  if(debug) print_sets(newind);
   
   return newind;
 }
 
-int create_new_head_node_right(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV)
-{
-  int newheadind = sgraph.clone(*h,newheadprop);
-  list<int>::iterator nextit=h; ++nextit;
-  nodelist.insert(nextit,newheadind);
+int create_new_head_node_right(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV)
+{
+  int newheadind = sgraph.clone(h,newheadprop);
+  // list<int>::iterator nextit=h; ++nextit;
+  // nodelist.insert(nextit,newheadind);
+  nodelist.push_back(newheadind);
   sgraph[newheadind].LH=newheadLH;
   sgraph[newheadind].LD=newheadLD;
@@ -160,14 +208,17 @@
   sgraph[newheadind].LV=newheadLV;
   
-  if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h);
+  copy_links(h,newheadind);
+  create_reverse_links(newheadind);
+
+  if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h);
+  if(debug) print_sets(newheadind);
   
   return newheadind;
 }
 
-int create_new_dep_node_right(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)
-{
-  int newind = sgraph.clone(*d,prop);
-  list<int>::iterator nextit=d; ++nextit;
-  nodelist.insert(nextit,newind);
+int create_new_dep_node_right(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)
+{
+  int newind = sgraph.clone(d,prop);
+  nodelist.push_back(newind);
   sgraph[newind].LH=LH;
   sgraph[newind].LD=LD;
@@ -175,5 +226,9 @@
   sgraph[newind].LV.reset();
   
-  if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d);
+  copy_links(d,newind);
+  create_reverse_links(newind);
+
+  if(debug) sgraph.print_node_debug(stderr,"C ",newind,d);
+  if(debug) print_sets(newind);
   
   return newind;
@@ -182,9 +237,9 @@
 //====================================================================================================
 
-void connect_left(list<int>::iterator h, list<int>::iterator d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)
-{
-
-  NodeProp &oldheadprop = sgraph[*h].prop;
-  NodeProp &olddepprop = sgraph[*d].prop;
+void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)
+{
+
+  NodeProp &oldheadprop = sgraph[h].prop;
+  NodeProp &olddepprop = sgraph[d].prop;
 
   NodeProp newheadprop  = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags);
@@ -192,20 +247,25 @@
   int newheadind;
   if(oldheadprop==newheadprop)
-    newheadind = *h;
+    newheadind = h;
   else
   {
-    bitset<MAXNODES> newheadLH = sgraph[*h].LH;
-    bitset<MAXNODES> newheadLV = sgraph[*d].LV;
-    bitset<MAXNODES> newheadLD = sgraph[*h].LD;
-
-    newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV);
-    if( newheadind >= 0 )
+    bitset<MAXNODES> newheadLH = sgraph[h].LH;
+    bitset<MAXNODES> newheadLV = sgraph[d].LV;
+    bitset<MAXNODES> newheadLD = sgraph[h].LD;
+
+    //    vector<int> newedge;
+
+    newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV);
+    if( newheadind >= 0) // W£¡CZONE
       sgraph[newheadind].LD |= newheadLD;
     else
-      newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV);
+      {
+	newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV);
+	sgraph[newheadind].edge.clear();
+	sgraph[newheadind].edge_contains_self = false;
+      }
+    
   }
 
-
-
   NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles);
 
@@ -213,56 +273,74 @@
   
   if(olddepprop==newdepprop)
-    newdepind = *d;
+    newdepind = d;
   else
   {
-    bitset<MAXNODES> newdepLH = sgraph[*d].LH;
-    bitset<MAXNODES> newdepLV = sgraph[*d].LV;
-    bitset<MAXNODES> newdepLD = sgraph[*d].LD;
-
-    newdepind = find_existing_node(sgraph[*d].mnode, newdepprop, newdepLH, newdepLV);
-    if( newdepind >= 0 )
+    bitset<MAXNODES> newdepLH = sgraph[d].LH;
+    bitset<MAXNODES> newdepLV = sgraph[d].LV;
+    bitset<MAXNODES> newdepLD = sgraph[d].LD;
+
+    newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV);
+    if( newdepind >= 0) // W£¡CZONE
       sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD
     else
-      newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV);
+      {
+	newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV);
+	sgraph[newdepind].edge.clear();
+	//sgraph[newdepind].edge.push_back(newdepind); // TO
+	sgraph[newdepind].edge_contains_self = true; // LUB TO
+      }
   }
-
-  sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,*h,*d));
-  
-  if(sgraph[*d].saturated()) sgraph[newheadind].LV |= sgraph[*d].LV;
-
-  sgraph[newheadind].LD.set(*d);
-  if(sgraph[*d].saturated()) sgraph[newheadind].LD |= sgraph[*d].LD;
-  
-  if(debug) sgraph.print_arc(stderr,newheadind,*d,l.role,0);
-  if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,*h);
-  if(debug) sgraph.print_node_debug(stderr,"U ",*d,*d);
+  
+
+  sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d));
+  sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d));
+  sgraph[newheadind].edge.push_back(newdepind);
+  
+  if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV;
+
+  sgraph[newheadind].LD.set(d);
+  if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD;
+  
+  if(debug) sgraph.print_arc(stderr,newheadind,d,l.role,0);
+  if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h);
+  if(debug) print_sets(newheadind);
+  if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d);
+  if(debug) print_sets(newdepind);
 }
 
 //----------------------------------------------------------------------------------------------------
 
-void connect_right(list<int>::iterator h, list<int>::iterator d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)
-{
-  NodeProp &oldheadprop = sgraph[*h].prop;
-
-  NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[*d].prop.flags);
+void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)
+{
+  NodeProp &oldheadprop = sgraph[h].prop;
+
+  NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags);
 
   int newheadind;
   
   if(oldheadprop==newheadprop)
-    newheadind = *h;
+    newheadind = h;
   else
   {
-    bitset<MAXNODES> newheadLH = sgraph[*h].LH;
-    bitset<MAXNODES> newheadLV = sgraph[*h].LV;
-    bitset<MAXNODES> newheadLD = sgraph[*h].LD;
-
-    newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV);
-    if( newheadind >= 0 )
+    bitset<MAXNODES> newheadLH = sgraph[h].LH;
+    bitset<MAXNODES> newheadLV = sgraph[h].LV;
+    bitset<MAXNODES> newheadLD = sgraph[h].LD;
+
+    newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV);
+
+    if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind);
+
+    if( newheadind >= 0) // W£¡CZONE
       sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD
     else
-      newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV);
+      {
+	newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV);
+	//if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO
+	sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self;      // LUB TO
+	sgraph[newheadind].visible_as_neighbour = false;
+      }
   }
 
-  NodeProp &olddepprop = sgraph[*d].prop;
+  NodeProp &olddepprop = sgraph[d].prop;
   NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles);
 
@@ -270,22 +348,29 @@
   
   if(olddepprop==newdepprop)
-    newdepind = *d;
+    newdepind = d;
   else
   {
-    bitset<MAXNODES> newdepLH = sgraph[*d].LH;
-    bitset<MAXNODES> newdepLV = sgraph[*d].LV;
-    bitset<MAXNODES> newdepLD = sgraph[*d].LD;
-
-    newdepind = find_existing_node(sgraph[*d].mnode, newdepprop, newdepLH, newdepLV);
-    if( newdepind >= 0 )
+    bitset<MAXNODES> newdepLH = sgraph[d].LH;
+    bitset<MAXNODES> newdepLV = sgraph[d].LV;
+    bitset<MAXNODES> newdepLD = sgraph[d].LD;
+
+    newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV);
+
+    if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind);
+
+    if( newdepind >= 0) // W£¡CZONE
       sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD
     else
-      newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV);
+      {
+	newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV);
+	sgraph[newdepind].edge.clear();
+	sgraph[newdepind].edge_contains_self = false;
+      }
   }
 
 
-
-  
-  sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,*h,*d));
+  sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d));
+  sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d));
+  //sgraph[newdepind].edge.push_back(newheadind);
 
   sgraph[newdepind].LH.set(newheadind);
@@ -296,6 +381,6 @@
 
   if(debug) sgraph.print_arc(stderr,newheadind,newdepind,l.role,1);
-  if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,*h);
-  if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,*d);
+  if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h);
+  if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d);
   
 }
@@ -323,22 +408,18 @@
 }
 
-// bool check_boubbles_at_target(list<Boubble*> boubbles, int node)
-// {
-//   for(list<Boubble*>::iterator b = boubbles.begin(); b != boubbles.end(); ++b )
-//     if( (*b)->is_at_target() && !grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) )
-//       return false;
-//   return true;
-// }
-
-//====================================================================================================
-
-void try_connect_dependents(list<int>::iterator j)
-{
-  for(list<int>::iterator i(j); i!=nodelist.begin(); --i)
-    if(sgraph.visible(*i,*j) && sgraph.saturated(*i))
-    {
-      if(debug) {fprintf(stderr,"## %d <-- %d ... ",*i,*j); }
-
-      list<const Link*> ji_links = grammar.connectable2( sgraph.cat(*j), sgraph.cat(*i), sgraph[*j].prop.flags, sgraph[*i].prop.flags); // ref do Roles!!!
+//====================================================================================================
+
+void try_connect_dependents(int j)
+{
+  // for(list<int>::iterator i(j); i!=nodelist.begin(); --i)
+  //   if(sgraph.visible(*i,*j) && sgraph.saturated(*i))
+  LViterator lvi(sgraph,j);
+  int i;
+  while((i=lvi.next()) >= 0)
+    if(sgraph.saturated(i))
+      {
+      if(debug) {fprintf(stderr,"## %d <-- %d ... ",i,j); }
+
+      list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!!
       list<const Link*>::iterator ri = ji_links.begin();
       if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); }
@@ -346,12 +427,12 @@
 	{
 	  for(; ri != ji_links.end(); ++ri )
-	    if(!grammar.check_constr2(sgraph[*j].prop,sgraph[*i].prop,0,**ri ))
+	    if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri ))
 	      { if(debug) fprintf(stderr,"constraints failed\n"); }
 	    else
 	      {
-		list<Boubble*> new_head_boubbles = collect_head_boubbles(*j,*i,(*ri)->role);
-		list<Boubble*> new_dep_boubbles = collect_dep_boubbles(*j,*i,(*ri)->role);
+		list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role);
+		list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role);
 		
-		if( !(check_boubbles_at_target(new_head_boubbles,*j) && check_boubbles_at_target(new_dep_boubbles,*i)) )
+		if( !(check_boubbles_at_target(new_head_boubbles,j) && check_boubbles_at_target(new_dep_boubbles,i)) )
 		  { if(debug) fprintf(stderr,"boubbles failed\n"); }
 		else
@@ -368,12 +449,17 @@
 //----------------------------------------------------------------------------------------------------
 
-void try_connect_heads(list<int>::iterator j)
-{
-  for(list<int>::iterator i(j); i!=nodelist.begin(); --i)
-    if(sgraph.visible(*i,*j))
-    {
-      if(debug) fprintf(stderr, "## %d --> %d ... ",*i,*j);
-
-      list<const Link*> ij_links = grammar.connectable2( sgraph.cat(*i), sgraph.cat(*j), sgraph[*i].prop.flags, sgraph[*j].prop.flags );
+void try_connect_heads(int j)
+{
+  // for(list<int>::iterator i(j); i!=nodelist.begin(); --i)
+  //   if(sgraph.visible(*i,*j) && sgraph.saturated(*j))
+
+  LViterator lvi(sgraph,j);
+  int i;
+  while((i=lvi.next()) >= 0)
+    if(sgraph.saturated(j))
+    {
+      if(debug) fprintf(stderr, "## %d --> %d ... ",i,j);
+
+      list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags );
       list<const Link*>::iterator ri = ij_links.begin();
       if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); }
@@ -381,12 +467,12 @@
 	{
 	  for(; ri != ij_links.end(); ++ri )
-	    if( !grammar.check_constr2( sgraph[*i].prop, sgraph[*j].prop, 1, **ri ) )
+	    if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) )
 	      { if(debug) fprintf(stderr,"constraints failed\n"); }
 	    else
 	      {
-		list<Boubble*> new_head_boubbles = collect_head_boubbles(*i,*j,(*ri)->role);
-		list<Boubble*> new_dep_boubbles = collect_dep_boubbles(*i,*j,(*ri)->role);
+		list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role);
+		list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role);
 		
-		if( !(check_boubbles_at_target(new_head_boubbles,*i) && check_boubbles_at_target(new_dep_boubbles,*j)) )
+		if( !(check_boubbles_at_target(new_head_boubbles,i) && check_boubbles_at_target(new_dep_boubbles,j)) )
 		  { if(debug) fprintf(stderr,"boubbles failed\n"); }
 		else
@@ -399,5 +485,60 @@
     }
 }
-  
+
+//====================================================================================================
+
+void update_sets()
+{
+  for(int n=0; n<sgraph.size(); ++n)
+    {
+      LViterator lvi(sgraph,n,false);
+      LHiterator lhi(sgraph,n);
+      LDiterator ldi(sgraph,n);
+      int i;
+
+      // printf("UPDATING LV[%d]:",n);
+      while((i=lvi.next())>=0)
+	{
+	  // printf(" %d",i);
+	  sgraph[n].LV.set(i);
+	}
+      // printf("\n");
+
+      while((i=lhi.next())>=0) sgraph[n].LH.set(i);
+      while((i=ldi.next())>=0) sgraph[n].LD.set(i);
+    }
+}
+
+//====================================================================================================
+
+void print_sets(int n)
+{
+  LViterator lvi(sgraph,n);
+  LHiterator lhi(sgraph,n);
+  LDiterator ldi(sgraph,n);
+  
+  int i;  
+  printf("LV[%d]: ",n);
+  while((i=lvi.next())>=0)
+	{
+	  printf("%d ",i);
+	  sgraph[n].LV.set(i);
+	}
+
+  printf("LH[%d]: ",n);
+  while((i=lhi.next())>=0)
+    {
+      printf("%d ",i);
+      sgraph[n].LH.set(i);
+    }
+  printf("LD[%d]: ",n);
+  while((i=ldi.next())>=0)
+    {
+      printf("%d ",i);
+      sgraph[n].LD.set(i);
+    }
+  printf("\n");
+}
+
 //====================================================================================================
 
@@ -430,15 +571,18 @@
     nodelist.push_back(basenode);
 
-    if(debug) {sgraph.print_node_debug(stderr,"B ",basenode,-1);} // STDOUT!!!
+    if(debug) sgraph.print_node_debug(stderr,"B ",basenode,-1); // STDOUT!!!
+    if(debug) print_sets(basenode);
 
     list<int>::iterator cursor=processed;
     while(++cursor != nodelist.end())
     {
-      try_connect_dependents(cursor);
-      try_connect_heads(cursor);
+      if(debug) sgraph.print_node_debug(stderr,"> ",*cursor,-1);
+      try_connect_dependents(*cursor);
+      try_connect_heads(*cursor);
       processed=cursor;
     }
 
   }
-  reverse_links();
-}
+   // reverse_links();
+  update_sets();
+}
