結果
問題 |
No.2319 Friends+
|
ユーザー |
|
提出日時 | 2023-06-01 21:22:34 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 718 ms / 3,000 ms |
コード長 | 2,565 bytes |
コンパイル時間 | 14,677 ms |
コンパイル使用メモリ | 379,764 KB |
実行使用メモリ | 101,120 KB |
最終ジャッジ日時 | 2024-12-28 15:16:00 |
合計ジャッジ時間 | 38,134 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 45 |
ソースコード
pub mod scanner { pub struct Scanner { buf: Vec<String>, } impl Scanner { pub fn new() -> Self { Self { buf: vec![] } } pub fn new_from(source: &str) -> Self { let source = String::from(source); let buf = Self::split(source); Self { buf } } pub fn next<T: std::str::FromStr>(&mut self) -> T { loop { if let Some(x) = self.buf.pop() { return x.parse().ok().expect(""); } let mut source = String::new(); std::io::stdin().read_line(&mut source).expect(""); self.buf = Self::split(source); } } fn split(source: String) -> Vec<String> { source .split_whitespace() .rev() .map(String::from) .collect::<Vec<_>>() } } } use crate::scanner::Scanner; #[derive(Clone, Copy)] struct BitSet([u64; 313]); impl BitSet { fn new() -> Self { Self([0; 313]) } fn set(&mut self, index: usize, b: bool) { let i = index / 64; let j = index % 64; let mask = 1u64 << j; if b { self.0[i] |= mask; } else { self.0[i] &= !mask; } } fn disjoint(&self, rhs: &Self) -> bool { for i in 0..313 { if (self.0[i] & rhs.0[i]).count_ones() > 0 { return false; } } true } } fn main() { let mut scanner = Scanner::new(); let t: usize = 1; for _ in 0..t { solve(&mut scanner); } } fn solve(scanner: &mut Scanner) { let n: usize = scanner.next(); let m: usize = scanner.next(); let mut p = vec![!0; 20000]; let mut w = vec![BitSet::new(); 20000]; let mut f = vec![BitSet::new(); 20000]; for i in 0..n { let x = scanner.next::<usize>() - 1; p[i] = x; w[x].set(i, true); } for _ in 0..m { let a = scanner.next::<usize>() - 1; let b = scanner.next::<usize>() - 1; f[a].set(b, true); f[b].set(a, true); } let q: usize = scanner.next(); for _ in 0..q { let x = scanner.next::<usize>() - 1; let y = scanner.next::<usize>() - 1; if p[x] == p[y] || w[p[y]].disjoint(&f[x]) { println!("No"); continue; } println!("Yes"); w[p[x]].set(x, false); w[p[y]].set(x, true); p[x] = p[y]; } }