Skip to content

Commit dc9129d

Browse files
committed
Modify abc054-c
1 parent 3823bf1 commit dc9129d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

examples/abc054-c.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// https://atcoder.jp/contests/abc054/tasks/abc054_c
22

3-
use petgraph::matrix_graph::UnMatrix;
3+
use itertools::Itertools as _;
4+
use petgraph::graph::UnGraph;
45

56
use std::io::{self, Read};
67

@@ -19,14 +20,12 @@ fn main() {
1920
let n = read!(usize);
2021
let abs = read!([({ Usize1 }, { Usize1 })]);
2122

22-
let graph = UnMatrix::<(), (), Option<()>, usize>::from_edges(abs);
23-
let mut ans = 0;
24-
let mut nodes = (0..n).map(Into::into).collect::<Vec<_>>();
25-
permutohedron::heap_recursive(&mut nodes, |nodes| {
26-
if nodes[0] == 0.into() && nodes.windows(2).all(|w| graph.has_edge(w[0], w[1])) {
27-
ans += 1;
28-
}
29-
});
23+
let graph = UnGraph::<(), (), usize>::from_edges(abs);
24+
let ans = graph
25+
.node_indices()
26+
.permutations(n)
27+
.filter(|p| p[0].index() == 0 && p.windows(2).all(|w| graph.contains_edge(w[0], w[1])))
28+
.count();
3029
println!("{}", ans);
3130
}
3231

test-with-generated-opts.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ testcases = "./target/test-with-generated-opts/testcases/{}"
77
name = "ABC054: C - One-stroke Path"
88
url = "https://atcoder.jp/contests/abc054/tasks/abc054_c"
99
matching = "Words"
10-
meta = { using = ["permutohedron", "petgraph"] }
10+
meta = { using = ["itertools", "petgraph"] }
1111

1212
[examples.abc057-b-naive]
1313
name = "ABC057: B - Checkpoints"

0 commit comments

Comments
 (0)