Skip to content

Commit 933218a

Browse files
committed
Regenerate minified files with improved line joining
1 parent 719eaf7 commit 933218a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+74
-5066
lines changed

cp-algo/min/geometry/closest_pair.hpp

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,5 @@
44
#include "point.hpp"
55
#include <vector>
66
#include <map>
7-
namespace cp_algo::geometry{
8-
template<typename ftype>
9-
auto closest_pair(std::vector<point_t<ftype>>const&r){
10-
using point=point_t<ftype>;
11-
size_t n=size(r);
12-
int64_t md=1e18;
13-
for(size_t i=0;i<n/100;i++){
14-
auto A=random::rng()%n;
15-
auto B=random::rng()%n;
16-
if(A!=B){
17-
md=std::min(md,norm(r[A]-r[B]));
18-
if(md==0){
19-
return std::pair{A,B};
20-
}
21-
}
22-
}
23-
std::map<point,std::vector<size_t>>neigs;
24-
md=(int64_t)ceil(sqrt((double)md));
25-
for(size_t i=0;i<n;i++){
26-
neigs[r[i]/md].push_back(i);
27-
}
28-
size_t a=0,b=1;
29-
md=norm(r[a]-r[b]);
30-
for(auto&[p,id]:neigs){
31-
for(int dx:{-1,0,1}){
32-
for(int dy:{-1,0,1}){
33-
auto pp=p+point{dx,dy};
34-
if(!neigs.count(pp)){
35-
continue;
36-
}
37-
for(size_t i:neigs[pp]){
38-
for(size_t j:id){
39-
if(j==i){
40-
break;
41-
}
42-
int64_t cur=norm(r[i]-r[j]);
43-
if(cur<md){
44-
md=cur;
45-
a=i;
46-
b=j;
47-
}
48-
}
49-
}
50-
}
51-
}
52-
}
53-
return std::pair{a,b};
54-
}
55-
}
7+
namespace cp_algo::geometry{template<typename ftype>auto closest_pair(std::vector<point_t<ftype>>const&r){using point=point_t<ftype>;size_t n=size(r);int64_t md=1e18;for(size_t i=0;i<n/100;i++){auto A=random::rng()%n;auto B=random::rng()%n;if(A!=B){md=std::min(md,norm(r[A]-r[B]));if(md==0){return std::pair{A,B};}}}std::map<point,std::vector<size_t>>neigs;md=(int64_t)ceil(sqrt((double)md));for(size_t i=0;i<n;i++){neigs[r[i]/md].push_back(i);}size_t a=0,b=1;md=norm(r[a]-r[b]);for(auto&[p,id]:neigs){for(int dx:{-1,0,1}){for(int dy:{-1,0,1}){auto pp=p+point{dx,dy};if(!neigs.count(pp)){continue;}for(size_t i:neigs[pp]){for(size_t j:id){if(j==i){break;}int64_t cur=norm(r[i]-r[j]);if(cur<md){md=cur;a=i;b=j;}}}}}}return std::pair{a,b};}}
568
#endif

cp-algo/min/geometry/convex_hull.hpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,5 @@
55
#include <utility>
66
#include <vector>
77
#include <ranges>
8-
namespace cp_algo::geometry{
9-
template<typename ftype>
10-
std::vector<point_t<ftype>>convex_hull(std::vector<point_t<ftype>>r){
11-
using point=point_t<ftype>;
12-
std::ranges::sort(r);
13-
if(size(r)<=1||r[0]==r.back()){
14-
return empty(r)?r:std::vector{r[0]};
15-
}
16-
std::vector<point>hull={r[0]};
17-
for(int half:{0,1}){
18-
size_t base=size(hull);
19-
for(auto it:std::views::drop(r,1)){
20-
while(size(hull)>=base+1){
21-
point a=hull.back();
22-
if(point::ccw(it-a,end(hull)[-2]-a)){
23-
break;
24-
}else{
25-
hull.pop_back();
26-
}
27-
}
28-
hull.push_back(it);
29-
}
30-
std::ranges::reverse(r);
31-
std::ignore=half;
32-
}
33-
hull.pop_back();
34-
return hull;
35-
}
36-
}
8+
namespace cp_algo::geometry{template<typename ftype>std::vector<point_t<ftype>>convex_hull(std::vector<point_t<ftype>>r){using point=point_t<ftype>;std::ranges::sort(r);if(size(r)<=1||r[0]==r.back()){return empty(r)?r:std::vector{r[0]};}std::vector<point>hull={r[0]};for(int half:{0,1}){size_t base=size(hull);for(auto it:std::views::drop(r,1)){while(size(hull)>=base+1){point a=hull.back();if(point::ccw(it-a,end(hull)[-2]-a)){break;}else{hull.pop_back();}}hull.push_back(it);}std::ranges::reverse(r);std::ignore=half;}hull.pop_back();return hull;}}
379
#endif

cp-algo/min/geometry/point.hpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,5 @@
22
#define CP_ALGO_GEOMETRY_POINT_HPP
33
#include "../util/complex.hpp"
44
#include <iostream>
5-
namespace cp_algo::geometry{
6-
template<typename ftype>
7-
struct point_t:complex<ftype>{
8-
using Base=complex<ftype>;
9-
using Base::Base;
10-
point_t(Base const&t):Base(t){}
11-
auto operator<=>(point_t const&t)const{
12-
return std::pair{y(),-x()}<=>std::pair{t.y(),-t.x()};
13-
}
14-
ftype x()const{return Base::real();}
15-
ftype y()const{return Base::imag();}
16-
point_t cmul(point_t const&t)const{return conj(*this)*t;}
17-
ftype dot(point_t const&t)const{return cmul(t).x();}
18-
ftype cross(point_t const&t)const{return cmul(t).y();}
19-
static constexpr point_t O={0,0};
20-
int half()const{
21-
return*this<O?-1:*this==O?0:1;
22-
}
23-
static bool ccw(point_t const&a,point_t const&b){
24-
return a.cross(b)>0;
25-
}
26-
static bool ccw_abs(point_t const&a,point_t const&b){
27-
return std::tuple{a.half(),(ftype)0,norm(a)}<
28-
std::tuple{b.half(),a.cross(b),norm(b)};
29-
}
30-
void read(){
31-
ftype _x,_y;
32-
std::cin>>_x>>_y;
33-
*this={_x,_y};
34-
}
35-
void print()const{
36-
std::cout<<x()<<' '<<y()<<"\n";
37-
}
38-
};
39-
}
5+
namespace cp_algo::geometry{template<typename ftype>struct point_t:complex<ftype>{using Base=complex<ftype>;using Base::Base;point_t(Base const&t):Base(t){}auto operator<=>(point_t const&t)const{return std::pair{y(),-x()}<=>std::pair{t.y(),-t.x()};}ftype x()const{return Base::real();}ftype y()const{return Base::imag();}point_t cmul(point_t const&t)const{return conj(*this)*t;}ftype dot(point_t const&t)const{return cmul(t).x();}ftype cross(point_t const&t)const{return cmul(t).y();}static constexpr point_t O={0,0};int half()const{return*this<O?-1:*this==O?0:1;}static bool ccw(point_t const&a,point_t const&b){return a.cross(b)>0;}static bool ccw_abs(point_t const&a,point_t const&b){return std::tuple{a.half(),(ftype)0,norm(a)}<std::tuple{b.half(),a.cross(b),norm(b)};}void read(){ftype _x,_y;std::cin>>_x>>_y;*this={_x,_y};}void print()const{std::cout<<x()<<' '<<y()<<"\n";}};}
406
#endif

cp-algo/min/graph/base.hpp

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,5 @@
44
#include "concepts.hpp"
55
#include "../structures/stack_union.hpp"
66
#include <ranges>
7-
namespace cp_algo::graph{
8-
using edge_index=int;
9-
template<edge_type _edge_t=edge_base,graph_mode _mode=undirected>
10-
struct graph{
11-
using edge_t=_edge_t;
12-
static constexpr auto mode=_mode;
13-
using incidence_list=structures::stack_union<edge_index>;
14-
graph(int n,int v0=0):v0(v0),adj(n){}
15-
graph transpose()const{
16-
static_assert(mode==directed,"transpose is only defined for directed graphs");
17-
graph<edge_t,mode>gt(n(),v0);
18-
for(auto v:nodes()){
19-
for(auto e:outgoing(v)){
20-
gt.add_edge(edge(e).traverse(v),edge(e));
21-
}
22-
}
23-
return gt;
24-
}
25-
edge_index add_edge(node_index u,edge_t e){
26-
edge_index idx=(edge_index)size(E);
27-
E.push_back(e);
28-
adj.push(u,idx);
29-
if constexpr(mode==undirected){
30-
adj.push(e.traverse(u),idx);
31-
}
32-
return idx;
33-
}
34-
edge_index add_edge(node_index u,auto... Args){
35-
return add_edge(u,edge_t(u,Args...));
36-
}
37-
void read_edges(node_index m){
38-
adj.reserve(mode==undirected?2*m:m);
39-
for(edge_index i=0;i<m;i++){
40-
auto[u,e]=edge_t::read(v0);
41-
add_edge(u,e);
42-
}
43-
}
44-
auto outgoing(node_index v)const{return adj[v];}
45-
auto edges()const{return E|std::views::all;}
46-
auto nodes()const{return std::views::iota(node_index(0),n());}
47-
auto edge_indices()const{return std::views::iota(edge_index(0),m());}
48-
auto&&incidence_lists(this auto&&self){return self.adj;}
49-
auto&&edge(this auto&&self,edge_index e){return self.E[e];}
50-
node_index n()const{return(node_index)incidence_lists().size();}
51-
edge_index m()const{return(edge_index)edges().size();}
52-
private:
53-
node_index v0;
54-
big_vector<edge_t>E;
55-
incidence_list adj;
56-
};
57-
template<edge_type edge_t=edge_base>
58-
using digraph=graph<edge_t,directed>;
59-
template<weighted_edge_type edge_t=weighted_edge,graph_mode mode=undirected>
60-
using weighted_graph=graph<edge_t,mode>;
61-
template<weighted_edge_type edge_t=weighted_edge>
62-
using weighted_digraph=digraph<edge_t>;
63-
}
7+
namespace cp_algo::graph{using edge_index=int;template<edge_type _edge_t=edge_base,graph_mode _mode=undirected>struct graph{using edge_t=_edge_t;static constexpr auto mode=_mode;using incidence_list=structures::stack_union<edge_index>;graph(int n,int v0=0):v0(v0),adj(n){}graph transpose()const{static_assert(mode==directed,"transpose is only defined for directed graphs");graph<edge_t,mode>gt(n(),v0);for(auto v:nodes()){for(auto e:outgoing(v)){gt.add_edge(edge(e).traverse(v),edge(e));}}return gt;}edge_index add_edge(node_index u,edge_t e){edge_index idx=(edge_index)size(E);E.push_back(e);adj.push(u,idx);if constexpr(mode==undirected){adj.push(e.traverse(u),idx);}return idx;}edge_index add_edge(node_index u,auto... Args){return add_edge(u,edge_t(u,Args...));}void read_edges(node_index m){adj.reserve(mode==undirected?2*m:m);for(edge_index i=0;i<m;i++){auto[u,e]=edge_t::read(v0);add_edge(u,e);}}auto outgoing(node_index v)const{return adj[v];}auto edges()const{return E|std::views::all;}auto nodes()const{return std::views::iota(node_index(0),n());}auto edge_indices()const{return std::views::iota(edge_index(0),m());}auto&&incidence_lists(this auto&&self){return self.adj;}auto&&edge(this auto&&self,edge_index e){return self.E[e];}node_index n()const{return(node_index)incidence_lists().size();}edge_index m()const{return(edge_index)edges().size();}private:node_index v0;big_vector<edge_t>E;incidence_list adj;};template<edge_type edge_t=edge_base>using digraph=graph<edge_t,directed>;template<weighted_edge_type edge_t=weighted_edge,graph_mode mode=undirected>using weighted_graph=graph<edge_t,mode>;template<weighted_edge_type edge_t=weighted_edge>using weighted_digraph=digraph<edge_t>;}
648
#endif

cp-algo/min/graph/concepts.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,5 @@
22
#define CP_ALGO_GRAPH_CONCEPTS_HPP
33
#include "edge_types.hpp"
44
#include <type_traits>
5-
namespace cp_algo::graph{
6-
enum graph_mode{directed,undirected};
7-
template<typename T,typename=void>
8-
struct graph_traits:std::false_type{};
9-
template<typename T>
10-
struct graph_traits<T,std::void_t<typename T::edge_t,decltype(T::mode)>>:std::true_type{
11-
using edge_t=typename T::edge_t;
12-
static constexpr auto mode=T::mode;
13-
static constexpr bool is_directed=mode==directed;
14-
static constexpr bool is_undirected=mode==undirected;
15-
static constexpr bool is_weighted=weighted_edge_type<edge_t>;
16-
};
17-
template<typename G>
18-
concept graph_type=graph_traits<G>::value;
19-
template<typename G>
20-
concept digraph_type=graph_type<G>&&graph_traits<G>::is_directed;
21-
template<typename G>
22-
concept undirected_graph_type=graph_type<G>&&graph_traits<G>::is_undirected;
23-
template<typename G>
24-
concept weighted_graph_type=graph_type<G>&&graph_traits<G>::is_weighted;
25-
template<typename G>
26-
concept weighted_digraph_type=digraph_type<G>&&graph_traits<G>::is_weighted;
27-
template<typename G>
28-
concept weighted_undirected_graph_type=undirected_graph_type<G>&&graph_traits<G>::is_weighted;
29-
}
5+
namespace cp_algo::graph{enum graph_mode{directed,undirected};template<typename T,typename=void>struct graph_traits:std::false_type{};template<typename T>struct graph_traits<T,std::void_t<typename T::edge_t,decltype(T::mode)>>:std::true_type{using edge_t=typename T::edge_t;static constexpr auto mode=T::mode;static constexpr bool is_directed=mode==directed;static constexpr bool is_undirected=mode==undirected;static constexpr bool is_weighted=weighted_edge_type<edge_t>;};template<typename G>concept graph_type=graph_traits<G>::value;template<typename G>concept digraph_type=graph_type<G>&&graph_traits<G>::is_directed;template<typename G>concept undirected_graph_type=graph_type<G>&&graph_traits<G>::is_undirected;template<typename G>concept weighted_graph_type=graph_type<G>&&graph_traits<G>::is_weighted;template<typename G>concept weighted_digraph_type=digraph_type<G>&&graph_traits<G>::is_weighted;template<typename G>concept weighted_undirected_graph_type=undirected_graph_type<G>&&graph_traits<G>::is_weighted;}
306
#endif

cp-algo/min/graph/cycle.hpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,5 @@
33
#include "dfs.hpp"
44
#include "base.hpp"
55
#include <deque>
6-
namespace cp_algo::graph{
7-
template<graph_type graph>
8-
struct cycle_context:dfs_context<graph>{
9-
using base=dfs_context<graph>;
10-
using base::base;
11-
std::deque<edge_index>cycle;
12-
bool closed=false;
13-
int v0;
14-
void on_return_from_child(node_index v,edge_index e){
15-
if(!empty(cycle)&&!closed){
16-
cycle.push_front(e);
17-
closed|=v==v0;
18-
}
19-
}
20-
void on_back_edge(node_index v,edge_index e){
21-
if(empty(cycle)){
22-
v0=base::g->edge(e).traverse(v);
23-
base::done=true;
24-
closed=v==v0;
25-
cycle.push_front(e);
26-
}
27-
}
28-
};
29-
template<graph_type graph>
30-
std::pair<node_index,std::deque<edge_index>>find_cycle(graph const&g){
31-
auto context=dfs<cycle_context>(g);
32-
return{context.v0,context.cycle};
33-
}
34-
}
6+
namespace cp_algo::graph{template<graph_type graph>struct cycle_context:dfs_context<graph>{using base=dfs_context<graph>;using base::base;std::deque<edge_index>cycle;bool closed=false;int v0;void on_return_from_child(node_index v,edge_index e){if(!empty(cycle)&&!closed){cycle.push_front(e);closed|=v==v0;}}void on_back_edge(node_index v,edge_index e){if(empty(cycle)){v0=base::g->edge(e).traverse(v);base::done=true;closed=v==v0;cycle.push_front(e);}}};template<graph_type graph>std::pair<node_index,std::deque<edge_index>>find_cycle(graph const&g){auto context=dfs<cycle_context>(g);return{context.v0,context.cycle};}}
357
#endif

cp-algo/min/graph/dfs.hpp

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,5 @@
33
#include "base.hpp"
44
#include <variant>
55
#include <stack>
6-
namespace cp_algo::graph{
7-
enum node_state{unvisited,visiting,visited,blocked};
8-
template<graph_type graph>
9-
struct dfs_context{
10-
big_vector<node_state>state;
11-
graph const*g;
12-
bool done=false;
13-
dfs_context(graph const&g):state(g.n()),g(&g){}
14-
void on_enter(node_index){}
15-
void on_tree_edge(node_index,edge_index){}
16-
void on_return_from_child(node_index,edge_index){}
17-
void on_back_edge(node_index,edge_index){}
18-
void on_forward_cross_edge(node_index,edge_index){}
19-
void on_exit(node_index){}
20-
};
21-
template<template<typename>class Context,graph_type graph>
22-
Context<graph>dfs(graph const&g){
23-
Context<graph>context(g);
24-
auto const&adj=g.incidence_lists();
25-
struct frame{
26-
node_index v;
27-
[[no_unique_address]]std::conditional_t<
28-
undirected_graph_type<graph>,
29-
edge_index,std::monostate>ep;
30-
int sv;
31-
enum{INIT,PROCESS_EDGES,HANDLE_CHILD}state;
32-
};
33-
std::stack<frame>dfs_stack;
34-
for(auto root:g.nodes()){
35-
if(context.done)break;
36-
if(context.state[root]!=unvisited)continue;
37-
if constexpr(undirected_graph_type<graph>){
38-
dfs_stack.push({root,-1,0,frame::INIT});
39-
}else{
40-
dfs_stack.push({root,{},0,frame::INIT});
41-
}
42-
while(!empty(dfs_stack)){
43-
auto&f=dfs_stack.top();
44-
if(f.state==frame::INIT){
45-
context.state[f.v]=visiting;
46-
context.on_enter(f.v);
47-
f.sv=adj.head[f.v];
48-
f.state=frame::PROCESS_EDGES;
49-
continue;
50-
}
51-
if(f.state==frame::HANDLE_CHILD){
52-
auto e=adj.data[f.sv];
53-
f.sv=adj.next[f.sv];
54-
context.on_return_from_child(f.v,e);
55-
f.state=frame::PROCESS_EDGES;
56-
continue;
57-
}
58-
bool found_child=false;
59-
while(f.sv!=0&&!context.done){
60-
auto e=adj.data[f.sv];
61-
if constexpr(undirected_graph_type<graph>){
62-
if(f.ep==e){
63-
f.sv=adj.next[f.sv];
64-
continue;
65-
}
66-
}
67-
node_index u=g.edge(e).traverse(f.v);
68-
if(context.state[u]==unvisited){
69-
context.on_tree_edge(f.v,e);
70-
f.state=frame::HANDLE_CHILD;
71-
if constexpr(undirected_graph_type<graph>){
72-
dfs_stack.push({u,e,0,frame::INIT});
73-
}else{
74-
dfs_stack.push({u,{},0,frame::INIT});
75-
}
76-
found_child=true;
77-
break;
78-
}else if(context.state[u]==visiting){
79-
context.on_back_edge(f.v,e);
80-
}else if(context.state[u]==visited){
81-
context.on_forward_cross_edge(f.v,e);
82-
}
83-
f.sv=adj.next[f.sv];
84-
}
85-
if(found_child)continue;
86-
context.state[f.v]=visited;
87-
context.on_exit(f.v);
88-
dfs_stack.pop();
89-
}
90-
}
91-
return context;
92-
}
93-
}
6+
namespace cp_algo::graph{enum node_state{unvisited,visiting,visited,blocked};template<graph_type graph>struct dfs_context{big_vector<node_state>state;graph const*g;bool done=false;dfs_context(graph const&g):state(g.n()),g(&g){}void on_enter(node_index){}void on_tree_edge(node_index,edge_index){}void on_return_from_child(node_index,edge_index){}void on_back_edge(node_index,edge_index){}void on_forward_cross_edge(node_index,edge_index){}void on_exit(node_index){}};template<template<typename>class Context,graph_type graph>Context<graph>dfs(graph const&g){Context<graph>context(g);auto const&adj=g.incidence_lists();struct frame{node_index v;[[no_unique_address]]std::conditional_t<undirected_graph_type<graph>,edge_index,std::monostate>ep;int sv;enum{INIT,PROCESS_EDGES,HANDLE_CHILD}state;};std::stack<frame>dfs_stack;for(auto root:g.nodes()){if(context.done)break;if(context.state[root]!=unvisited)continue;if constexpr(undirected_graph_type<graph>){dfs_stack.push({root,-1,0,frame::INIT});}else{dfs_stack.push({root,{},0,frame::INIT});}while(!empty(dfs_stack)){auto&f=dfs_stack.top();if(f.state==frame::INIT){context.state[f.v]=visiting;context.on_enter(f.v);f.sv=adj.head[f.v];f.state=frame::PROCESS_EDGES;continue;}if(f.state==frame::HANDLE_CHILD){auto e=adj.data[f.sv];f.sv=adj.next[f.sv];context.on_return_from_child(f.v,e);f.state=frame::PROCESS_EDGES;continue;}bool found_child=false;while(f.sv!=0&&!context.done){auto e=adj.data[f.sv];if constexpr(undirected_graph_type<graph>){if(f.ep==e){f.sv=adj.next[f.sv];continue;}}node_index u=g.edge(e).traverse(f.v);if(context.state[u]==unvisited){context.on_tree_edge(f.v,e);f.state=frame::HANDLE_CHILD;if constexpr(undirected_graph_type<graph>){dfs_stack.push({u,e,0,frame::INIT});}else{dfs_stack.push({u,{},0,frame::INIT});}found_child=true;break;}else if(context.state[u]==visiting){context.on_back_edge(f.v,e);}else if(context.state[u]==visited){context.on_forward_cross_edge(f.v,e);}f.sv=adj.next[f.sv];}if(found_child)continue;context.state[f.v]=visited;context.on_exit(f.v);dfs_stack.pop();}}return context;}}
947
#endif

0 commit comments

Comments
 (0)