Submission #50274

# Submission time Handle Problem Language Result Execution time Memory
50274 2018-06-09T02:22:12 Z SerejadexXx Ferries (NOI13_ferries) C++14
40 / 40
335 ms 63348 KB
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>

using namespace std;

vector<pair<pair<int, int>, int> > r;
vector<int> ne;
vector<int> pr;
vector<int> d;
vector<int> u;
vector<vector<int>> q;
vector<int> q_u;

int ferries(int N, int M, int * A, int * B, int * C)
{
    r.clear();
    d.clear();
    u.clear();
    pr.clear();
    pr.assign(N + 1, -1);
    ne.clear();
    ne.assign(M + 1, 0);
    q.clear();
    q_u.clear();
    for (int i = 0; i < N; i++) {
        vector<int> w;
        q.push_back(w);
        q_u.push_back(0);
    }

    for (int i = 0; i < M; i++) {
        A[i]--;
        B[i]--;
        ne[i] = pr[B[i]];
        pr[B[i]] = i;
        q[A[i]].push_back(C[i]);
    }
    for (int i = 0; i < N; i++) {
        sort(q[i].begin(), q[i].end());
        reverse(q[i].begin(), q[i].end());
    }

    for (int i = 0; i < N; i++) {
        d.push_back(2000000000);
        u.push_back(0);
    }
    d[N - 1] = 0;
    priority_queue<pair<int, int>> qq;
    qq.push(make_pair(-d[N - 1], N - 1));

    while (!qq.empty()) {
        int v = qq.top().second;
        qq.pop();
        if (u[v]) {
            continue;
        }
        u[v] = 1;
        for (int i = pr[v]; i >= 0; i = ne[i]) {
            int to = A[i];
            if (u[to] == 0) {
                int val = d[v] + q[to][q_u[to]++];
                //cout << v << " " << to << " " << val << " " << endl;
                if (val < d[to]) {
                    d[to] = val;
                    qq.push(make_pair(-d[to], to));
                }
            }
        }
    }

    return (d[0]);
}

int AA[300005], BB[300005], CC[300005];
int main()
{

    //------------------------------------
    //  Read  input 
    //-----------------------------------
    int M, N, i;
    scanf("%d%d", &M, &N);
    for (i = 0; i<N; i++)
    {
        scanf("%d%d%d", &AA[i], &BB[i], &CC[i]);
    }

    printf("%d\n", ferries(M, N, AA, BB, CC));
//    system("pause");

    return 0;
}

Compilation message

ferries.cpp: In function 'int main()':
ferries.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &M, &N);
     ~~~~~^~~~~~~~~~~~~~~~
ferries.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &AA[i], &BB[i], &CC[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 13 ms 2324 KB Output is correct
4 Correct 125 ms 16616 KB Output is correct
5 Correct 126 ms 19608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 19608 KB Output is correct
2 Correct 3 ms 19608 KB Output is correct
3 Correct 12 ms 19608 KB Output is correct
4 Correct 59 ms 19608 KB Output is correct
5 Correct 113 ms 20256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 20256 KB Output is correct
2 Correct 21 ms 20256 KB Output is correct
3 Correct 238 ms 29148 KB Output is correct
4 Correct 335 ms 34080 KB Output is correct
5 Correct 209 ms 38212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 204 ms 43080 KB Output is correct
2 Correct 219 ms 48048 KB Output is correct
3 Correct 267 ms 53536 KB Output is correct
4 Correct 214 ms 58436 KB Output is correct
5 Correct 263 ms 63348 KB Output is correct