generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a2e480
commit f78d1a0
Showing
29 changed files
with
340 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef TIFALIBS_DS_DSU_DELINEATION | ||
#define TIFALIBS_DS_DSU_DELINEATION | ||
|
||
#include "../util/traits.hpp" | ||
|
||
namespace tifa_libs::ds { | ||
|
||
CEXP vvecu dsu_delineation(dsu_c auto& dsu) NE { | ||
const u32 n = dsu.size(); | ||
vvecu mp(n); | ||
flt_ (u32, u, 0, n) mp[(u32)dsu.find(u)].push_back(u); | ||
auto [l, r] = remove_if(mp, [](auto CR x) { return x.empty(); }); | ||
mp.erase(l, r); | ||
return mp; | ||
} | ||
|
||
} // namespace tifa_libs::ds | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef TIFALIBS_GRAPH_E_TCC | ||
#define TIFALIBS_GRAPH_E_TCC | ||
|
||
#include "../ds/dsu_basic.hpp" | ||
#include "../ds/dsu_delineation.hpp" | ||
#include "alist.hpp" | ||
|
||
namespace tifa_libs::graph { | ||
|
||
struct e_tcc { | ||
vecu dfn, low, post, path, deg; | ||
ds::dsu_basic<> dsu; | ||
vvecu belongs; | ||
|
||
//! g should be undirected | ||
template <bool with_deg> | ||
e_tcc(alist<with_deg> CR g) NE : dfn(g.size(), -1_u32), low(g.size()), post(g.size()), path(g.size(), -1_u32), deg(g.size()), dsu(g.size()) { | ||
const u32 n = g.size(); | ||
u32 tot = -1_u32; | ||
const auto dfs = [&](auto &&f, u32 u, u32 t = -1_u32) -> void { | ||
u32 pc{}; | ||
for (dfn[u] = low[u] = ++tot; u32 v : g[u]) { | ||
if (v == u || (v == t && !pc++)) continue; | ||
if (~dfn[v]) { | ||
if (dfn[v] < dfn[u]) { | ||
++deg[u], low[u] = std::min(low[u], dfn[v]); | ||
continue; | ||
} | ||
--deg[u]; | ||
for (auto &p = path[u]; ~p && dfn[p] <= dfn[v] && dfn[v] <= post[p]; p = path[p]) | ||
dsu.merge(u, p), deg[u] += deg[p]; | ||
continue; | ||
} | ||
if (f(f, v, u); !~path[v] && deg[v] <= 1) { | ||
low[u] = min(low[u], low[v]), deg[u] += deg[v]; | ||
continue; | ||
} | ||
if (!deg[v]) v = path[v]; | ||
if (low[u] > low[v]) low[u] = min(low[u], low[v]), swap(v, path[u]); | ||
for (; ~v; v = path[v]) dsu.merge(u, v), deg[u] += deg[v]; | ||
} | ||
post[u] = tot; | ||
}; | ||
flt_ (u32, u, 0, n) | ||
if (!~dfn[u]) dfs(dfs, u); | ||
belongs = ds::dsu_delineation(dsu); | ||
} | ||
}; | ||
|
||
} // namespace tifa_libs::graph | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: dsu_delineation | ||
documentation_of: //src/code/ds/dsu_delineation.hpp | ||
--- |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: e_tcc | ||
documentation_of: //src/code/graph/e_tcc.hpp | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: hld | ||
documentation_of: //src/code/tree/hld.hpp | ||
--- |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
\paragraph{样例一图片} | ||
|
||
\begin{center} | ||
\includegraphics[width=0.4\textwidth]{img/luogu-P6658-1.png} | ||
\end{center} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_5_D" | ||
|
||
#include "../../code/io/fastin.hpp" | ||
#include "../../code/io/fastout.hpp" | ||
#include "../../code/tree/hld.hpp" | ||
|
||
using T = std::pair<i64, i32>; | ||
using F = i64; | ||
|
||
T op(T a, T b) { return T{a.first + b.first, a.second + b.second}; } | ||
void mapping(T& a, F f) { a.first += f; } | ||
void composition(F& f, F g) { f += g; } | ||
|
||
int main() { | ||
u32 n, q; | ||
tifa_libs::fin >> n; | ||
vecii b(n, 0); | ||
vec<T> a(n); | ||
tifa_libs::graph::tree tr_(n); | ||
for (u32 u = 0, k; u < n; ++u) { | ||
tifa_libs::fin >> k; | ||
for (u32 i = 0, v; i < k; ++i) tifa_libs::fin >> v, tr_.add_edge(u, v); | ||
} | ||
tifa_libs::graph::hld<T, op, F, mapping, composition> tr({0, 0}, 0, tr_); | ||
flt_ (u32, i, 0, n) a[tr.info.dfn[i]].first = b[i], a[tr.info.dfn[i]].second = 1; | ||
tr.build(a); | ||
tifa_libs::fin >> q; | ||
for (u32 i = 0, opt, u; i < q; ++i) { | ||
tifa_libs::fin >> opt >> u; | ||
if (opt == 0) { | ||
i64 x; | ||
tifa_libs::fin >> x; | ||
tr.node_update((u32)u, x); | ||
} else { | ||
tifa_libs::fout << tr.chain_query((u32)u, 0).first << '\n'; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_5_E" | ||
|
||
#include "../../code/io/fastin.hpp" | ||
#include "../../code/io/fastout.hpp" | ||
#include "../../code/tree/hld.hpp" | ||
|
||
using T = std::pair<i64, i32>; | ||
using F = i64; | ||
|
||
T op(T a, T b) { return T{a.first + b.first, a.second + b.second}; } | ||
void mapping(T& a, F f) { a.first += f * a.second; } | ||
void composition(F& f, F g) { f += g; } | ||
|
||
int main() { | ||
u32 n, q; | ||
tifa_libs::fin >> n; | ||
vecii b(n, 0); | ||
vec<T> a(n); | ||
tifa_libs::graph::tree tr_(n); | ||
for (u32 u = 0, k; u < n; ++u) { | ||
tifa_libs::fin >> k; | ||
for (u32 i = 0, v; i < k; ++i) tifa_libs::fin >> v, tr_.add_edge(u, v); | ||
} | ||
tifa_libs::graph::hld<T, op, F, mapping, composition> tr({0, 0}, 0, tr_); | ||
flt_ (u32, i, 0, n) a[tr.info.dfn[i]].first = b[i], a[tr.info.dfn[i]].second = 1; | ||
tr.build(a); | ||
tifa_libs::fin >> q; | ||
for (u32 i = 0, opt, u; i < q; ++i) { | ||
tifa_libs::fin >> opt >> u; | ||
if (opt == 0) { | ||
i64 x; | ||
tifa_libs::fin >> x; | ||
tr.chain_update((u32)u, 0, x); | ||
tr.node_update(0, -x); | ||
} else { | ||
tifa_libs::fout << tr.chain_query((u32)u, 0).first << '\n'; | ||
} | ||
} | ||
return 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test_cpverifier/library-checker-graph/three_edge_connected_components.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#define PROBLEM "https://judge.yosupo.jp/problem/three_edge_connected_components" | ||
|
||
#include "../../code/graph/e_tcc.hpp" | ||
|
||
int main() { | ||
std::cin.tie(nullptr)->std::ios::sync_with_stdio(false); | ||
u32 n, m; | ||
std::cin >> n >> m; | ||
tifa_libs::graph::alist g(n); | ||
for (u32 i = 0, u, v; i < m; ++i) { | ||
std::cin >> u >> v; | ||
g.add_edge(u, v); | ||
} | ||
tifa_libs::graph::e_tcc tcc(g); | ||
std::cout << tcc.belongs.size() << '\n'; | ||
for (auto &&b : tcc.belongs) { | ||
std::cout << b.size(); | ||
for (auto x : b) | ||
std::cout << ' ' << x; | ||
std::cout << '\n'; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.