Skip to content

Commit 180ad35

Browse files
committed
Add an example for ABC073-D
1 parent 02e21ec commit 180ad35

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

examples/abc073-d.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// https://atcoder.jp/contests/abc073/tasks/abc073_d
2+
3+
use itertools::Itertools as _;
4+
use petgraph::graph::{NodeIndex, UnGraph};
5+
6+
use std::collections::HashMap;
7+
use std::io::{self, Read};
8+
9+
fn main() {
10+
let mut input = read_to_static(io::stdin()).split_whitespace();
11+
macro_rules! read {
12+
([$tt:tt]) => (read!([$tt; read!(usize)]));
13+
([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
14+
(($($tt:tt),+)) => (($(read!($tt)),*));
15+
($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
16+
({ NodeIndex1 }) => {
17+
NodeIndex::from(read!(u32) - 1)
18+
};
19+
}
20+
21+
let (_, m, r) = read!((usize, usize, usize));
22+
let rs = read!([{ NodeIndex1 }; r]);
23+
let abcs = read!([({ NodeIndex1 }, { NodeIndex1 }, u32); m]);
24+
25+
let graph = UnGraph::<(), u32>::from_edges(abcs);
26+
27+
let dijkstra = rs
28+
.iter()
29+
.map(|&r| {
30+
let dijkstra = petgraph::algo::dijkstra(&graph, r, None, |e| *e.weight());
31+
(r, dijkstra)
32+
})
33+
.collect::<HashMap<_, _>>();
34+
35+
let ans = rs
36+
.into_iter()
37+
.permutations(r)
38+
.map(|rs| rs.windows(2).map(|w| dijkstra[&w[0]][&w[1]]).sum::<u32>())
39+
.min()
40+
.unwrap();
41+
println!("{}", ans);
42+
}
43+
44+
fn read_to_static(mut source: impl Read) -> &'static str {
45+
let mut input = "".to_owned();
46+
source.read_to_string(&mut input).unwrap();
47+
Box::leak(input.into_boxed_str())
48+
}

test-with-generated-opts.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ url = "https://atcoder.jp/contests/abc057/tasks/abc057_b"
3333
matching = "Words"
3434
meta = { using = ["whiteread"] }
3535

36+
[examples.abc073-d]
37+
name = "ABC073: D - joisino's travel"
38+
url = "https://atcoder.jp/contests/abc073/tasks/abc073_d"
39+
matching = "Words"
40+
meta = { using = ["itertools", "petgraph"] }
41+
3642
[examples.abc084-d]
3743
name = "ABC084: D - 2017-like Number"
3844
url = "https://atcoder.jp/contests/abc084/tasks/abc084_d"

0 commit comments

Comments
 (0)