Submission #670709

# Submission time Handle Problem Language Result Execution time Memory
670709 2022-12-09T22:15:09 Z Stavab Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
0 ms 212 KB
#include "crocodile.h"
#include <vector>
#include <queue>
#include <utility>

using namespace std;

#define INF 19999999999

vector<vector<pair<int, int>>> city;
vector<int> times;
vector<int> visited;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    city.assign(N, vector<pair<int, int>>());
    times.assign(N, INF);
    visited.assign(N, 0);

    for (int i = 0; i < N - 1; i++)
    {
        city[R[i][0]].push_back(make_pair(R[i][1], L[i]));
        city[R[i][1]].push_back(make_pair(R[i][0], L[i]));
    }

    priority_queue<pair<int, int>> pq;
    for (int i = 0; i < K; i++)
    {
        times[P[i]] = 0;
        visited[P[i]] = 1;

        for(int j = 0; j < city[P[i]].size(); j++)
            pq.push(make_pair(city[P[i]][j].second, city[P[i]][j].first));
    }

    while(!pq.empty())
    {
        int curTime = pq.top().first;
        int curNode = pq.top().second;

        if(times[curNode] == INF)
            times[curNode] = curTime;
        else
        {
            if(!visited[curNode])
            {
                for(int j = 0; j < city[curNode].size(); j++)
                    pq.push(make_pair(curTime + city[curNode][j].second, city[curNode][j].first));

                visited[curNode] = 1;
                times[curNode] = curTime;

                if(curNode == 0)
                    return curTime;
            }
        }

        pq.pop();
    }
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:8:13: warning: overflow in conversion from 'long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '19999999999' to '-1474836481' [-Woverflow]
    8 | #define INF 19999999999
      |             ^~~~~~~~~~~
crocodile.cpp:17:21: note: in expansion of macro 'INF'
   17 |     times.assign(N, INF);
      |                     ^~~
crocodile.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = 0; j < city[P[i]].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~~~~~
crocodile.cpp:47:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |                 for(int j = 0; j < city[curNode].size(); j++)
      |                                ~~^~~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:26:36: warning: control reaches end of non-void function [-Wreturn-type]
   26 |     priority_queue<pair<int, int>> pq;
      |                                    ^~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -