Submission #757773

# Submission time Handle Problem Language Result Execution time Memory
757773 2023-06-13T18:17:09 Z taher Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
539 ms 89684 KB
#include <bits/stdc++.h>
#include "crocodile.h"

using namespace std;

const long long inf = 200000000000000;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
  int n = N;
  int m = M;
  int k = K;

  vector<vector<array<long long, 2>>> adj(n);
  for (int i = 0; i < m; i++) {
    int u = R[i][0];
    int v = R[i][1];
    int t = L[i];
    adj[u].push_back({v, t});
    adj[v].push_back({u, t});
  }
  vector<int> leaves(k);
  for (int i = 0; i < k; i++) {
    leaves[i] = P[i];
  }
  priority_queue<array<long long, 2>, vector<array<long long, 2>>, greater<array<long long, 2>>> pQue;
  
  vector<long long> d(n, inf);  // good
  vector<long long> p(n, inf);  // min
  vector<bool> done(n);
  vector<int> cnt(n);
  vector<bool> mark(n);
  for (auto x : leaves) {
    mark[x] = true;
    d[x] = 0;
    p[x] = 0;
    pQue.push({d[x], x});
  }
  while (!pQue.empty()) {
    auto t = pQue.top();
    pQue.pop();
    if (done[t[1]]) {
      continue;
    }
    done[t[1]] = true;
    for (auto x : adj[t[1]]) {
      cnt[x[0]]++;
      if (cnt[x[0]] == 1) {
        d[x[0]] = x[1] + t[0];
        p[x[0]] = x[1] + t[0];
      } else if (cnt[x[0]] == 2) {
        d[x[0]] = max(d[x[0]], x[1] + t[0]);
        p[x[0]] = min(p[x[0]], x[1] + t[0]);
        pQue.push({d[x[0]], x[0]});
      } else {
        if (x[1] + t[0] <= p[x[0]]) {
          d[x[0]] = p[x[0]];
          pQue.push({d[x[0]], x[0]});
          p[x[0]] = x[1] + t[0];
        } else if (x[1] + t[0] < d[x[0]]) {
          d[x[0]] = x[1] + t[0];
          pQue.push({d[x[0]], x[0]});
        }
      }
    }
  }
  return d[0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 444 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 980 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 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 444 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 444 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 980 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 403 ms 81656 KB Output is correct
17 Correct 72 ms 18012 KB Output is correct
18 Correct 95 ms 20460 KB Output is correct
19 Correct 539 ms 89684 KB Output is correct
20 Correct 293 ms 65772 KB Output is correct
21 Correct 37 ms 8144 KB Output is correct
22 Correct 294 ms 62556 KB Output is correct