Skip to content
Snippets Groups Projects
Commit 3ba56335 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Fix LCA

parent 237f4a32
Branches
No related tags found
No related merge requests found
alg2pdf 0 → 100755
#!/bin/bash
# Random temp file name
tex_file=$(mktemp)
# Print the tex file header
cat<<EOF >$tex_file
\documentclass{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color} %% Allow color names
\usepackage[letterpaper, portrait, margin=1in]{geometry}
%\lstdefinestyle{customasm}{
% belowcaptionskip=1\baselineskip,
% xleftmargin=\parindent,
% language=C++, %% Change this to whatever you write in
% breaklines=true, %% Wrap long lines
% basicstyle=\footnotesize\ttfamily,
% commentstyle=\itshape\color{Gray},
% stringstyle=\color{Black},
% numberstyle=\color{Orange},
% keywordstyle=\bfseries\color{OliveGreen},
% identifierstyle=\color{blue},
%}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\definecolor{darkpink}{rgb}{0.75,0.25,0.5}
\lstdefinestyle{customasm}{
language=[ISO]C++,
breaklines=true, %% Wrap long lines
keywordstyle=\color{blue}\bfseries,
commentstyle=\color{darkgreen}\textit,
stringstyle=\color{darkpink}\ttfamily,
basicstyle=\footnotesize\ttfamily\color{red},
identifierstyle={\color{black}},
%
literate=*
{;}{{{\color{black};}}}{1}
{.7}{{{\color{red}.7}}}{2},%
%
morekeywords={int32_t}
}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\begin{document}
\tableofcontents
EOF
# xleftmargin=-8em,
past_dir_name="00"
find . -type f \( -iname \*.cpp -o -iname \*.cu \) |
# Change ./foo/bar.src to foo/bar.src
sed 's/^\..//' |
# Loop through each file
while read i; do
dir_name=`echo $i | awk -F '/' '{print $1}' | sed 's/_/\\\_/g'`
file_name=`echo $i | awk -F '/' '{print $2}' | sed 's/_/\\\_/g'`
if [ "$dir_name" != "$past_dir_name" ]; then
# Start new section
echo "\newpage" >> $tex_file
echo "\section{$dir_name}" >> $tex_file
else
echo "\\" >> $tex_file
fi
# Create a section for each file
echo "\subsection{$file_name}" >> $tex_file
# This command will include the file in the PDF
echo "\lstinputlisting[style=customasm]{$i}" >>$tex_file
past_dir_name="$dir_name"
done &&
echo "\end{document}" >> $tex_file &&
# This needs to be run twice for the TOC to be generated
pdflatex $tex_file -output-directory . &&
pdflatex $tex_file -output-directory .
mv tmp.pdf caderno.pdf
rm tmp.*
#include <bits/stdc++.h>
#define MAX 0
#define MOD 1000000007
#define EPS 1e-6
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define sz size()
#define pb push_back
#define ende '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
ll ans = 1;
for (int i = 0; i < n + 1; ++i)
ans *= 2;
cout << ans - 1 << ende;
return 0;
}
File deleted
...@@ -11,21 +11,22 @@ ...@@ -11,21 +11,22 @@
* *** = used in both * and ** * *** = used in both * and **
*/ */
vector<ii> graph[MAX]; vector<int> graph[MAX]; //*** vector<ii>
int h[MAX]; int h[MAX];
int par[MAX][MAXLOG], cost[MAX][MAXLOG]; int par[MAX][MAXLOG];
//*** int cost[MAX][MAXLOG];
// Perform DFS while filling h, par, and cost // Perform DFS while filling h, par, and cost
void dfs(int v, int p = -1, int c = 0) { void dfs(int v, int p = -1, int c = 0) {
par[v][0] = p; par[v][0] = p;
//*** cost[v][0] = c; //*** cost[v][0] = c;
if (p + 1) if (p != -1)
h[v] = h[p] + 1; h[v] = h[p] + 1;
for (int i = 1; i < MAXLOG; ++i) for (int i = 1; i < MAXLOG; ++i)
if (par[v][i - 1] + 1) { if (par[v][i - 1] != -1) {
par[v][i] = par[par[v][i - 1]][i - 1]; par[v][i] = par[par[v][i - 1]][i - 1];
//* cost[v][i] += cost[v][i - 1] + cost[par[v][i - 1]][i - 1]; //* cost[v][i] += cost[v][i - 1] + cost[par[v][i - 1]][i - 1];
//** cost[v][i] = max(cost[v][i], max(cost[par[v][i-1]][i-1], cost[v][i-1])); //** cost[v][i] = max(cost[v][i], max(cost[par[v][i-1]][i-1], cost[v][i-1]));
...@@ -40,7 +41,7 @@ void dfs(int v, int p = -1, int c = 0) { ...@@ -40,7 +41,7 @@ void dfs(int v, int p = -1, int c = 0) {
// Preprocess tree rooted at v // Preprocess tree rooted at v
void preprocess(int v) { void preprocess(int v) {
memset(par, -1, sizeof par); memset(par, -1, sizeof par);
memset(cost, 0, sizeof cost); //*** memset(cost, 0, sizeof cost);
dfs(v); dfs(v);
} }
...@@ -53,25 +54,24 @@ int query(int p, int q) { ...@@ -53,25 +54,24 @@ int query(int p, int q) {
swap(p, q); swap(p, q);
for (int i = MAXLOG - 1; i >= 0; --i) for (int i = MAXLOG - 1; i >= 0; --i)
if (par[p][i] + 1 && h[par[p][i]] >= h[q]) { if (par[p][i] != -1 && h[par[p][i]] >= h[q]) {
//* ans += cost[p][i]; //* ans += cost[p][i];
//** ans = max(ans, cost[p][i]); //** ans = max(ans, cost[p][i]);
p = par[p][i]; p = par[p][i];
} }
if (p == q) if (p == q)
return p; return p; //*** return ans;
//*** return ans;
for (int i = MAXLOG - 1; i >= 0; --i) for (int i = MAXLOG - 1; i >= 0; --i)
if (par[p][i] + 1 && par[p][i] != par[q][i]) { if (par[p][i] != -1 && par[p][i] != par[q][i]) {
//* ans += cost[p][i] + cost[q][i]; //* ans += cost[p][i] + cost[q][i];
//** ans = max(ans, max(cost[p][i], cost[q][i])); //** ans = max(ans, max(cost[p][i], cost[q][i]));
p = par[p][i]; p = par[p][i];
q = par[q][i]; q = par[q][i];
} }
return cost[p][0]; return par[p][0];
//* if (p == q) return ans; //* if (p == q) return ans;
//* else return ans + cost[p][0] + cost[q][0]; //* else return ans + cost[p][0] + cost[q][0];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment