#include #include #include #include #include #include #include #define NMAX 100000 #define NMIN 2 using namespace std; vector adj[2][NMAX]; set > arestas[2]; vector folhas[2]; vector filhos[2][NMAX]; int tipo[2][NMAX]; vector tiposatuais[2]; int ntipos; map hashtipos; int grau[2][NMAX]; int n[2]; int fila[NMAX]; int foi[NMAX]; int conexo(int q) { int inicio = 0; int fim = 1; int atual; int i; for (i=0; i vetor, int j) { vector temp; int i; string s; int tam = 0; char aux[10]; for (i=0; i<(int)vetor.size(); i++) { temp.push_back(tipo[j][vetor[i]]); } sort(temp.begin(), temp.end()); for (i=0; i<(int)temp.size(); i++) { if (i) { str[tam] = ' '; tam++; } sprintf(aux, "%d", temp[i]); strcpy(&str[tam], aux); tam += strlen(aux); } s = str; if (hashtipos.find(s)==hashtipos.end()) { hashtipos[s] = ntipos; ntipos++; } return hashtipos[s]; } void legrafo(int q, int size) { int i; int x, y; n[q]=size; for (i=0; i 0) break; //diminui o grau do pai grau[j][adj[j][folhas[j][i]][k]]--; if (grau[j][adj[j][folhas[j][i]][k]] == 0) //se era ultimo vertice do grafo grau[j][adj[j][folhas[j][i]][k]]++; //incrementa para saber q eh folha filhos[j][adj[j][folhas[j][i]][k]].push_back(folhas[j][i]); //adiciona a folha na lista do pai } } } //ordena as listas de tipos das folhas, para poder comparar for (j=0; j<2; j++) sort(tiposatuais[j].begin(), tiposatuais[j].end()); for (i=0; i<(int)tiposatuais[0].size(); i++) { if (tiposatuais[0][i] != tiposatuais[1][i]) //se as folhas nao sao isomorfas isomorfo = 0; } if (total[0] == n[0] || total[1] == n[1]) break; } if (isomorfo) { printf("S\n"); } else { printf("N\n"); } } return 0; }