Submission #682630

# Submission time Handle Problem Language Result Execution time Memory
682630 2023-01-16T16:03:52 Z anonimy Ferries (NOI13_ferries) C++14
40 / 40
262 ms 22492 KB
#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

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
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 10 ms 2360 KB Output is correct
4 Correct 111 ms 19512 KB Output is correct
5 Correct 112 ms 19520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 9 ms 2260 KB Output is correct
4 Correct 52 ms 9848 KB Output is correct
5 Correct 80 ms 15180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2388 KB Output is correct
2 Correct 12 ms 2400 KB Output is correct
3 Correct 227 ms 21264 KB Output is correct
4 Correct 256 ms 21620 KB Output is correct
5 Correct 239 ms 20916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 21312 KB Output is correct
2 Correct 191 ms 21212 KB Output is correct
3 Correct 253 ms 22364 KB Output is correct
4 Correct 246 ms 22380 KB Output is correct
5 Correct 262 ms 22492 KB Output is correct