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

Small fixes

parent a6251d32
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,8 @@
/// Include:
/// - structure/disjoint_set
typedef pair<ii,int> iii;
vector<iii> edges;
using edge = pair<ii,int>;
vector<edge> edges;
struct Kruskal {
int N;
......@@ -17,8 +17,8 @@ struct Kruskal {
// Minimum Spanning Tree: comp = less<int>()
// Maximum Spanning Tree: comp = greater<int>()
int run(vector<iii> &mst, function<bool(int,int)> comp) {
sort(all(edges), [&](const iii &a, const iii &b) {
int run(vector<edge> &mst, function<bool(int,int)> comp) {
sort(all(edges), [&](const edge &a, const edge &b) {
return comp(a.se, b.se);
});
......
......@@ -9,36 +9,33 @@
struct KMP {
string patt;
vector<int> table;
vector<int> pi;
KMP(string patt) :
patt(patt), table(patt.size()+1)
patt(patt), pi(patt.size())
{ preprocess(); }
void preprocess() {
fill(all(table), -1);
patt[0] = 0;
for (int i = 1, j = 0; i < patt.size(); ++i) {
while (j > 0 && patt[i] != patt[j])
j = pi[j - 1];
for (int i = 0, j = -1; i < patt.size(); ++i) {
while (j >= 0 && patt[i] != patt[j])
j = table[j];
table[i + 1] = ++j;
if (patt[i] == patt[j]) j++;
pi[i] = j;
}
}
vector<int> search(const string &txt) {
vector<int> occurs;
void search(const string &txt) {
for (int i = 0, j = 0; i < txt.size(); ++i) {
while (j >= 0 && txt[i] != patt[j])
j = table[j];
j++;
while (j > 0 && txt[i] != patt[j])
j = pi[j - 1];
if (txt[i] == patt[j]) j++;
if (j == patt.size()) {
occurs.pb(i - j);
j = table[j];
cout << "Pattern found at " << (i - j) << ende;
j = pi[j - 1];
}
}
return occurs;
}
};
......@@ -20,7 +20,7 @@ struct SegmentTree {
T ident = T();
vector<T> tree;
SegmentTree(F &func) : func(func), tree(MAX*4) {}
SegmentTree(F func) : func(func), tree(MAX*4) {}
void build(const vector<T> &v,
int node = 1, int l = 0, int r = N - 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment