Submission #169023

# Submission time Handle Problem Language Result Execution time Memory
169023 2019-12-17T20:06:09 Z AlexLuchianov Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
680 ms 67304 KB
#include "crocodile.h"
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;

struct Edge{
  int to;
  int cost;
  bool operator < (Edge const &a) const{
    return cost > a.cost;
  }
};
std::vector<Edge> g[1 + nmax];

int dpcount[1 + nmax], dp[1 + nmax];

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]});
  }
  std::priority_queue<Edge> pq;
  for(int i = 0; i < K; i++) {
    dpcount[P[i]] = 1;
    pq.push({P[i], 0 });
  }

  while(0 < pq.size()){
    int node = pq.top().to;
    int cost = pq.top().cost;
    pq.pop();
    dpcount[node]++;
    if(dpcount[node] == 2){
      dp[node] = cost;
      if(node == 0)
        break;
      for(int h = 0; h < g[node].size(); h++){
        Edge e = g[node][h];
        if(dpcount[e.to] < 2)
          pq.push({e.to, dp[node] + e.cost});
      }
    }
  }

  if(dpcount[0] < 2)
    return -1;
  else
    return dp[0];
}


Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:45:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int h = 0; h < g[node].size(); h++){
                      ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 6 ms 3192 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 9 ms 3320 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 5 ms 2808 KB Output is correct
5 Correct 5 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 6 ms 3192 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 9 ms 3320 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 593 ms 64596 KB Output is correct
17 Correct 98 ms 13816 KB Output is correct
18 Correct 109 ms 15284 KB Output is correct
19 Correct 680 ms 67304 KB Output is correct
20 Correct 368 ms 58164 KB Output is correct
21 Correct 53 ms 7672 KB Output is correct
22 Correct 476 ms 46300 KB Output is correct