結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
|
提出日時 | 2025-01-25 13:25:19 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 1,711 bytes |
コンパイル時間 | 23,797 ms |
コンパイル使用メモリ | 377,808 KB |
実行使用メモリ | 35,280 KB |
最終ジャッジ日時 | 2025-01-25 22:46:26 |
合計ジャッジ時間 | 19,152 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge7 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
use proconio::{input, marker::Usize1};fn main() {input! {n: usize,m: usize,p: usize,y: usize,abc: [(Usize1,Usize1,usize); m],de: [(Usize1,usize); p],}let mut graph = vec![vec![]; n];for &(a, b, c) in &abc {graph[a].push((b, c));graph[b].push((a, c));}let dist = dijkstra(&graph, 0);let mut ans = 0;for &(d, e) in &de {if dist[d] > y {continue;}let rem = y - dist[d];ans = ans.max(rem / e);}println!("{}", ans);}#[derive(Debug, Clone, Eq, PartialEq)]struct Node {vertex: usize,cost: usize,}impl Ord for Node {fn cmp(&self, other: &Self) -> std::cmp::Ordering {other.cost.cmp(&self.cost)}}impl PartialOrd for Node {fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {Some(self.cmp(other))}}pub fn dijkstra(graph: &[Vec<(usize, usize)>], start: usize) -> Vec<usize> {let n = graph.len();let mut dist = vec![std::usize::MAX; n];let mut pq = std::collections::BinaryHeap::new();dist[start] = 0;pq.push(Node {vertex: start,cost: 0,});while let Some(Node { vertex, cost }) = pq.pop() {if dist[vertex] < cost {continue;}for &(next_vertex, edge_cost) in &graph[vertex] {let new_cost = cost + edge_cost;if new_cost < dist[next_vertex] {dist[next_vertex] = new_cost;pq.push(Node {vertex: next_vertex,cost: new_cost,});}}}dist}