Submission
| Id | When | Author | Problem | Language | CPU | Memory | Verdict |
|---|---|---|---|---|---|---|---|
| 50353 | 2026-03-13 21:54:28 | cyblox | บินประหยัด จำกัดเที่ยว (K-Stops Flights) |
|
7 ms | 3492 kb | Accepted |
Test Cases
| CPU | Memory | Verdict | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 6 ms | 3332 kb | Accepted | ||||||||
| 2 | 7 ms | 3436 kb | Accepted | ||||||||
| 3 | 6 ms | 3372 kb | Accepted | ||||||||
| 4 | 7 ms | 3488 kb | Accepted | ||||||||
| 5 | 6 ms | 3492 kb | Accepted | ||||||||
Source Code
program.cpp
#include <bits/stdc++.h> using namespace std; struct Edge { int v, w; }; typedef map<int, vector<Edge>> AdjList; struct State { int cost, u, stops; bool operator>(const State &other) const { return cost > other.cost; } }; int dijkstra(AdjList &adj, int s, int e, int k) { priority_queue<State, vector<State>, greater<State>> pq; map<int, vector<int>> dist; for (const auto &p : adj) { dist[p.first] = vector<int>(k + 2, INT_MAX); } dist[s][0] = 0; pq.push({0, s, 0}); while (!pq.empty()) { auto [cost, u, stops] = pq.top(); pq.pop(); if (u == e) { return cost; } if (stops > k) { continue; } for (const auto &edge : adj[u]) { int newCost = cost + edge.w; if (newCost < dist[edge.v][stops + 1]) { dist[edge.v][stops + 1] = newCost; pq.push({newCost, edge.v, stops + 1}); } } } return -1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; int s, e; cin >> s >> e; AdjList adj; for (int i = 1; i <= n; i++) { adj[i] = {}; } for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; adj[u].push_back({v, w}); } cout << dijkstra(adj, s, e, k) << '\n'; return 0; }