답안 #319652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319652 2020-11-06T03:05:44 Z spatarel 기지국 (IOI20_stations) C++17
0 / 100
4 ms 700 KB
#include "stations.h"
#include <algorithm>
//#include <stdio.h>
#include <vector>

const int MAX_N = 1000;

bool visited[1 + MAX_N];
std::vector<int> neighbours[1 + MAX_N];

int counter;

void visit(std::vector<int> &labels, int u) {
  labels[u] = counter;
  //printf("%d->%d\n", u, counter);
  counter++;
}

void dfs(std::vector<int> &labels, int u, bool parity = true) {
  visited[u] = true;
  if (parity) {
    visit(labels, u);
  }
  for (int v : neighbours[u]) {
    if (!visited[v]) {
      dfs(labels, v, !parity);
    }
  }
  if (!parity) {
    visit(labels, u);
  }
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  std::vector<int> labels(n);
  for (int i = 0; i < n - 1; i++) {
    neighbours[u[i]].push_back(v[i]);
    neighbours[v[i]].push_back(u[i]);
  }
  counter = 0;
  dfs(labels, 0);
  return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
  int answer;
  std::sort(c.begin(), c.end());
  /*
  for (int n : c) {
    printf("%d ", n);
  }
  printf("\n");//*/
  if (s < c[0]) {
    int p = c.back();
    int l = s;
    int r = c.end()[-2];
    if (l <= t && t <= r) {
      int i = 0;
      while (c[i] <= t) {
        i++;
      }
      answer = c[i - 1];
    } else {
      answer = p;
    }
  } else {
    int p = c[0];
    int l = c[1];
    int r = s;
    //printf("%d %d\n", l, r);
    if (l <= t && t <= r) {
      int i = 1;
      while (i < (int)c.size() && c[i] <= t) {
        i++;
      }
      answer = c[i - 1];
    } else {
      answer = p;
    }
  }
  //printf("%d->%d (%d)\n", s, t, answer);
  return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 700 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 492 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 652 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 492 KB Invalid labels (duplicates values). scenario=1, label=0
2 Halted 0 ms 0 KB -