답안 #333673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333673 2020-12-07T13:12:14 Z ncduy0303 페리들 (NOI13_ferries) C++17
40 / 40
326 ms 19556 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

int n, m;
vector<int> adj[MAX_N];
priority_queue<int> cost[MAX_N];
vector<ll> dist;

void dijk(int s) {
    dist.assign(n + 1, LINF);
    priority_queue<ar<ll,2>, vector<ar<ll,2>>, greater<ar<ll,2>>> pq;
    dist[s] = 0; pq.push({0, s});
    while (pq.size()) {
        auto [d, u] = pq.top(); pq.pop();
        if (d > dist[u]) continue;
        for (auto v : adj[u]) {
            int w = cost[v].top(); cost[v].pop();
            if (dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                pq.push({dist[v], v});
            }
        }
    } 
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v, w; cin >> u >> v >> w;
        adj[v].push_back(u);
        cost[u].push(w);
    }
    dijk(n);
    cout << dist[1] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5868 KB Output is correct
2 Correct 5 ms 5888 KB Output is correct
3 Correct 14 ms 7276 KB Output is correct
4 Correct 132 ms 18780 KB Output is correct
5 Correct 133 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5868 KB Output is correct
2 Correct 5 ms 5868 KB Output is correct
3 Correct 14 ms 7276 KB Output is correct
4 Correct 62 ms 12392 KB Output is correct
5 Correct 111 ms 15212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7020 KB Output is correct
2 Correct 18 ms 7020 KB Output is correct
3 Correct 261 ms 18380 KB Output is correct
4 Correct 293 ms 18796 KB Output is correct
5 Correct 279 ms 18028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 18372 KB Output is correct
2 Correct 268 ms 18284 KB Output is correct
3 Correct 326 ms 19468 KB Output is correct
4 Correct 305 ms 19556 KB Output is correct
5 Correct 307 ms 19556 KB Output is correct