void ConnectivityGraph::deleteEdge( EdgeIP e ) { // std::cout << "deleting edge " << *e << // ( e->isTree ? " (tree)" : " (nontree)" ) << std::endl; // assert( e->count == 0 ); Vertex & u( vertices[e->vxid1] ); Vertex & v( vertices[e->vxid2] ); assert( EulerTourTree::connected( &u.ETvertices[0], &v.ETvertices[0] ) ); if ( e->isTree ) { // cut all forests F_i, for 0 <= i <= level(e) for ( ETForestLevel i = e->level; i >= 0; --i ) { ETNode * oldroot = e->arcs[i].first->findRoot(); assert( oldroot == e->arcs[i].second->findRoot() ); // remove the old root from the forest removeRoot( oldroot, i ); ETNode * r1 = NULL, * r2 = NULL; EulerTourTree::cut( e->arcs[i].first, e->arcs[i].second, &r1, &r2 ); #ifdef DEBUG ETNode * ru = u.ETvertices[i].loopNode->findRoot(); ETNode * rv = v.ETvertices[i].loopNode->findRoot(); assert( ru != rv ); assert( ru == r1 || ru == r2 ); assert( rv == r1 || rv == r2 ); #endif // put the new roots in the forest insertRoot( r1, i ); insertRoot( r2, i ); } // attempt to find a replacement edge for ( ETForestLevel i = e->level; i >= 0; --i ) { if ( replaceEdge( *e, i ) ) break; } } // delete e; }
//main///////////////////////////////////////////////////////////////////////////////////////////////////////// int main(){ mapa m; grafo g = inicializaGrafo(&g, &m); int i, i1, i2, i3; char esc[20]; //comando a ser digitado int FM = 1; while (FM == 1){ scanf("%s", esc); //lerá o comando até o primeiro espaço, para depois ler até o proximo espaço, e assim por diante int escI = identificaComando(esc); //identifica o comando digitado switch(escI){ case _CV: //cria vértice scanf("%d", &i1); insertVertex(&g, &m, i1); break; case _DV: //destrói vértice scanf("%d", &i1); removeVertex(&g, i1, &m); break; case _CA: //cria aresta scanf("%d %d %d", &i1, &i2, &i3); insertEdge(&g, i1, i2, &m, i3); break; case _DA: //destrói aresta scanf("%d", &i1); removeEdge(&g, i1, &m); break; case _TV: //troca vértice scanf("%d %d", &i1, &i2); replaceVertex(i1, i2, m); break; case _TA: //troca aresta scanf("%d %d", &i1, &i2); replaceEdge(i1, i2, m); break; case _IG: //imprime grafo printf("%d\n", g.nvertices); for (i = 0; i < m.indiceVert; i++){ vertice *v = pegaVertRef(m, i+1); if (v != NULL){ printf("%d ", i+1); printf("%d\n", v->conteudo); } } printf("%d\n", g.narestas); for (i = 0; i < m.indiceAres; i++){ aresta *a = pegaAresRef(m, i+1); if (a != NULL){ printf("%d ", i+1); vertice *vT = a->dir; printf("%d ", pegaVertInd(m, vT)); vT = a->esq; printf("%d ", pegaVertInd(m, vT)); printf("%d\n", a->conteudo); } } break; case _CM: //caminho mínimo scanf("%d %d", &i1, &i2); dijkstra(&g, m, i1, i2); break; case _FM: //fim FM = 0; break; } } return 0; }