Skip to content

Commit 9166938

Browse files
lrvideckisweb-flow
andauthored
Add cuts callback (#135)
* add cuts with callback * [auto-verifier] verify commit ebabb1b * golf and format * [auto-verifier] verify commit de0d02e * golf * [auto-verifier] verify commit 899e5be * update * [auto-verifier] verify commit 4fd3c4d * update config * golf * [auto-verifier] verify commit 422f8e5 * fix bug in script * name script after the commands it runs * format tests now * [auto-verifier] verify commit 023a617 * catch typo * simplify * reorder functions * ignore these again * fix typo * [auto-verifier] verify commit f90e8d6 * fix comment example init * fix docs again * [auto-verifier] verify commit 0a5a61f --------- Co-authored-by: GitHub <noreply@github.com>
1 parent ac4d0d0 commit 9166938

File tree

10 files changed

+90
-23
lines changed

10 files changed

+90
-23
lines changed

.github/workflows/programming_team_code_ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
run: oj-verify all --tle 60 --timeout 21600
3131

32-
check_format_lint:
32+
greps_clangformat_cppcheck:
3333
runs-on: ubuntu-latest
3434
steps:
3535
- uses: actions/checkout@v2
@@ -41,7 +41,7 @@ jobs:
4141
- name: Install dependencies
4242
run: sudo apt update && sudo apt install -y clang-format-19 cppcheck
4343
- name: checks format then lints
44-
run: make --directory=tests/ check_format_lint
44+
run: make --directory=tests/ greps_clangformat_cppcheck
4545

4646
clangtidy:
4747
runs-on: ubuntu-latest
@@ -101,7 +101,7 @@ jobs:
101101

102102
publish_ptc:
103103
runs-on: ubuntu-latest
104-
needs: [library_checker_aizu, check_format_lint, clangtidy, compile_gcc, compile_clang, files_without_tests, build_ptc]
104+
needs: [library_checker_aizu, greps_clangformat_cppcheck, clangtidy, compile_gcc, compile_clang, files_without_tests, build_ptc]
105105
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
106106
steps:
107107
- uses: actions/checkout@v2
@@ -119,7 +119,7 @@ jobs:
119119

120120
update_main:
121121
runs-on: ubuntu-latest
122-
needs: [library_checker_aizu, check_format_lint, clangtidy, compile_gcc, compile_clang, files_without_tests]
122+
needs: [library_checker_aizu, greps_clangformat_cppcheck, clangtidy, compile_gcc, compile_clang, files_without_tests]
123123
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
124124
steps:
125125
- uses: actions/checkout@v2

.verify-helper/timestamps.remote.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"tests/library_checker_aizu_tests/data_structures/bit_rupq.test.cpp": "2024-12-05 10:41:42 -0600",
1111
"tests/library_checker_aizu_tests/data_structures/bit_rurq.test.cpp": "2024-12-05 10:41:42 -0600",
1212
"tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp": "2024-12-14 19:50:29 -0600",
13-
"tests/library_checker_aizu_tests/data_structures/deque.test.cpp": "2024-12-14 15:47:13 -0600",
14-
"tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp": "2024-12-14 19:50:29 -0600",
15-
"tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp": "2024-12-14 15:47:13 -0600",
13+
"tests/library_checker_aizu_tests/data_structures/deque.test.cpp": "2025-06-23 03:31:40 -0600",
14+
"tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp": "2025-06-23 03:31:40 -0600",
15+
"tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp": "2025-06-23 03:31:40 -0600",
1616
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc.test.cpp": "2024-12-14 15:47:13 -0600",
1717
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc_lines.test.cpp": "2024-12-14 15:47:13 -0600",
1818
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_lines.test.cpp": "2024-12-14 15:47:13 -0600",
@@ -52,6 +52,7 @@
5252
"tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2024-12-05 10:41:42 -0600",
5353
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2025-02-10 23:30:47 -0700",
5454
"tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2024-12-14 19:50:29 -0600",
55+
"tests/library_checker_aizu_tests/graphs/cuts_callback.test.cpp": "2025-06-23 03:38:41 -0600",
5556
"tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2024-12-14 19:50:29 -0600",
5657
"tests/library_checker_aizu_tests/graphs/dijkstra_lib_checker.test.cpp": "2024-12-14 19:50:29 -0600",
5758
"tests/library_checker_aizu_tests/graphs/directed_cycle.test.cpp": "2025-02-10 23:30:47 -0700",

library/data_structures/deque_op/back.hpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

library/data_structures/deque_op/front.hpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

library/data_structures/deque_op/queue_only.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ template<class T, class F> struct deq {
1818
return op(l.back()[1], r.back()[1]);
1919
}
2020
int siz() { return sz(l) + sz(r); }
21-
void push_back(T elem) {
22-
r.push_back(
23-
{elem, empty(r) ? elem : op(r.back()[1], elem)});
24-
}
21+
T front() { return (empty(l) ? r[0] : l.back())[0]; }
22+
T back() { return (empty(r) ? l[0] : r.back())[0]; }
2523
void pop_front() {
2624
if (empty(l)) {
2725
vector<T> a(sz(r));
@@ -31,6 +29,10 @@ template<class T, class F> struct deq {
3129
}
3230
l.pop_back();
3331
}
32+
void push_back(T elem) {
33+
r.push_back(
34+
{elem, empty(r) ? elem : op(r.back()[1], elem)});
35+
}
3436
void rebuild(const vector<T>& a, int sz_le) {
3537
vector<T> presum(sz(a));
3638
partial_sum(rend(a) - sz_le, rend(a),
@@ -46,6 +48,4 @@ template<class T, class F> struct deq {
4648
}
4749
#include "deque.hpp"
4850
#include "index.hpp"
49-
#include "front.hpp"
50-
#include "back.hpp"
5151
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
//! https://cp-algorithms.com/graph/cutpoints.html
3+
//! @code
4+
//! {
5+
//! vector<vector<int>> adj(n);
6+
//! cuts_callback(adj, [&](const vi& nodes) {});
7+
//! }
8+
//! vector<basic_string<int>> adj(n);
9+
//! rep (i, 0, m) {
10+
//! int u, v;
11+
//! cin >> u >> v;
12+
//! u--, v--;
13+
//! adj[u] += v;
14+
//! adj[v] += u;
15+
//! }
16+
//! cuts_callback(adj, [&](const vi& nodes) {
17+
//! });
18+
//! @endcode
19+
//! @time O(n + m)
20+
//! @space O(n + m)
21+
void cuts_callback(const auto& adj, auto f) {
22+
int n = sz(adj), q = 0, s = 0;
23+
vi tin(n), st(n);
24+
auto dfs = [&](auto&& self, int v, int p) -> int {
25+
int low = tin[v] = ++q;
26+
for (int u : adj[v])
27+
if (u != p) {
28+
int siz = s, lu = 0;
29+
low = min(low,
30+
tin[u] ?: (lu = self(self, st[s++] = u, v)));
31+
if (lu >= tin[v]) {
32+
st[s++] = v;
33+
f(vi(siz + all(st) - n + s));
34+
s = siz;
35+
}
36+
}
37+
return low;
38+
};
39+
rep(i, 0, n) if (!tin[i]) dfs(dfs, i, i);
40+
}

tests/.config/.code_snippet_excluded_file_list

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ find_first.hpp
77
find_last.hpp
88
loops
99
kth_path.hpp
10-
back.hpp
1110
deque.hpp
12-
front.hpp
1311
index.hpp
1412
compare_substrings.hpp
1513
compare_suffixes.hpp

tests/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ help:
77
@echo " |"
88
@echo "make compile_commented_snippets | compile code in @code...@endcode comments"
99
@echo " |"
10-
@echo "make check_format_lint | checks format with clang-format, then cppcheck"
10+
@echo "make greps_clangformat_cppcheck | greps to catch various bad things, clang-format, cppcheck"
1111
@echo " |"
1212
@echo "make do_format | format with clang-format"
1313
@echo " |"
@@ -31,8 +31,8 @@ compile_gcc:
3131
compile_clang:
3232
./scripts/compile_clang.sh
3333

34-
check_format_lint:
35-
./scripts/check_format_lint.sh
34+
greps_clangformat_cppcheck:
35+
./scripts/greps_clangformat_cppcheck.sh
3636

3737
do_format:
3838
./scripts/do_format.sh
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/biconnected_components"
3+
#include "../template.hpp"
4+
#include "../../../library/graphs/bridges_cuts/cuts_callback.hpp"
5+
int main() {
6+
cin.tie(0)->sync_with_stdio(0);
7+
int n, m;
8+
cin >> n >> m;
9+
vector<basic_string<int>> adj(n);
10+
for (int i = 0; i < n; i++) adj[i] += i;
11+
for (int i = 0; i < m; i++) {
12+
int u, v;
13+
cin >> u >> v;
14+
adj[u] += v;
15+
adj[v] += u;
16+
}
17+
vector<bool> vis(n, 0);
18+
vector<vector<int>> all_bccs;
19+
cuts_callback(adj, [&](const vi& nodes_bcc) {
20+
for (int v : nodes_bcc) vis[v] = 1;
21+
all_bccs.push_back(nodes_bcc);
22+
});
23+
for (int i = 0; i < n; i++)
24+
if (!vis[i]) all_bccs.push_back({i});
25+
cout << ssize(all_bccs) << '\n';
26+
for (const vector<int>& other_nodes : all_bccs) {
27+
cout << ssize(other_nodes) << ' ';
28+
for (int v : other_nodes) cout << v << ' ';
29+
cout << '\n';
30+
}
31+
return 0;
32+
}

tests/scripts/check_format_lint.sh renamed to tests/scripts/greps_clangformat_cppcheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ find ../library/ library_checker_aizu_tests/ -name "*[A-Z]*" -or -name "*-*" |
3636
grep --invert-match "README" &&
3737
exit 1
3838

39-
clang-format-19 --dry-run --Werror --style=file:.config/.clang-format library_checker_aizu_tests/**/*.hpp ../library/**/*.hpp ../library/**/*.cpp || exit 1
39+
clang-format-19 --dry-run --Werror --style=file:.config/.clang-format library_checker_aizu_tests/**/*.hpp library_checker_aizu_tests/**/*.test.cpp ../library/**/*.hpp ../library/**/*.cpp || exit 1
4040

4141
git submodule init
4242
git submodule update

0 commit comments

Comments
 (0)