Submission #478001

# Submission time Handle Problem Language Result Execution time Memory
478001 2021-10-05T02:45:16 Z sumit_kk10 Ferries (NOI13_ferries) C++17
40 / 40
338 ms 17752 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int n, m;

void solve(){
    cin >> n >> m;
    vector<int> inc[n + 1], graph[n + 1];
    vector<int> dis(n + 1, INT_MAX);
    for(int i = 1; i <= m; ++i){
        int u, v, c;
        cin >> u >> v >> c;
        graph[v].push_back(u);
        inc[u].push_back(c);
    }
    for(int i = 1; i <= n; ++i)
        sort(inc[i].begin(), inc[i].end());
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
    pq.push({0, n});
    dis[n] = 0;
    while(!pq.empty()){
        int cost = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(dis[node] != cost) continue;
        for(auto k : graph[node]){
            if(dis[k] > cost + inc[k].back()){
                dis[k] = cost + inc[k].back();
                pq.push({dis[k], k});
            }
            inc[k].pop_back();
        }
    }
    cout << dis[1] << "\n";
}

int main(){
    fast;
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 10 ms 1668 KB Output is correct
4 Correct 114 ms 13544 KB Output is correct
5 Correct 108 ms 13564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 9 ms 1664 KB Output is correct
4 Correct 54 ms 6892 KB Output is correct
5 Correct 108 ms 11972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1436 KB Output is correct
2 Correct 13 ms 1864 KB Output is correct
3 Correct 217 ms 17088 KB Output is correct
4 Correct 210 ms 17304 KB Output is correct
5 Correct 261 ms 16568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 12312 KB Output is correct
2 Correct 202 ms 17032 KB Output is correct
3 Correct 235 ms 17752 KB Output is correct
4 Correct 246 ms 17732 KB Output is correct
5 Correct 338 ms 17720 KB Output is correct