読者です 読者をやめる 読者になる 読者になる

Codeforces Round #351 Div2 D: Bear and Two Paths

解法

埋め込み

コード

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  vector<bool> used(N + 1, false);
  used[a] = true;
  used[b] = true;
  used[c] = true;
  used[d] = true;

  if (N == 4) {
    cout << -1 << endl;
    return 0;
  }
  int e = 0;
  for (int i = 1; i <= N; ++i)
    if (!used[i]) {
      e = i;
      used[i] = true;
      break;
    }
  assert(e > 0);

  if (N == 5) {
    if (K < 6) {
      cout << -1 << endl;
      return 0;
    }
    cout << a << " " << c << " " << e << " " << d << " " << b << endl;
    cout << c << " " << a << " " << e << " " << b << " " << d << endl;
    return 0;
  }

  if (K < N - 1 + 2) {
    cout << -1 << endl;
    return 0;
  }

  cout << a << " ";
  for (int i = 1; i <= N; ++i) {
    if (!used[i]) {
      cout << i << " ";
    }
  }
  cout << c << " " << e << " " << d << " " << b << endl;

  cout << c << " ";
  for (int i = N; i >= 1; --i) {
    if (!used[i]) {
      cout << i << " ";
    }
  }
  cout << a << " " << e << " " << b << " " << d << endl;
}