답안 #410333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410333 2021-05-22T14:12:27 Z 600Mihnea 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
30 ms 11088 KB
#include <bits/stdc++.h>
#include "crocodile.h"

using namespace std;

typedef long long ll;

const int N = 100000 + 7;
const int INF = (int) 1e9 + 7;
int n, m, k, best[N];
multiset<int> adj[N];
vector<pair<int, int>> g[N];
priority_queue<pair<int, int>> q;

void push(int i, int value) {
  best[i] = value;
  for (auto &it : g[i]) {
    adj[it.first].insert(min(INF, best[i] + it.second));
  }
  q.push({-best[i], i});
}

int get_second(int a) {
  if ((int) adj[a].size() < 2) {
    return INF;
  }
  auto it = adj[a].begin();
  it++;
  return *it;
}

int travel_plan(int nn, int mm, int r[][2], int len[], int kk, int ch[]) {
  n = nn;
  m = mm;
  k = kk;
  for (int i = 0; i < n; i++) {
    g[i].clear();
    adj[i].clear();
    best[i] = INF;
  }
  for (int i = 0; i < m; i++) {
    g[r[i][0]].push_back({r[i][1], len[i]});
    g[r[i][1]].push_back({r[i][0], len[i]});
    adj[r[i][0]].insert(INF);
    adj[r[i][1]].insert(INF);
  }
  for (int i = 0; i < k; i++) {
    push(ch[i], 0);
  }
  int cnt = 0;
  while (!q.empty()) {
    int a = q.top().second, o = -q.top().first;
    q.pop();
    if (best[a] != o) {
      continue;
    }
    for (auto &it : g[a]) {
      int node = it.first, relax = get_second(node);
      if (relax < best[node]) {
        push(node, relax);
      }
    }
  }
  if (best[0] == INF) {
    best[0] = -1;
  }
  return best[0];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:50:7: warning: unused variable 'cnt' [-Wunused-variable]
   50 |   int cnt = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7580 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7500 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7580 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7500 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7628 KB Output is correct
9 Correct 12 ms 8652 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 8 ms 7884 KB Output is correct
12 Incorrect 30 ms 11088 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7580 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7500 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7628 KB Output is correct
9 Correct 12 ms 8652 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 8 ms 7884 KB Output is correct
12 Incorrect 30 ms 11088 KB Output isn't correct
13 Halted 0 ms 0 KB -