This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grafo = { | |
'a': ['b', 'd', 'e'], | |
'b': ['a', 'c', 'e'], | |
'c': ['b', 'e'], | |
'd': ['a', 'e'], | |
'e': ['a', 'b', 'c', 'd', 'f'], | |
'f': ['e'] | |
} | |
def busca_em_largura(grafo, vertice_do_grafo): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grafo = { | |
'a': ['b', 'd', 'e'], | |
'b': ['a', 'c', 'e'], | |
'c': ['b', 'e'], | |
'd': ['a', 'e'], | |
'e': ['a', 'b', 'c', 'd', 'f'], | |
'f': ['e'] | |
} | |
# coisos globais |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cria_grafo(lista_de_vertices, lista_de_arestas): | |
grafo = {} | |
for vertice in lista_de_vertices: | |
grafo[vertice] = [] | |
for aresta in lista_de_arestas: | |
grafo[aresta[0]].append(aresta[1]) | |
return grafo | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transpor_digrafo(digrafo): | |
digrafo_t = {} | |
for vertice in digrafo: | |
digrafo_t[vertice] = [] | |
for vertice in digrafo: | |
for vizinho in digrafo[vertice]: | |
digrafo_t[vizinho].append(vertice) | |
return digrafo_t | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coisos globais | |
valor_profundidade_entrada = 0 # contador da profundidade em que os vertices entram da pilha (chamado recursivamente) | |
valor_profundidade_saida = 0 # contador da profundidade em que os vertices saem da pilha (termina sua chamada recursiva) | |
# dicionario com as profunfidades em que cada vertice entrou e saiu da pilha numa lista [profundidade_entrada, profundidade_saida] | |
profundidades_entrada_saida = {} | |
pai = {} # dicionario com os pais de cada vertice na arvore de busca em profundidade | |
aresta = {} # classificacao das arestas na arvore de busca em profundidade do grafo | |
niveis = {} # nivel de cada vertice na arvore de busca em profundidade | |
# conjunto de vertices ainda nao visitados (nunca entraram (e portanto nem sairam) da pilha) | |
nao_visitados = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coisos globais | |
valor_profundidade_entrada = 0 # contador da profundidade em que os vertices entram da pilha (chamado recursivamente) | |
valor_profundidade_saida = 0 # contador da profundidade em que os vertices saem da pilha (termina sua chamada recursiva) | |
# dicionario com as profunfidades em que cada vertice entrou e saiu da pilha numa lista [profundidade_entrada, profundidade_saida] | |
profundidades_entrada_saida = {} | |
pai = {} # dicionario com os pais de cada vertice na arvore de busca em profundidade | |
aresta = {} # classificacao das arestas na arvore de busca em profundidade do grafo | |
niveis = {} # nivel de cada vertice na arvore de busca em profundidade | |
# conjunto de vertices ainda nao visitados (nunca entraram (e portanto nem sairam) da pilha) | |
nao_visitados = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
# coisos globais | |
valor_profundidade_entrada = 0 # contador da profundidade em que os vertices entram da pilha (chamado recursivamente) | |
valor_profundidade_saida = 0 # contador da profundidade em que os vertices saem da pilha (termina sua chamada recursiva) | |
# dicionario com as profunfidades em que cada vertice entrou e saiu da pilha numa lista [profundidade_entrada, profundidade_saida] | |
profundidades_entrada_saida = {} | |
pai = {} # dicionario com os pais de cada vertice na arvore de busca em profundidade | |
aresta = {} # classificacao das arestas na arvore de busca em profundidade do grafo | |
niveis = {} # nivel de cada vertice na arvore de busca em profundidade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recurse_delete($path) | |
{ | |
if (is_dir($path) === true) | |
{ | |
$files = array_diff(scandir($path), array('.', '..')); | |
foreach ($files as $file) | |
{ | |
recurse_delete(realpath($path) . '/' . $file); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recursive_copy($source, $destination) | |
{ | |
if (is_dir($source) === true) { | |
$success = true; | |
if (!file_exists($destination)) { | |
mkdir($destination, 0777, true); | |
} | |
$files = array_diff(scandir($source), ['.', '..']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sets = {} | |
setsRanked = {} | |
def makeSet(x): | |
sets[x] = set([x]) | |
def find(x): | |
for representative,subset in sets.iteritems(): | |
if x in subset: | |
return representative |
OlderNewer