답안 #38895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38895 2018-01-07T17:19:26 Z cheater2k 페리들 (NOI13_ferries) C++14
40 / 40
653 ms 15996 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()) {
				int cur = len[v].back(); len[v].pop_back();
				if (d[v] > d[u] + cur) {
					d[v] = d[u] + cur; 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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7096 KB Output is correct
2 Correct 3 ms 7228 KB Output is correct
3 Correct 33 ms 8088 KB Output is correct
4 Correct 296 ms 15996 KB Output is correct
5 Correct 276 ms 15996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7096 KB Output is correct
2 Correct 0 ms 7228 KB Output is correct
3 Correct 23 ms 8072 KB Output is correct
4 Correct 119 ms 11592 KB Output is correct
5 Correct 159 ms 13748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 7756 KB Output is correct
2 Correct 33 ms 7756 KB Output is correct
3 Correct 576 ms 13960 KB Output is correct
4 Correct 559 ms 14104 KB Output is correct
5 Correct 613 ms 14104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 653 ms 13960 KB Output is correct
2 Correct 629 ms 13960 KB Output is correct
3 Correct 583 ms 14132 KB Output is correct
4 Correct 593 ms 14776 KB Output is correct
5 Correct 553 ms 14784 KB Output is correct