Submission #38894

# Submission time Handle Problem Language Result Execution time Memory
38894 2018-01-07T17:05:05 Z cheater2k Ferries (NOI13_ferries) C++14
0 / 40
586 ms 13960 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
const int inf = 1e9 + 10;
typedef pair<int,int> ii;

int n, m;
vector<int> rev[N], len[N];
int d[N];

void solve() {
	for (int i = 1; i <= n; ++i) d[i] = inf;
	priority_queue < ii, vector<ii>, greater<ii> > pq;
	pq.push(ii(0, n));
	d[n] = 0;

	while(!pq.empty()) {
		ii top = pq.top(); pq.pop();
		int u = top.second, du = top.first;
		if (du != d[u]) continue;
		if (u == 1) {
			printf("%d\n", du); return;
		}

		for (int v : rev[u]) {
			if (!len[v].empty() && d[v] > d[u] + len[v].back()) {
				d[v] = d[u] + len[v].back(); len[v].pop_back();
				pq.push(ii(d[v], v));
			}
		}
	}
}

int main() {
	cin >> n >> m;
	while(m--) {
		int u, v, w; cin >> u >> v >> w;
		rev[v].push_back(u);
		len[u].push_back(w);
	}
	for (int i = 1; i <= n; ++i) {
		sort(len[i].begin(), len[i].end());
	}

	solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 7096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 7096 KB Output is correct
2 Incorrect 0 ms 7228 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 7756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 586 ms 13960 KB Output isn't correct
2 Halted 0 ms 0 KB -