This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
vector<vector<ll>> G;
vector<priority_queue<ll>> edges;
vector<ll> dist;
ll n;
void dijkstra(ll s)
{
vector<bool> visited(n + 1, false);
dist.resize(n + 1, 1e18);
priority_queue<pll, vector<pll>, greater<pll>> pq;
dist[s] = 0;
pq.push({ 0, s });
while (!pq.empty())
{
ll v = pq.top().second;
pq.pop();
if (visited[v]) continue;
visited[v] = true;
for (ll i = 0; i < G[v].size(); i++)
{
ll u = G[v][i], w = edges[u].top();
edges[u].pop();
if (dist[v] + w < dist[u])
{
dist[u] = dist[v] + w;
pq.push({ dist[u], u });
}
}
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll m;
cin >> n >> m;
G.resize(n + 1);
edges.resize(n + 1);
for (ll i = 0; i < m; i++)
{
ll a, b, c;
cin >> a >> b >> c;
G[b].push_back(a);
edges[a].push(c);
}
dijkstra(n);
cout << dist[1];
}
Compilation message (stderr)
ferries.cpp: In function 'void dijkstra(ll)':
ferries.cpp:34:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (ll i = 0; i < G[v].size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |