답안 #305276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305276 2020-09-22T21:08:27 Z abeker 기지국 (IOI20_stations) C++17
0 / 100
2 ms 640 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;

typedef pair <int, int> pii;

vector <int> label(int N, int K, vector <int> u, vector <int> v) {
  vector <vector <int>> adj(N);
  for (int i = 0; i < N - 1; i++) {
    adj[u[i]].push_back(v[i]);
    adj[v[i]].push_back(u[i]);
  }
  int timer = 0;
  vector <pii> sorted;
  vector <int> labels(N);
  function <void(int, int, int)> dfs = [&](int x, int p, int d) {
    int disc = timer++;
    for (auto it : adj[x])
      if (it != p)
        dfs(it, x, d ^ 1);
    int fin = timer++;
    sorted.push_back({d ? fin : disc, x});
  };   
  sort(sorted.begin(), sorted.end());
  for (int i = 0; i < N; i++)
    labels[sorted[i].second] = i;
  return labels;
}

int find_next_station(int start, int dest, vector <int> neigh) { 
  int parent = -1;
  sort(neigh.begin(), neigh.end());
  if (start && start < neigh[0]) {
    parent = neigh.back();
    neigh.insert(neigh.begin(), start);
    neigh.pop_back();
  }
  else if (start > neigh.back()) {
    parent = neigh[0];	  
    neigh.erase(neigh.begin());
    neigh.push_back(start);
  }	
  for (int i = 1; i < neigh.size(); i++)
    if (dest > neigh[i - 1] && dest < neigh[i])
      return neigh[i - 1];
  return parent;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for (int i = 1; i < neigh.size(); i++)
      |                   ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -