Submission #670712

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

using namespace std;

#define INF 1999999999

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>, vector<pair<int, int>>, greater<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++)
        {
            if(!visited[city[P[i]][j].first])
                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++)
                {
                    if(!visited[city[curNode][j].first])
                        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();
    }

    return -1;
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
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:50: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]
   50 |                 for(int j = 0; j < city[curNode].size(); j++)
      |                                ~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 2 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 2 ms 432 KB Output isn't correct
10 Halted 0 ms 0 KB -