Skip to content

Commit

Permalink
typical90 012
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 28, 2024
1 parent 1adf95a commit 4e6b4d0
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions cargo-atcoder-1.70.0/contests/typical90/src/bin/012.rs
@@ -1,10 +1,51 @@
use ac_library::Dsu;
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
a: [Usize1; n],
h: usize,
w: usize,
capital_q: usize,
};
let ans = n - a.len();
println!("{}", ans);

let mut dsu = Dsu::new(h * w);
let mut table = vec![vec![false; w]; h];

for _ in 0..capital_q {
input! {
t: usize,
};

match t {
1 => {
input! {
r: Usize1,
c: Usize1,
}
table[r][c] = true;
let dir = vec![(-1, 0), (0, -1), (0, 1), (1, 0)];
for (dr, dc) in dir {
let (nr, nc) = (r as i64 + dr, c as i64 + dc);
if !(0..h as i64).contains(&nr) || !(0..w as i64).contains(&nc) {
continue;
}
let (nr, nc) = (nr as usize, nc as usize);
if table[nr][nc] {
dsu.merge(r * w + c, nr * w + nc);
}
}
}
2 => {
input! {
ra: Usize1,
ca: Usize1,
rb: Usize1,
cb: Usize1,
}
let ans = table[ra][ca] && dsu.same(ra * w + ca, rb * w + cb);
println!("{}", if ans { "Yes" } else { "No" });
}
_ => unreachable!(),
}
}
}

0 comments on commit 4e6b4d0

Please sign in to comment.