chore: backup

This commit is contained in:
subcrip 2024-05-20 14:46:53 +08:00
parent 42bda9b279
commit 6478be4f2d
Signed by: subcrip
SSH Key Fingerprint: SHA256:dFPFi68d8C87YkFkEBU4TkcrYRySWpekRR1hbnDWUCw
11 changed files with 548 additions and 25 deletions

View File

@ -29,7 +29,7 @@ xwayland {
# See https://wiki.hyprland.org/Configuring/Keywords/
# Set programs that you use
$terminal = alacritty
$terminal = kitty
$fileManager = thunar
$menu = wofi --show drun
@ -58,6 +58,7 @@ exec-once = udiskie &
exec-once = clash-verge
exec-once = dhcpcd
exec-once = sleep 5 && 1password --silent
exec-once = sleep 5 && dropbox
#############################
@ -74,7 +75,8 @@ env = XDG_SESSION_DESKTOP,wayland
env = EDITOR,vim
env = MOZ_ENABLE_WAYLAND,1
# env = GDK_BACKEND,"wayland,x11"
env = QT_QPA_PLATFORM,wayland;xcb
# env = QT_QPA_PLATFORM,wayland;xcb
env = QT_QPA_PLATFORM,"wayland;xcb"
env = QT_QPA_PLATFORMTHEME,qt5ct
env = QT_AUTO_SCREEN_SCALE_FACTOR,1
# env = QT_SCALE_FACTOR,1.2

View File

@ -1,6 +1,6 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "b152822e1a4bafb6bdf11a16cc26525cbd95ee00" },
"LuaSnip": { "branch": "master", "commit": "de1a287c9cb525ae52bc846e8f6207e5ef1da5ac" },
"NeoColumn.nvim": { "branch": "main", "commit": "db7695c7c70fcacd290712deef659bca464634ee" },
"arshamiser.nvim": { "branch": "master", "commit": "13af62f49e5c906589aba48b338267c9ef6e2a8e" },
"arshlib.nvim": { "branch": "master", "commit": "e76e35c927098d07445c72e9416cce243f6aae59" },
@ -12,52 +12,50 @@
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
"cmp-emoji": { "branch": "main", "commit": "e8398e2adf512a03bb4e1728ca017ffeac670a9f" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"codesnap.nvim": { "branch": "main", "commit": "a223fd882953e56ae1a8747fdc44b8d6a2ff7a9b" },
"cphelper.nvim": { "branch": "main", "commit": "ab259315496514d58b2021048ef40437ad0f5814" },
"diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" },
"dressing.nvim": { "branch": "master", "commit": "5162edb1442a729a885c45455a07e9a89058be2f" },
"dressing.nvim": { "branch": "master", "commit": "572314728cb1ce012e825fd66331f52c94acac12" },
"eslint.nvim": { "branch": "main", "commit": "158f2289907d377018752fcfe0d61b746dc11767" },
"feline.nvim": { "branch": "master", "commit": "3587f57480b88e8009df7b36dc84e9c7ff8f2c49" },
"fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" },
"fzf-lua": { "branch": "main", "commit": "7109a18dd1832703209fc8f46e85df3c6ed6d059" },
"fzf-lua": { "branch": "main", "commit": "53698d7ff093592228d14a509933ce403b3b8f9f" },
"git-conflict.nvim": { "branch": "main", "commit": "4c8e252b87d54d944c1e56bfb477f78b6fdaf661" },
"gitsigns.nvim": { "branch": "main", "commit": "805610a9393fa231f2c2b49cb521bfa413fadb3d" },
"goto-preview": { "branch": "main", "commit": "3552fad4a0244ffd9ac86508e29ccc5166f19eb8" },
"heirline.nvim": { "branch": "master", "commit": "c52391dc4428d503f65e6bcb1533e6334f22a136" },
"hlargs.nvim": { "branch": "main", "commit": "0ee7783f9f40a6dd15fbb4e497b24818342a9940" },
"hop.nvim": { "branch": "master", "commit": "059e88e9dcaad3280ea1fd5c757f6904f274aed5" },
"image.nvim": { "branch": "master", "commit": "66af29f7244256eea82b2583ab65c2fab0567d0d" },
"indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" },
"lazy.nvim": { "branch": "main", "commit": "758bb5de98b805acc5eeed8cdc8ac7f0bc4b0b86" },
"leetcode.nvim": { "branch": "master", "commit": "458da8ea7e73e8ed221165aa56a595e33c4ec644" },
"legendary.nvim": { "branch": "master", "commit": "33108b19edadee8c2758f6bc574cc8335fdf89fb" },
"image.nvim": { "branch": "master", "commit": "da64ce69598875c9af028afe129f916b02ccc42e" },
"indent-blankline.nvim": { "branch": "master", "commit": "171d4d5a1560ccb556e94aa6df7e969068384049" },
"lazy.nvim": { "branch": "main", "commit": "c717ab88ff47830845a1e422a1d6495c764fac1d" },
"legendary.nvim": { "branch": "master", "commit": "38d1f3950792295c38b8ce33d134ace3ad75a9a1" },
"lsp-inlayhints.nvim": { "branch": "main", "commit": "d981f65c9ae0b6062176f0accb9c151daeda6f16" },
"lsp_signature.nvim": { "branch": "master", "commit": "aed5d1162b0f07bb3af34bedcc5f70a2b6466ed8" },
"lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"marks.nvim": { "branch": "master", "commit": "74e8d01b2a2131b6e46354cffc553aa7f81bcf5b" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" },
"mason.nvim": { "branch": "main", "commit": "49ff59aded1047a773670651cfa40e76e63c6377" },
"melange-nvim": { "branch": "master", "commit": "95ec2aee0d3e88e8d9d338ecd60d32a36e8f6bdb" },
"melange-nvim": { "branch": "master", "commit": "3d787ca41e98be6bdc95e71ac5ad425082d37406" },
"modicator.nvim": { "branch": "main", "commit": "780ea1e98c9bee8f3816685213b0aac42b34cd75" },
"monokai": { "branch": "master", "commit": "aafde73a622435891d36b411d8623e705ead6293" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "7aad1bf3f6b849cbf108e02c55ad4d701cb4d33a" },
"neodev.nvim": { "branch": "main", "commit": "ce9a2e8eaba5649b553529c5498acb43a6c317cd" },
"neogit": { "branch": "master", "commit": "bc0c609e3568a171e0549b449aa1b2b4b5b20e8c" },
"nui.nvim": { "branch": "main", "commit": "a3597dc88b53489d3fddbddbbd13787355253bb0" },
"neogit": { "branch": "master", "commit": "8cd0b5c4f1ca5e7b15c90f6cb1d6c37d931e9ad4" },
"nui.nvim": { "branch": "main", "commit": "b1b3dcd6ed8f355c78bad3d395ff645be5f8b6ae" },
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },
"nvim-autopairs": { "branch": "master", "commit": "14e97371b2aab6ee70054c1070a123dfaa3e217e" },
"nvim-cmp": { "branch": "main", "commit": "24122371810089d390847d8ba66325c1f1aa64c0" },
"nvim-autopairs": { "branch": "master", "commit": "b0b79e42a28f09719a7da9534c3731fa37319d9b" },
"nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" },
"nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" },
"nvim-lspconfig": { "branch": "master", "commit": "94513a5b246cf32a8f87ca714af50911df63351c" },
"nvim-lspconfig": { "branch": "master", "commit": "6d2ae9fdc3111a6e8fd5db2467aca11737195a30" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
"nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" },
"nvim-numbertoggle": { "branch": "main", "commit": "c5827153f8a955886f1b38eaea6998c067d2992f" },
"nvim-surround": { "branch": "main", "commit": "6d0dc3dbb557bcc6a024969da461df4ba803fc48" },
"nvim-treesitter": { "branch": "master", "commit": "f224fef9d28e1fd30ccd9a9c374ced2546dde6ea" },
"nvim-treesitter-context": { "branch": "master", "commit": "df58c81237ffe2b277e14a1692212162a34e2e2a" },
"nvim-surround": { "branch": "main", "commit": "79aaa42da1f698ed31bcbe7f83081f69dca7ba17" },
"nvim-treesitter": { "branch": "master", "commit": "1eabe69bfa8f78e14fcf5d42a2b3881babaca30a" },
"nvim-treesitter-context": { "branch": "master", "commit": "55e29081e73d2e4b2d62fb4dc3eebe21bf66a1e2" },
"nvim-web-devicons": { "branch": "master", "commit": "e37bb1feee9e7320c76050a55443fa843b4b6f83" },
"outline.nvim": { "branch": "main", "commit": "dbd836893fb99cfc33119d7c4abbdb700210f54b" },
"plenary.nvim": { "branch": "master", "commit": "08e301982b9a057110ede7a735dd1b5285eb341f" },
@ -70,7 +68,7 @@
"twilight.nvim": { "branch": "main", "commit": "8b7b50c0cb2dc781b2f4262a5ddd57571556d1e4" },
"usage-tracker.nvim": { "branch": "main", "commit": "739532b069e0d829b45ede989c657ac32a2141a6" },
"vim-cursorword": { "branch": "master", "commit": "34852083276c1fd9ff4cccaf052111e7d5a2472e" },
"vim-fugitive": { "branch": "master", "commit": "ce882460cf3db12e99f8bf579cbf99e331f6dd4f" },
"vim-fugitive": { "branch": "master", "commit": "5a9bd42dd8dd127779f3cd8982a0419b7ca9c7f5" },
"vim-obsession": { "branch": "master", "commit": "fe9d3e1a9a50171e7d316a52e1e56d868e4c1fe5" },
"vim-prosession": { "branch": "master", "commit": "1cb2eadde0b79f49eb4b5a54cc78735aea33cbca" },
"vim-visual-multi": { "branch": "master", "commit": "b84a6d42c1c10678928b0bf8327f378c8bc8af5a" },

View File

@ -300,7 +300,7 @@ local plugins = {
},
{ 'Civitasv/cmake-tools.nvim' },
{ 'p00f/cphelper.nvim' },
{ "arielherself/melange-nvim"},
{ "arielherself/melange-nvim", commit = "3d787ca" },
{ 'hrsh7th/vim-vsnip' },
{
"NeogitOrg/neogit",
@ -936,3 +936,5 @@ require('goto-preview').setup {
}
require('colorizer').setup {}
require('ibl').setup {}

View File

@ -0,0 +1,86 @@
return [=[
struct bounded_flow {
int n, m, S, T;
dinic net;
ll sum;
vector<ll> fl;
vector<ll> init;
bounded_flow(int n, int m) : sum(0), n(n), m(m), S(0), T(n + 1), net(n + 1), fl(m), init(n + 1) {}
void add_edge(int from, int to, ll low, ll high, int edge_id = -1) {
if (edge_id != -1) {
fl[edge_id] += low;
}
net.add_edge(from, to, high - low, edge_id, -1);
init[to] += low, init[from] -= low;
}
void prep(int s, int t) {
for (int i = 1; i <= n; ++i) {
if (init[i] > 0) {
net.add_edge(S, i, init[i], -1, -1);
sum += init[i];
} else if (init[i] < 0) {
net.add_edge(i, T, -init[i], -1, -1);
}
}
net.add_edge(t, s, INFLL, INF, -1);
}
optional<pair<ll, vector<ll>>> run_max_flow(int s, int t) {
prep(s, t);
if (sum != net.run(S, T)) {
return nullopt;
} else {
auto res_flow = net.run(s, t);
for (int from = 1; from <= n; ++from) {
for (auto&& [to, cap, flow, rev, mark] : net.edges[from]) {
if (mark != -1 and mark != INF) {
fl[mark] += flow;
}
}
}
return {{res_flow, fl}};
}
}
optional<pair<ll, vector<ll>>> run_min_flow(int s, int t) {
prep(s, t);
if (sum != net.run(S, T)) {
return nullopt;
} else {
int curr;
for (int i = 0; i < m; ++i) {
if (net.edges[t][i].mark == INF) {
net.edges[t][i].cap = 0;
net.edges[net.edges[t][i].to][net.edges[t][i].rev].cap = 0;
curr = net.edges[t][i].flow; // WARN: real flow
break;
}
}
curr -= net.run(t, s);
for (int from = 1; from <= n; ++from) {
for (auto&& [to, cap, flow, rev, mark] : net.edges[from]) {
if (mark != -1 and mark != INF) {
fl[mark] += flow;
}
}
}
return {{curr, fl}};
}
}
optional<pair<ll, vector<ll>>> run_flow(int s, int t) { // BUG: unchecked code
prep(s, t);
auto res_flow = net.run(S, T);
if (sum != res_flow) {
return nullopt;
} else {
for (int from = 1; from <= n; ++from) {
for (auto&& [to, cap, flow, rev, mark] : net.edges[from]) {
if (mark != -1 and mark != INF) {
fl[mark] += flow;
}
}
}
return {{res_flow, fl}};
}
}
};
]=]

View File

@ -0,0 +1,86 @@
return [=[
struct bounded_mcmf {
int n, m, S, T;
mcmf net;
ll sum;
vector<ll> fl;
vector<ll> init;
vector<ll> costs;
bounded_mcmf(int n, int m) : sum(0), n(n), m(m), S(0), T(n + 1), net(n + 1), fl(m), init(n + 1), costs(m) {}
// handle negative loop case
void add_edge(int from, int to, ll low, ll high, ll cost, int edge_id = -1) {
if (cost < 0) {
__add_edge(from, to, high, high, cost, -1);
__add_edge(to, from, 0, high - low, -cost, edge_id);
} else {
__add_edge(from, to, low, high, cost, edge_id);
}
if (edge_id != -1) {
costs[edge_id] = cost;
if (cost < 0) {
fl[edge_id] += high; // RealFlow = UpperBound - Flow
} else {
fl[edge_id] += low; // RealFlow = LowerBound + Flow
}
}
}
void __add_edge(int from, int to, ll low, ll high, ll cost, int edge_id = -1) {
net.add_edge(from, to, high - low, cost, edge_id, -1);
init[to] += low, init[from] -= low;
}
void prep(int s, int t) {
for (int i = 1; i <= n; ++i) {
if (init[i] > 0) {
net.add_edge(S, i, init[i], 0, -1, -1);
sum += init[i];
} else if (init[i] < 0) {
net.add_edge(i, T, -init[i], 0, -1, -1);
}
}
net.add_edge(t, s, INFLL, 0, -1, -1);
}
// min-cost max-flow
optional<tuple<ll, ll, vector<ll>>> run_mcmf(int s, int t) { // BUG: unchecked code
prep(s, t);
if (sum != net.run(S, T).first) {
return nullopt;
} else {
auto [res_flow, res_cost] = net.run(s, t);
for (int from = 1; from <= n; ++from) {
for (auto&& [to, cap, flow, cost, rev, mark] : net.edges[from]) {
if (mark != -1) {
if (costs[mark] < 0) {
fl[mark] -= flow;
} else {
fl[mark] += flow;
}
}
}
}
return {{res_flow, res_cost, fl}};
}
}
// min-cost flow
optional<tuple<ll, ll, vector<ll>>> run_mcf(int s, int t) {
prep(s, t);
auto [res_flow, res_cost] = net.run(S, T);
if (sum != res_flow) {
return nullopt;
} else {
for (int from = 1; from <= n; ++from) {
for (auto&& [to, cap, flow, cost, rev, mark] : net.edges[from]) {
if (mark != -1) {
if (costs[mark] < 0) {
fl[mark] -= flow;
} else {
fl[mark] += flow;
}
}
}
}
return {{res_flow, res_cost, fl}};
}
}
};
]=]

View File

@ -0,0 +1,74 @@
return [=[
struct dinic {
struct edge {
int to;
ll cap;
ll flow;
int rev;
int mark;
};
vector<vector<edge>> edges;
vector<int> layer;
vector<bool> vis;
dinic(int n) : edges(n + 1), layer(n + 1), vis(n + 1) {}
void add_edge(int from, int to, ll cap, int mark = 0, int mark_rev = 0) {
edges[from].push_back({ to, cap, 0, int(edges[to].size()), mark });
edges[to].push_back({ from, 0, 0, int(edges[from].size() - 1), mark_rev });
}
bool bfs(int s, int t) {
layer.assign(edges.size(), 0);
deque<pii> dq;
layer[s] = 1;
dq.emplace_back(s, 1);
while (dq.size()) {
popfront(dq, v, l);
for (auto&& e : edges[v]) {
if (layer[e.to] == 0 and e.cap > e.flow) {
layer[e.to] = l + 1;
dq.emplace_back(e.to, l + 1);
}
}
}
return layer[t] != 0;
}
ll dfs(int s, int t, ll cap) {
if (vis[s]) {
return 0;
}
vis[s] = 1;
if (s == t) {
return cap;
}
ll res = 0;
int n = edges[s].size();
for (int i = 0; i < n; ++i) {
auto e = edges[s][i];
if (e.cap > e.flow and layer[e.to] == layer[s] + 1) {
ll nw = dfs(e.to, t, min(cap - res, e.cap - e.flow));
edges[s][i].flow += nw;
edges[e.to][e.rev].flow -= nw;
res += nw;
if (res == cap) {
return res;
}
}
}
return res;
}
ll run(int s, int t) {
ll res = 0;
while (bfs(s, t)) {
vis.assign(edges.size(), 0);
res += dfs(s, t, LLONG_MAX);
}
return res;
}
};
]=]

View File

@ -0,0 +1,59 @@
return [=[
struct edmonds_karp {
struct edge {
int to;
ll cap;
ll flow;
pair<int, int> rev;
int mark;
};
vector<vector<edge>> edges;
edmonds_karp(int n) : edges(n + 1) {}
void add_edge(int from, int to, ll cap, int mark = 0, int mark_rev = 0) {
edges[from].push_back({to, cap, 0, make_pair(to, int(edges[to].size())), mark});
edges[to].push_back({from, 0, 0, make_pair(from, int(edges[from].size() - 1)), mark_rev});
}
ll run(int s, int t) {
int n = edges.size();
vector<pii> pa_(n + 1);
ll res = 0;
while (1) {
vector<ll> pf(n + 1);
deque<int> dq;
dq.emplace_back(s);
pf[s] = LLONG_MAX;
while (dq.size()) {
int v = dq.front(); dq.pop_front();
for (auto&& [i, ne] : enumerate(edges[v])) {
if (pf[ne.to] == 0 and ne.cap > ne.flow) {
pf[ne.to] = min(pf[v], ne.cap - ne.flow);
pa_[ne.to] = {v, i};
dq.emplace_back(ne.to);
}
}
if (pf[t] != 0) {
break;
}
}
if (pf[t] == 0) {
break;
}
int p = t;
while (pa_[p].first != 0) {
auto [x, y] = pa_[p];
edges[x][y].flow += pf[t];
auto [z, w] = edges[x][y].rev;
edges[z][w].flow -= pf[t];
p = x;
}
res += pf[t];
}
return res;
}
};
]=]

View File

@ -179,3 +179,63 @@ ls.add_snippets(nil, {
})
}
})
local edmonds_karp = require('snippets.edmonds-karp')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'edmonds_karp',
namr = 'edmonds_karp',
dscr = 'Max flow using Edmonds-Karp',
},{
text(lines(edmonds_karp))
})
}
})
local dinic = require('snippets.dinic')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'dinic',
namr = 'dinic',
dscr = 'Max flow using Dinic',
},{
text(lines(dinic))
})
}
})
local mcmf = require('snippets.mcmf')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'mcmf',
namr = 'mcmf',
dscr = 'Minimum cost max flow',
},{
text(lines(mcmf))
})
}
})
local bounded_mcmf = require('snippets.bounded-mcmf')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'bounded_mcmf',
namr = 'bounded_mcmf',
dscr = 'Minimum cost (max) flow with bounds',
},{
text(lines(bounded_mcmf))
})
}
})
local bounded_flow = require('snippets.bounded-flow')
ls.add_snippets(nil, {
cpp = {
snip({
trig = 'bounded_flow',
namr = 'bounded_flow',
dscr = 'Max/min-flow with bounds',
},{
text(lines(bounded_flow))
})
}
})

View File

@ -0,0 +1,81 @@
return [=[
struct mcmf {
struct edge {
int to;
ll cap;
ll flow;
ll cost;
int rev;
int mark;
};
vector<vector<edge>> edges;
vector<ll> dis;
vector<bool> vis;
ll ret;
mcmf(int n) : edges(n + 1), dis(n + 1), vis(n + 1) {}
void add_edge(int from, int to, ll cap, ll cost, int mark = 0, int mark_rev = 0) {
edges[from].push_back({ to, cap, 0, cost, int(edges[to].size()), mark });
edges[to].push_back({ from, 0, 0, -cost, int(edges[from].size() - 1), mark_rev });
}
bool sp(int s, int t) {
dis.assign(edges.size(), INFLL);
dis[s] = 0;
int n = edges.size();
int f = 1;
while (f) {
f = 0;
for (int i = 0; i < n; ++i) {
for (auto&& [to, cap, flow, cost, rev, mark] : edges[i]) {
if (cap > flow and dis[to] > dis[i] + cost) {
dis[to] = dis[i] + cost;
f = 1;
}
}
}
}
return dis[t] != INFLL;
}
ll dfs(int s, int t, ll cap) {
if (vis[s]) {
return 0;
}
vis[s] = 1;
if (s == t) {
return cap;
}
ll res = 0;
int n = edges[s].size();
for (int i = 0; i < n; ++i) {
auto e = edges[s][i];
if (e.cap > e.flow and dis[e.to] == dis[s] + e.cost) {
ll nw = dfs(e.to, t, min(cap - res, e.cap - e.flow));
edges[s][i].flow += nw;
edges[e.to][e.rev].flow -= nw;
res += nw;
ret += nw * e.cost;
if (res == cap) {
return res;
}
}
}
return res;
}
// returns: (flow, cost)
pll run(int s, int t) {
ll res = 0; ret = 0;
while (sp(s, t)) {
vis.assign(edges.size(), 0);
ll curr = dfs(s, t, LLONG_MAX);
res += curr;
}
return { res, ret };
}
};
]=]

View File

@ -1,5 +1,15 @@
return [=[
namespace tarjan {
struct mutex_cond {
int v1; bool cond1;
int v2; bool cond2;
mutex_cond(int v1, bool cond1, int v2, bool cond2) : v1(v1), cond1(cond1), v2(v2), cond2(cond2) {}
};
struct inclusive_cond {
int v1; bool cond1;
int v2; bool cond2;
inclusive_cond(int v1, bool cond1, int v2, bool cond2) : v1(v1), cond1(cond1), v2(v2), cond2(cond2) {}
};
// Returns the mapping between vertices and their affiliated sccs.
vector<int> scc(const vector<vector<int>>& ch) {
int n = ch.size();
@ -26,7 +36,6 @@ namespace tarjan {
}
return br;
}
// This method can eliminate redundant edges or self-loops
vector<vector<int>> build_scc(const vector<vector<int>>& ch) {
int n = ch.size();
@ -66,6 +75,72 @@ namespace tarjan {
}
return res;
}
// indices start from 1, result has `n` items
optional<vector<bool>> solve_twosat(int n, const vector<mutex_cond>& conditions) {
vector<vector<int>> ch(2 * n + 1);
for (auto&& [v1, cond1, v2, cond2] : conditions) {
ch[(1 ^ cond1) * n + v1].emplace_back(cond2 * n + v2);
ch[(1 ^ cond2) * n + v2].emplace_back(cond1 * n + v1);
}
auto sccno = scc(ch);
for (int i = 1; i <= n; ++i) {
if (sccno[i] == sccno[i + n]) {
return nullopt;
}
}
vector<bool> res;
for (int i = 1; i <= n; ++i) {
if (sccno[i] < sccno[i + n]) {
res.emplace_back(false);
} else {
res.emplace_back(true);
}
}
return res;
};
// indices start from 1, result has `n` items
optional<vector<bool>> solve_twosat(int n, const vector<inclusive_cond>& conditions) {
vector<mutex_cond> trans_conds;
for (auto&& [v1, cond1, v2, cond2] : conditions) {
trans_conds.emplace_back(v1, cond1, v2, not cond2);
}
return solve_twosat(n, trans_conds);
}
// Returns if each vertex is a cut vertex
// All indices start from 1
vector<int> cut_v(const vector<vector<int>>& ch) {
int n = ch.size() - 1;
vector<bool> vis(n + 1);
vector<int> low(n + 1), dfn(n + 1), flag(n + 1);
int cnt = 0;
auto dfs = [&] (auto dfs, int v, int pa) -> void {
vis[v] = 1;
low[v] = dfn[v] = ++cnt;
int child = 0;
for (auto&& u : ch[v]) {
if (not vis[u]) {
++child;
dfs(dfs, u, v);
low[v] = min(low[v], low[u]);
if (pa != v and low[u] >= dfn[v] and not flag[v]) {
flag[v] = 1;
}
} else if (u != pa) {
low[v] = min(low[v], dfn[u]);
}
}
if (pa == v and child >= 2 and not flag[v]) {
flag[v] = 1;
}
};
for (int i = 1; i <= n; ++i) {
if (not dfn[i]) {
dfs(dfs, i, 0);
}
}
return flag;
}
}
]=]

File diff suppressed because one or more lines are too long