結果
| 問題 |
No.1601 With Animals into Institute
|
| コンテスト | |
| ユーザー |
sapphire__15
|
| 提出日時 | 2021-07-10 15:19:02 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 577 ms / 3,000 ms |
| コード長 | 1,993 bytes |
| コンパイル時間 | 13,283 ms |
| コンパイル使用メモリ | 379,460 KB |
| 実行使用メモリ | 38,144 KB |
| 最終ジャッジ日時 | 2024-07-02 02:31:07 |
| 合計ジャッジ時間 | 21,532 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
// -*- coding:utf-8-unix -*-
use std::cmp::Ordering;
use proconio::input;
use std::collections::BinaryHeap;
#[derive(Debug)]
struct Edge { to: usize, length: i64 }
#[derive(Debug)]
struct Entry { to: usize, length: i64 }
impl PartialEq for Entry {
fn eq(&self, other: &Self) -> bool {
self.length == other.length
}
}
impl Eq for Entry {}
impl PartialOrd for Entry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
other.length.partial_cmp(&self.length)
}
}
impl Ord for Entry {
fn cmp(&self, other: &Self) -> Ordering {
self.length.cmp(&other.length)
}
}
fn main() {
input! {
n: usize,
m: usize,
}
let mut da: Vec<Vec<Edge>> = Vec::new();
for _ in 0..n * 2 {
da.push(Vec::new());
}
for _ in 0..m {
input! {
a: usize,
b: usize,
c: i64,
x: i32,
}
da[n + a - 1].push(Edge { to: n + b - 1, length: c });
da[n + b - 1].push(Edge { to: n + a - 1, length: c });
if x == 1 {
da[n + a - 1].push(Edge { to: b - 1, length: c });
da[n + b - 1].push(Edge { to: a - 1, length: c });
} else {
da[a - 1].push(Edge { to: b - 1, length: c });
da[b - 1].push(Edge { to: a - 1, length: c });
}
}
let mut used = Vec::new();
used.resize(n*2, -1);
let mut pq = BinaryHeap::new();
pq.push(Entry{ to: n*2-1, length: 0});
loop {
let now = pq.pop();
match now {
None => break,
Some(x) => {
if used[x.to] < 0 {
used[x.to] = x.length;
for to in &da[x.to] {
pq.push(Entry {to: to.to,
length: x.length + to.length
});
}
}
}
}
}
for i in 0..n-1 {
println!("{}", used[i]);
}
}
sapphire__15