結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2021-03-12 23:57:39 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,106 bytes |
| 記録 | |
| コンパイル時間 | 604 ms |
| コンパイル使用メモリ | 148,820 KB |
| 最終ジャッジ日時 | 2026-05-02 02:49:22 |
| 合計ジャッジ時間 | 1,719 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error: cannot explicitly dereference within an implicitly-borrowing pattern --> src/main.rs:56:26 | 56 | .filter(|(_, &d)| d == 1) | ^ reference pattern not allowed when implicitly borrowing | = note: for more information, see <https://doc.rust-lang.org/reference/patterns.html#binding-modes> note: matching on a reference type with a non-reference pattern implicitly borrows the contents --> src/main.rs:56:22 | 56 | .filter(|(_, &d)| d == 1) | ^^^^^^^ this non-reference pattern matches on a reference type `&_` help: match on the reference with a reference pattern to avoid implicitly borrowing | 56 | .filter(|&(_, &d)| d == 1) | + error: could not compile `main` (bin "main") due to 1 previous error
ソースコード
fn run<'a, F: FnMut() -> &'a str, W: std::io::Write>(scan: &mut F, writer: &mut W) {
macro_rules! scan {
([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::<Vec<_>>());
(($($t:tt),*)) => (($(scan!($t)),*));
(Usize1) => (scan!(usize) - 1);
(Bytes) => (scan().as_bytes().to_vec());
($t:ty) => (scan().parse::<$t>().unwrap());
}
macro_rules! println {
($($arg:tt)*) => (writeln!(writer, $($arg)*).ok());
}
let n = scan!(usize);
let mut graph = vec![vec![]; n];
let mut degree = vec![0; n];
for _ in 0..(n - 1) {
let (a, b) = scan!((Usize1, Usize1));
graph[a].push(b);
graph[b].push(a);
degree[a] += 1;
degree[b] += 1;
}
let count = degree.iter().filter(|&&d| d >= 3).count();
if count >= 2 {
println!("No");
return;
} else if count == 0 {
println!("Yes");
return;
}
let mut root = 0;
for (i, &d) in degree.iter().enumerate() {
if d >= 3 {
root = i;
}
}
let mut deque = std::collections::VecDeque::new();
deque.push_back(root);
let mut dist = vec![0; n];
dist[root] = 1;
while let Some(from) = deque.pop_front() {
for &to in &graph[from] {
if dist[to] == 0 {
deque.push_back(to);
dist[to] = dist[from] + 1;
}
}
}
let mut set = {
degree.iter().enumerate()
.filter(|(_, &d)| d == 1)
.map(|(i, _)| dist[i])
.collect::<Vec<_>>()
};
set.dedup();
if set.len() == 1 {
println!("Yes");
} else {
println!("No");
}
}
fn main() {
let ref mut buf = Vec::new();
std::io::Read::read_to_end(&mut std::io::stdin(), buf).ok();
let mut scanner = unsafe {
std::str::from_utf8_unchecked(buf).split_ascii_whitespace()
};
let ref mut scan = || scanner.next().unwrap();
let stdout = std::io::stdout();
let ref mut writer = std::io::BufWriter::new(stdout.lock());
run(scan, writer);
}
Strorkis