Skip to content

Commit 6017df8

Browse files
authored
Merge pull request rust-lang-ja#33 from qryxip/ja-all-enabled-add-union-find-crate
Add `union-find` crate
2 parents deb6830 + cdd5a5f commit 6017df8

File tree

11 files changed

+71
-2
lines changed

11 files changed

+71
-2
lines changed

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ im-rc = "=14.0.0"
133133
fixedbitset = "=0.2.0"
134134
bitset-fixed = "=0.1.0"
135135

136+
# union-find (a.k.a. disjoint-set)
137+
union-find = "=0.3.2"
138+
136139
# 競技プログラミングの入出力サポート
137140
proconio = { version = "=0.3.4", features = ["derive"] }
138141
text_io = "=0.1.7"

examples/abc120-d.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// https://atcoder.jp/contests/abc120/tasks/abc120_d
2+
3+
use proconio::marker::Usize1;
4+
use proconio::{fastout, input};
5+
use union_find::{QuickFindUf, UnionBySize, UnionFind as _};
6+
7+
#[fastout]
8+
fn main() {
9+
input! {
10+
n: usize,
11+
m: usize,
12+
abs: [(Usize1, Usize1); m],
13+
}
14+
15+
let mut u = QuickFindUf::<UnionBySize>::new(n);
16+
let mut k = n * (n - 1) / 2;
17+
let mut r = vec![k];
18+
r.extend(abs.into_iter().rev().map(|(a, b)| {
19+
let p = u.get(a).size() * u.get(b).size();
20+
if u.union(a, b) {
21+
k -= p;
22+
}
23+
k
24+
}));
25+
assert_eq!(r.pop(), Some(0));
26+
for r in r.into_iter().rev() {
27+
println!("{}", r);
28+
}
29+
}

examples/tests.ron

+4
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
name: "ABC049 / ARC065: C - 白昼夢 / Daydream",
1313
matching: ExactWords,
1414
),
15+
"abc120-d": (
16+
name: "ABC120: D - Decayed Bridges ",
17+
matching: ExactWords,
18+
),
1519
}
1620
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
4 5
2+
1 2
3+
3 4
4+
1 3
5+
2 3
6+
1 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
6 5
2+
2 3
3+
1 2
4+
5 6
5+
3 4
6+
4 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2 1
2+
1 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0
2+
0
3+
4
4+
5
5+
6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
8
2+
9
3+
12
4+
14
5+
15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tools/test-with-generated-opts/src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
179179
.with_context(|| format!("Failed to execute {}", binary.display()))?;
180180

181181
child.stdin.as_mut().unwrap().write_all(input.as_ref())?;
182-
let status = child.wait()?;
183-
let stop = Instant::now();
182+
child.stdin.take();
184183
let actual = {
185184
let mut actual = "".to_owned();
186185
child
@@ -191,6 +190,8 @@ fn test(task_name: &str, matching: Matching, testsets: &Path, binary: &Path) ->
191190
.with_context(|| format!("{} outputted invalid UTF-8", binary.display()))?;
192191
actual
193192
};
193+
let status = child.wait()?;
194+
let stop = Instant::now();
194195

195196
let time = (stop - start).as_millis();
196197
let verdict = if status.success() && matching.accepts(&expected, &actual) {

0 commit comments

Comments
 (0)