regular backup

This commit is contained in:
arielherself 2024-10-05 19:28:38 +08:00
parent dcd5417e73
commit 2490f8091a
Signed by: arielherself
SSH Key Fingerprint: SHA256:AK3cyo9tFsp7Mox7K0sYphleC8hReXhnRKxwuDT5LBc
5 changed files with 145 additions and 2 deletions

View File

@ -174,6 +174,9 @@ in {
pkgs.nix-index
pkgs.rclone
pkgs.sshfs
pkgs.usbutils
pkgs.udiskie
pkgs.udisks
# Pwn
pkgs.nmap
@ -364,6 +367,7 @@ in {
# This plugin seems to break terminfo when default shell of a terminal emulator is set to zsh.
# set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'erikw/tmux-powerline'
set -g @plugin 'tmux-plugins/tmux-yank'
run '${config.xdg.configHome}/tmux/plugins/tpm/tpm'
'';
};

View File

@ -0,0 +1,66 @@
return [=[
struct hierholzer {
struct edge_t {
int from, to, rev, stale;
edge_t(int from, int to, int rev, int stale) : from(from), to(to), rev(rev), stale(stale) {}
};
int n;
vector<edge_t> edges;
vector<vector<int>> ch;
quick_union qu;
hierholzer(int n) : n(n), ch(n + 1), qu(n + 1) {}
void add_edge(int u, int v) {
int left = edges.size(), right = left + 1;
edges.emplace_back(u, v, right, false);
edges.emplace_back(v, u, left, false);
ch[u].emplace_back(left);
ch[v].emplace_back(right);
qu.merge(u, v);
}
optional<vector<int>> solve() {
if (qu.query_size(1) != n) {
return nullopt;
}
int odd = 0;
int last_odd;
for (int i = 1; i <= n; ++i) {
if (ch[i].size() % 2) {
odd += 1;
last_odd = i;
}
}
int start;
if (odd == 0) {
start = 1;
} else if (odd == 2) {
start = last_odd;
} else {
return nullopt;
}
vector<int> res;
auto dfs = [&] (auto&& dfs, int v) -> void {
while (ch[v].size()) {
int i = ch[v].back();
ch[v].pop_back();
if (not edges[i].stale) {
edges[i].stale = true;
edges[edges[i].rev].stale = true;
dfs(dfs, edges[i].to);
}
}
res.emplace_back(v);
};
dfs(dfs, start);
return res;
}
};
]=]

View File

@ -76,6 +76,19 @@ ls.add_snippets(nil, {
}
})
local quick_union_rollback = require('snippets.quick-union-rollback')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'quick_union_rollback',
namr = 'quick_union_rollback',
dscr = 'Union Find (with Rollback)',
},{
text(lines(quick_union_rollback))
})
}
})
local sparse_table = require('snippets.sparse-table')
ls.add_snippets(nil, {
cpp = {
@ -339,3 +352,17 @@ ls.add_snippets(nil, {
})
}
})
local hierholzer = require('snippets.hierholzer')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'hierholzer',
namr = 'hierholzer',
dscr = 'Find Euler path',
},{
text(lines(hierholzer))
})
}
})

View File

@ -0,0 +1,46 @@
return [=[
class quick_union {
public:
size_t n;
vector<size_t> c, sz;
vector<pair<size_t, size_t>> history;
public:
quick_union(size_t n) : n(n), c(n), sz(n) {
iota(c.begin(), c.end(), 0);
sz.assign(n, 1);
}
size_t query(size_t i) {
if (c[i] != i) return query(c[i]);
return c[i];
}
void merge(size_t i, size_t j) {
if (connected(i, j)) {
history.emplace_back(n, n);
} else {
i = query(i), j = query(j);
if (sz[i] > sz[j]) swap(i, j);
history.emplace_back(i, j);
sz[j] += sz[i];
c[i] = j;
}
}
bool connected(size_t i, size_t j) {
return query(i) == query(j);
}
size_t query_size(size_t i) {
return sz[query(i)];
}
void rollback() {
auto [i, j] = popback(history);
if (i == n and j == n) return;
c[i] = i;
sz[j] -= sz[i];
}
};
]=]

View File

@ -7,12 +7,12 @@ public:
iota(c.begin(), c.end(), 0);
sz.assign(n, 1);
}
size_t query(size_t i) {
if (c[i] != i) c[i] = query(c[i]);
return c[i];
}
void merge(size_t i, size_t j) {
if (connected(i, j)) return;
sz[query(j)] += sz[query(i)];