結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-11 00:14:49 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,521 bytes |
| コンパイル時間 | 16,758 ms |
| コンパイル使用メモリ | 378,536 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 11:26:49 |
| 合計ジャッジ時間 | 17,744 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 11 |
コンパイルメッセージ
warning: use of deprecated method `std::error::Error::description`: use the Display impl or to_string()
--> src/main.rs:97:62
|
97 | Err(why) => panic!("error in read_line: {}", why.description()),
| ^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
ソースコード
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
use std::collections::*;
use std::cmp::*;
fn exec() {
let mut sc = Scanner::new();
let n: usize = sc.ne();
let mut edge = vec![(0, 0); n];
let mut num = BTreeMap::new();
for i in 0..n {
let y1: usize = sc.ne::<usize>() - 1;
let x1: usize = sc.ne::<usize>() - 1;
let y2: usize = sc.ne::<usize>() - 1;
let x2: usize = sc.ne::<usize>() - 1;
let n1 = y1 * 100 + x1;
let n2 = y2 * 100 + x2;
edge[i] = (n1, n2);
num.insert(n1, 0);
num.insert(n2, 0);
}
let mut t = 0;
for (_, val) in num.iter_mut() {
*val = t;
t += 1;
}
let m = num.len();
let mut adj = vec![Vec::new(); m];
for &(u, v) in &edge {
let u_ = num[&u];
let v_ = num[&v];
adj[u_].push(v_);
adj[v_].push(u_);
}
fn dfs(mut ord: &mut Vec<i32>, adj: &Vec<Vec<usize>>, cur: usize, par: usize) -> bool {
let mut cnt = 0;
let mut ok = true;
let curord = ord[cur];
for &nxt in &adj[cur] {
if nxt == par {
continue;
}
if ord[nxt] == -1 {
ord[nxt] = ord[cur] + 1;
ok &= dfs(&mut ord, &adj, nxt, cur);
}
ord[cur] = min(ord[cur], ord[nxt]);
if curord > ord[nxt] {
cnt += 1;
}
}
ok &= cnt <= 1;
ok
}
let mut ord = vec![-1; m];
let mut ok = true;
for i in 0..m {
if ord[i] == -1 {
ord[i] = 0;
ok &= dfs(&mut ord, &adj, i, i);
}
}
println!("{}", if ok { "YES" } else { "NO" });
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
let builder = thread::Builder::new();
let th = builder.stack_size(DEFAULT_STACK);
let handle = th.spawn(|| { exec(); }).unwrap();
let _ = handle.join();
}
#[allow(dead_code)]
struct Scanner {
stdin: Stdin,
id: usize,
buf: Vec<u8>,
}
#[allow(dead_code)]
impl Scanner {
fn new() -> Scanner {
Scanner {
stdin: io::stdin(),
id: 0,
buf: Vec::new(),
}
}
fn next_line(&mut self) -> Option<String> {
let mut res = String::new();
match self.stdin.read_line(&mut res) {
Ok(0) => return None,
Ok(_) => Some(res),
Err(why) => panic!("error in read_line: {}", why.description()),
}
}
fn next<T: FromStr>(&mut self) -> Option<T> {
while self.buf.len() == 0 {
self.buf = match self.next_line() {
Some(r) => {
self.id = 0;
r.trim().as_bytes().to_owned()
}
None => return None,
};
}
let l = self.id;
assert!(self.buf[l] != b' ');
let n = self.buf.len();
let mut r = l;
while r < n && self.buf[r] != b' ' {
r += 1;
}
let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
Ok(s) => Some(s),
Err(_) => panic!("parse error"),
};
while r < n && self.buf[r] == b' ' {
r += 1;
}
if r == n {
self.buf.clear();
} else {
self.id = r;
}
res
}
fn ne<T: FromStr>(&mut self) -> T {
self.next::<T>().unwrap()
}
}