Submission #530989

#TimeUsernameProblemLanguageResultExecution timeMemory
530989mat50013Crocodile's Underground City (IOI11_crocodile)C++11
0 / 100
1 ms1480 KiB
#include "crocodile.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int MAX_N(50005);
vector<pair<int, int> > G[MAX_N + 5];
ll dist[MAX_N + 5];
bool waiting[MAX_N + 5], viz[MAX_N + 5];
bool cmp(pair<int, int> a, pair<int, int> b)
{
    return (dist[a.first] + a.second) < (dist[b.first] + b.second);
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for(int i = 0; i < M; ++i)
        G[R[i][0]].push_back({R[i][1], L[i]}), G[R[i][1]].push_back({R[i][0], L[i]});
    for(int i = 0; i < N; ++i)
        dist[i] = LLONG_MAX / 2;
    queue<int> q;
    for(int i = 0; i < K; ++i)
    {
        dist[P[i]] = 0;
        q.push(P[i]);
    }
    while(!q.empty())
    {
        int nd = q.front();
        q.pop();
        waiting[nd] = 0;
        for(auto it: G[nd])
            if(dist[nd] + it.second < dist[it.first])
            {
                dist[it.first] = dist[nd] + it.second;
                if(!waiting[it.first])
                {
                    q.push(it.first);
                    waiting[it.first] = 1;
                }
            }
    }
    int timp = 0, curNd = 0;
    viz[curNd] = 1;
    while(dist[curNd] != 0)
    {
        sort(G[curNd].begin(), G[curNd].end(), cmp);
        for(int i = 1; i < (G[curNd].size()); ++i)
            if(!viz[G[curNd][i].first])
            {
                timp += G[curNd][i].second;
                curNd = G[curNd][i].first;
                viz[curNd] = 1;
                break;
            }
    }
    return timp;
}

Compilation message (stderr)

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:47: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]
   47 |         for(int i = 1; i < (G[curNd].size()); ++i)
      |                        ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...