Skip to content

Commit 3feb767

Browse files
committed
Merge branch 'master' into doc-for-dsu
2 parents cdc1075 + 40329df commit 3feb767

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.idea/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ac-library-rs
22

3+
[![CI](https://github.com/rust-lang-ja/ac-library-rs/workflows/CI/badge.svg)](https://github.com/rust-lang-ja/ac-library-rs/actions?workflow=CI)
4+
[![Rust 2018 1.42.0+](https://img.shields.io/badge/rust%202018-1.42.0+-lightgray.svg)](https://www.rust-lang.org)
5+
![Crates.io](https://img.shields.io/badge/crates.io-not%20yet-inactive)
6+
![License](https://img.shields.io/badge/license-CC0--1.0-informational)
7+
38
ac-library-rs is a rust port of AtCoder Library (ACL).
49

510
See below for ACL.

src/dsu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ mod tests {
195195
fn dsu_works() {
196196
let mut d = Dsu::new(4);
197197
d.merge(0, 1);
198-
assert_eq!(d.same(0, 1), true);
198+
assert!(d.same(0, 1));
199199
d.merge(1, 2);
200-
assert_eq!(d.same(0, 2), true);
200+
assert!(d.same(0, 2));
201201
assert_eq!(d.size(0), 3);
202-
assert_eq!(d.same(0, 3), false);
202+
assert!(!d.same(0, 3));
203203
assert_eq!(d.groups(), vec![vec![0, 1, 2], vec![3]]);
204204
}
205205
}

src/maxflow.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ where
201201
self.graph.g[e_to][e_rev].cap -= d;
202202
res += d;
203203
if res == up {
204-
break;
204+
return res;
205205
}
206206
}
207207
self.iter[v] = self.graph.g[v].len();
@@ -320,4 +320,15 @@ mod test {
320320

321321
assert_eq!(graph.flow(s, t), 2);
322322
}
323+
324+
#[test]
325+
fn test_dont_repeat_same_phase() {
326+
let n = 100_000;
327+
let mut graph = MfGraph::new(3);
328+
graph.add_edge(0, 1, n);
329+
for _ in 0..n {
330+
graph.add_edge(1, 2, 1);
331+
}
332+
assert_eq!(graph.flow(0, 2), n);
333+
}
323334
}

src/mincostflow.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub struct MinCostFlowEdge<T> {
1111
pub struct MinCostFlowGraph<T> {
1212
pos: Vec<(usize, usize)>,
1313
g: Vec<Vec<_Edge<T>>>,
14-
cost_sum: T,
1514
}
1615

1716
impl<T> MinCostFlowGraph<T>
@@ -22,7 +21,6 @@ where
2221
Self {
2322
pos: vec![],
2423
g: (0..n).map(|_| vec![]).collect(),
25-
cost_sum: T::zero(),
2624
}
2725
}
2826

@@ -56,7 +54,6 @@ where
5654
assert!(cost >= T::zero());
5755

5856
self.pos.push((from, self.g[from].len()));
59-
self.cost_sum += cost;
6057

6158
let rev = self.g[to].len();
6259
self.g[from].push(_Edge { to, rev, cap, cost });
@@ -131,7 +128,7 @@ where
131128
pe: &mut [usize],
132129
) -> bool {
133130
let n = self.g.len();
134-
let mut dist = vec![self.cost_sum; n];
131+
let mut dist = vec![T::max_value(); n];
135132
let mut vis = vec![false; n];
136133

137134
let mut que = std::collections::BinaryHeap::new();
@@ -209,4 +206,13 @@ mod tests {
209206
let expected = [(0, 0), (3, 3)];
210207
assert_eq!(expected[..], *graph.slope(0, 2, i32::max_value()));
211208
}
209+
210+
#[test]
211+
fn only_one_nonzero_cost_edge() {
212+
let mut graph = MinCostFlowGraph::new(3);
213+
assert_eq!(0, graph.add_edge(0, 1, 1, 1));
214+
assert_eq!(1, graph.add_edge(1, 2, 1, 0));
215+
let expected = [(0, 0), (1, 1)];
216+
assert_eq!(expected[..], *graph.slope(0, 2, i32::max_value()));
217+
}
212218
}

0 commit comments

Comments
 (0)