답안 #410331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410331 2021-05-22T14:07:02 Z 600Mihnea 악어의 지하 도시 (IOI11_crocodile) C++17
89 / 100
2000 ms 134396 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) {
  for (auto &it : g[i]) {
    adj[it.first].erase(adj[it.first].find(min(INF, best[i] + it.second)));
  }
  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:53:7: warning: unused variable 'cnt' [-Wunused-variable]
   53 |   int cnt = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 6 ms 7500 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7488 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 6 ms 7500 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7488 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7488 KB Output is correct
9 Correct 12 ms 8104 KB Output is correct
10 Correct 6 ms 7352 KB Output is correct
11 Correct 8 ms 7628 KB Output is correct
12 Correct 29 ms 8740 KB Output is correct
13 Correct 15 ms 8780 KB Output is correct
14 Correct 6 ms 7352 KB Output is correct
15 Correct 7 ms 7620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 6 ms 7500 KB Output is correct
5 Correct 6 ms 7500 KB Output is correct
6 Correct 6 ms 7488 KB Output is correct
7 Correct 6 ms 7500 KB Output is correct
8 Correct 6 ms 7488 KB Output is correct
9 Correct 12 ms 8104 KB Output is correct
10 Correct 6 ms 7352 KB Output is correct
11 Correct 8 ms 7628 KB Output is correct
12 Correct 29 ms 8740 KB Output is correct
13 Correct 15 ms 8780 KB Output is correct
14 Correct 6 ms 7352 KB Output is correct
15 Correct 7 ms 7620 KB Output is correct
16 Execution timed out 2023 ms 134396 KB Time limit exceeded
17 Halted 0 ms 0 KB -