From ac011ea05e08936833fa143aa0a90cc883c4bb97 Mon Sep 17 00:00:00 2001 From: iagorrr04 Date: Tue, 31 Oct 2023 22:55:28 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Adiciona=20vers=C3=A3o=20simplificada=20da?= =?UTF-8?q?=20DFS=20para=20achar=20di=C3=A2metro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grafos/slides/arvores_diametro/codes/dp2.cpp | 64 ++++++++ Grafos/slides/arvores_diametro/main.tex | 149 +++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 Grafos/slides/arvores_diametro/codes/dp2.cpp diff --git a/Grafos/slides/arvores_diametro/codes/dp2.cpp b/Grafos/slides/arvores_diametro/codes/dp2.cpp new file mode 100644 index 00000000..2de8b0d3 --- /dev/null +++ b/Grafos/slides/arvores_diametro/codes/dp2.cpp @@ -0,0 +1,64 @@ +#include + +using namespace std; +using ii = pair; + +const int MAX { 2 * 1'00'000 + 1 }; +vector adj[MAX]; +int to_leaf[MAX], max_length[MAX]; + +void dfs(int u, int p) +{ + int ds1, ds2; + ds1 = ds2 = -1; + + for (auto v : adj[u]) + { + if (v == p) + continue; + + if (ds1 < ds2) swap(ds1, ds2); + + dfs(v, u); + + ds1 = max(ds2, to_leaf[v]); + } + + + to_leaf[u] = max(ds1, ds2) + 1; + max_length[u] = 2 + ds1 + ds2; +} + +int diameter(int root, int N) +{ + dfs(root, 0); + + int d = 0; + + for (int u = 1; u <= N; ++u) + d = max(d, max_length[u]); + + return d; +} + +int main() +{ + vector edges; + int N; + cin >> N; + for (int i = 1; i <= N-1; i++) { + int u, v; + cin >> u >> v; + edges.emplace_back(u, v); + } + + for (const auto& [u, v] : edges) { + adj[u].push_back(v); + adj[v].push_back(u); + } + + // 4 + cout << diameter(1, N) << endl; + + return 0; +} diff --git a/Grafos/slides/arvores_diametro/main.tex b/Grafos/slides/arvores_diametro/main.tex index ef45a433..a3129978 100644 --- a/Grafos/slides/arvores_diametro/main.tex +++ b/Grafos/slides/arvores_diametro/main.tex @@ -1169,6 +1169,155 @@ \inputsnippet{cpp}{27}{41}{codes/dp.cpp} \end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores } }; + +\end{tikzpicture} +\end{frame} + + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores } }; + \node[anchor=west] (a) at (0.1, 5.0) { $\star$ \bbtext{Guardaremos em $\displaystyle \mathrm{ds1}$ e $\displaystyle \mathrm{ds2}$, o maior e segundo maior valor para $\displaystyle \mathrm{to\_leaf}[v]$.} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + + + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + + + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; + + \end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + + + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; + \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas 1 filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + ds2 = ds2 + 1$} }; + +\end{tikzpicture} +\end{frame} +\begin{frame}[plain,t] + +\begin{tikzpicture} +\node[draw,opacity=0] at (0, 0) {x}; +\node[draw,opacity=0] at (14, 8) {x}; + \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; + + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + + + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; + \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas 1 filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + ds2 = ds2 + 1$} }; + \node[anchor=west] (a) at (0.5, 2.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + -1 = 0$} }; + +\end{tikzpicture} +\end{frame} + +\begin{frame}[plain,t] + + \inputsnippet{cpp}{10}{30}{codes/dp2.cpp} + +\end{frame} + \begin{frame}[plain,t] \begin{tikzpicture} \node[draw,opacity=0] at (0, 0) {x}; From a9fa11173ebd026018547c2910fff3c5e1d512a9 Mon Sep 17 00:00:00 2001 From: iagorrr04 Date: Wed, 1 Nov 2023 11:41:38 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Corrige=20erros=20de=20digita=C3=A7=C3=A3o?= =?UTF-8?q?=20e=20renomeia=20vari=C3=A1veis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grafos/slides/arvores_diametro/codes/dp2.cpp | 22 +++---- Grafos/slides/arvores_diametro/main.tex | 62 ++++++++++---------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/Grafos/slides/arvores_diametro/codes/dp2.cpp b/Grafos/slides/arvores_diametro/codes/dp2.cpp index 2de8b0d3..811a774d 100644 --- a/Grafos/slides/arvores_diametro/codes/dp2.cpp +++ b/Grafos/slides/arvores_diametro/codes/dp2.cpp @@ -21,7 +21,7 @@ void dfs(int u, int p) dfs(v, u); - ds1 = max(ds2, to_leaf[v]); + ds2 = max(ds2, to_leaf[v]); } @@ -43,14 +43,8 @@ int diameter(int root, int N) int main() { - vector edges; - int N; - cin >> N; - for (int i = 1; i <= N-1; i++) { - int u, v; - cin >> u >> v; - edges.emplace_back(u, v); - } + vector edges { ii(1, 7), ii(3, 7), ii(7, 4), ii(4, 2), + ii(4, 5), ii(5, 6) }; for (const auto& [u, v] : edges) { adj[u].push_back(v); @@ -58,7 +52,15 @@ int main() } // 4 - cout << diameter(1, N) << endl; + cout << diameter(4, 7) << endl; + + // 0 0 0 2 1 0 1 + for (int u = 1; u <= 7; ++u) + cout << to_leaf[u] << (u == 7 ? '\n' : ' '); + + // 0 0 0 4 1 0 2 + for (int u = 1; u <= 7; ++u) + cout << max_length[u] << (u == 7 ? '\n' : ' '); return 0; } diff --git a/Grafos/slides/arvores_diametro/main.tex b/Grafos/slides/arvores_diametro/main.tex index a3129978..759d88c6 100644 --- a/Grafos/slides/arvores_diametro/main.tex +++ b/Grafos/slides/arvores_diametro/main.tex @@ -1186,7 +1186,7 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores } }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores. } }; \end{tikzpicture} \end{frame} @@ -1198,8 +1198,8 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores } }; - \node[anchor=west] (a) at (0.1, 5.0) { $\star$ \bbtext{Guardaremos em $\displaystyle \mathrm{ds1}$ e $\displaystyle \mathrm{ds2}$, o maior e segundo maior valor para $\displaystyle \mathrm{to\_leaf}[v]$.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{Partindo da idéia anterior é possível guardar apenas os dois melhores valores. } }; + \node[anchor=west] (a) at (0.1, 5.0) { $\star$ \bbtext{Guardaremos em $\displaystyle \mathrm{d1}$ e $\displaystyle \mathrm{d2}$, o maior e segundo maior valor para $\displaystyle \mathrm{to\_leaf}[v]$.} }; \end{tikzpicture} \end{frame} @@ -1210,7 +1210,7 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; \end{tikzpicture} \end{frame} @@ -1221,8 +1221,8 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; \end{tikzpicture} \end{frame} @@ -1233,9 +1233,9 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; - \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado.} }; \end{tikzpicture} \end{frame} @@ -1246,12 +1246,12 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; - \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado.} }; - \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2}$ tem-se que :} }; \end{tikzpicture} \end{frame} @@ -1262,13 +1262,13 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; - \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado.} }; - \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2}$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores valores.} }; \end{tikzpicture} \end{frame} @@ -1279,15 +1279,15 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; - \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado.} }; - \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2}$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; - \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas 1 filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + ds2 = ds2 + 1$} }; + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores valores.} }; + \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas um filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2} = 2 + d1 + (-1) = 1 + d1$} }; \end{tikzpicture} \end{frame} @@ -1298,16 +1298,16 @@ \node[draw,opacity=0] at (14, 8) {x}; \node[anchor=west] (title) at (0.0, 7.0) { \Large \bbbold{Possível simplificação da DFS} }; - \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{ds1}, \displaystyle \mathrm{ds2}) + 1 = -1 + 1= 0$} }; - \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado assim como antes.} }; + \node[anchor=west] (a) at (0.1, 6.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1$ tem-se que :} }; + \node[anchor=west] (a) at (0.5, 5.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{to\_leaf}[u] = max(\displaystyle \mathrm{d1}, \displaystyle \mathrm{d2}) + 1 = -1 + 1= 0$} }; + \node[anchor=west] (a) at (0.5, 5.0) { $\star$ \bbtext{Caso contrário o maior valor será somado.} }; - \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2}$ tem-se que :} }; + \node[anchor=west] (a) at (0.1, 4.0) { $\star$ \bbtext{ Fazendo com que $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2}$ tem-se que :} }; - \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores como antes.} }; - \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas 1 filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + ds2 = ds2 + 1$} }; - \node[anchor=west] (a) at (0.5, 2.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{ds1} + \displaystyle \mathrm{ds2} = 2 + -1 + -1 = 0$} }; + \node[anchor=west] (a) at (0.5, 3.5) { $\star$ \bbtext{Se $u$ tiver pelo menos dois filhos somará os dois maiores.} }; + \node[anchor=west] (a) at (0.5, 3.0) { $\star$ \bbtext{Se $u$ apenas um filho: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2} = 2 + d1 + -1 = 1 + d1$} }; + \node[anchor=west] (a) at (0.5, 2.5) { $\star$ \bbtext{Se $u$ for uma folha: $\displaystyle \mathrm{max\_lenght}[u] = 2 + \displaystyle \mathrm{d1} + \displaystyle \mathrm{d2} = 2 + -1 + -1 = 0$} }; \end{tikzpicture} \end{frame}