제출 #1362368

#제출 시각아이디문제언어결과실행 시간메모리
1362368lyra_g13Stations (IOI20_stations)C++20
100 / 100
290 ms592 KiB
#include "stations.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

vector<int> label(int n, int k, vector<int> u, vector<int> v) {

  vector<vector<ll>> adj(n);
  for (int i = 0; i < n - 1; i++) {
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }

  vector<ll> in(n), out(n);
  vector<ll> vis(n), dist(n);
  ll timer = 0;

  auto dfs = [&](auto &&self, ll u) {
    if (vis[u])
      return;
    timer++;
    in[u] = timer;
    vis[u] = 1;
    for (auto v : adj[u]) {
      if (vis[v])
        continue;
      dist[v] = dist[u] + 1;
      self(self, v);
    }
    out[u] = timer;
    timer++;
  };

  dfs(dfs, 0);

  vector<int> buff(n);

  for (int i = 0; i < n; i++) {
    if (dist[i] % 2 == 0) {
      buff[i] = in[i];
    } else {
      buff[i] = out[i];
    }
  }

  vector<int> label = buff;
  sort(buff.begin(), buff.end());
  buff.erase(unique(buff.begin(), buff.end()), buff.end());

  auto get = [&](ll u) {
    return lower_bound(buff.begin(), buff.end(), u) - buff.begin();
  };

  for (int i = 0; i < n; i++) {
    label[i] = get(label[i]);
  }

  return label;
};

int find_next_station(int s, int t, vector<int> c) {

  if (s < c[0]) {

    if (t < s or t > c[c.size() - 1])
      return c[c.size() - 1];
    for (int i = 0; i < c.size(); i++) {
      if (s < t and t <= c[i]) {
        return c[i];
      } else {
        s = c[i];
      }
    }
  } else {
    for (int i = 1; i < c.size(); i++) {
      if (i == c.size() - 1) {
        if (s > t and c[i] <= t) {
          return c[i];
        } else {
          return c[0];
        }
      } else {
        if (c[i] <= t and t < c[i + 1]) {
          return c[i];
        }
      }
    }
    return c[0];
  }
};

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
   90 | };
      | ^
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…