Submission #639736

# Submission time Handle Problem Language Result Execution time Memory
639736 2022-09-11T11:22:48 Z finn__ Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
545 ms 93340 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

typedef pair<unsigned, uint64_t> edge;

struct node
{
    unsigned u;
    uint64_t w;

    bool operator<(node const &x) const
    {
        return w > x.w;
    }
};

int travel_plan(int n, int m, int edges[][2], int len[], int k, int p[])
{
    vector<vector<edge>> g(n);

    for (unsigned i = 0; i < m; i++)
    {
        unsigned u = edges[i][0], v = edges[i][1];
        uint64_t w = len[i];
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }

    vector<uint64_t> d1(n, UINT64_MAX), d2(n, UINT64_MAX);
    priority_queue<node> q;
    vector<bool> finished(n, 0);

    for (unsigned i = 0; i < k; i++)
    {
        d1[p[i]] = 0;
        d2[p[i]] = 0;
        q.push((node){p[i], 0});
    }

    while (!q.empty())
    {
        unsigned u = q.top().u;
        uint64_t w = q.top().w;
        q.pop();

        if (!finished[u] && w == d2[u])
        {
            finished[u] = 1;

            if (w != UINT64_MAX)
            {
                for (auto const &[v, y] : g[u])
                {
                    if (!finished[v] && y != UINT64_MAX)
                    {
                        if (w + y < d1[v])
                        {
                            d2[v] = d1[v];
                            d1[v] = w + y;
                            q.push({v, d2[v]});
                        }
                        else if (w + y < d2[v])
                        {
                            d2[v] = w + y;
                            q.push({v, d2[v]});
                        }
                    }
                }
            }
        }
    }

    return d2[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:22:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   22 |     for (unsigned i = 0; i < m; i++)
      |                          ~~^~~
crocodile.cpp:34:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   34 |     for (unsigned i = 0; i < k; i++)
      |                          ~~^~~
crocodile.cpp:38:26: warning: narrowing conversion of '*(p + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'unsigned int' [-Wnarrowing]
   38 |         q.push((node){p[i], 0});
      |                       ~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 1084 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 3 ms 1084 KB Output is correct
13 Correct 3 ms 1108 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 404 ms 83528 KB Output is correct
17 Correct 87 ms 19792 KB Output is correct
18 Correct 102 ms 22228 KB Output is correct
19 Correct 545 ms 93340 KB Output is correct
20 Correct 257 ms 65740 KB Output is correct
21 Correct 37 ms 8680 KB Output is correct
22 Correct 289 ms 62936 KB Output is correct