이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = a - 1; i >= (b); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define endl '\n'
#define umap unordered_map
#define uset unordered_set
#define INF 1000000000
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(NULL);
set<pair<ll, int>> s, pq;
vector<ll> dist;
vector<pair<int, ll>> graph[50001];
int k, n, m, o;
cin >> k >> n >> m >> o;
rep(i, 0, m) {
ll a, b, t;
cin >> a >> b >> t;
graph[a].emplace_back(b, t);
}
rep(i, 0, n) s.emplace(1e15, i);
while (o--) {
dist.assign(n, 1e15);
pq = s;
ll a, b;
cin >> a >> b;
pq.erase({1e15, a});
pq.emplace(0, a);
while (!pq.empty()) {
ll cost, u;
tie(cost, u) = *pq.begin();
pq.erase(pq.begin());
trav(edge, graph[u]) {
ll w = edge.second;
int v = edge.first;
if (cost + w >= dist[v]) continue;
pq.erase({dist[v], v});
pq.insert({cost + w, v});
dist[v] = cost + w;
}
}
if (dist[b] == 1e15) cout<<-1<<endl;
else cout<<dist[b]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |