text
stringlengths
49
983k
#include <bits/stdc++.h> namespace xxx { using namespace std; const double EPS = 1e-8; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline long long rd() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long pow_mod(long long a, long long n) { if (n == 0) return 1; long long x = pow_mod(a, n / 2); long long ans = x * x % MOD; if (n & 1) ans = ans * a % MOD; return ans; } } // namespace xxx using namespace xxx; const int M = 2e5 + 20; const int N = 2e5 + 20; int n, k, a, b, c, d; int path[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; cin >> a >> b >> c >> d; if (n < 5 || k < n + 1) { cout << -1 << endl; exit(0); } path[1] = a; path[2] = c; path[n] = b; path[n - 1] = d; for (int i = 3, j = 1; i <= n - 2; i++, j++) { while (j == a || j == b || j == c || j == d) j++; path[i] = j; } for (int i = 1; i <= n; i++) { cout << path[i] << ' '; } cout << endl; swap(path[1], path[2]); swap(path[n], path[n - 1]); for (int i = 1; i <= n; i++) { cout << path[i] << ' '; } cout << endl; exit(0); }
#include <bits/stdc++.h> using namespace std; vector<int> arr; int main() { int n, k; int a, b, c, d; cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << -1; return 0; } printf("%d %d ", a, c); for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) printf("%d ", i); } printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) printf("%d ", i); } printf("%d %d", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000 + 5; int main() { int n, k; while (scanf("%d%d", &n, &k) != EOF) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); if (n == 4 || k <= n) { printf("-1\n"); } else { printf("%d %d ", a, c); for (int i = 1; i <= n; i++) { if (!(i == a || i == b || i == c || i == d)) { printf("%d ", i); } } printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 1; i <= n; i++) { if (!(i == a || i == b || i == c || i == d)) { printf("%d ", i); } } printf("%d %d\n", b, d); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (k > n && n > 4) { vector<int> path; path.push_back(a); path.push_back(c); for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) path.push_back(i); } path.push_back(d); path.push_back(b); if (path.size() > k) { cout << -1; exit(0); } for (int i = 0; i < n; i++) { cout << path[i] << ' '; } cout << '\n'; path.clear(); path.push_back(c); path.push_back(a); for (int i = 1; i <= n; i++) { if (i != c && i != d && i != a && i != b) path.push_back(i); } path.push_back(b); path.push_back(d); for (int i = 0; i < n; i++) { cout << path[i] << ' '; } } else cout << -1; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target( \ "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long MOD = 1e9 + 7; long long INF = 1e18; long long a, b, c, d; long long gd(long long x) { return x != a && x != b && x != c && x != d; } signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20); long long n, k; cin >> n >> k; cin >> a >> b >> c >> d; if (n == 4 || k < n + 1) { cout << "-1"; return 0; } cout << a << " " << c << " "; vector<long long> ans; for (int i = 0; i < n; i++) { if (gd(i + 1)) { cout << i + 1 << " "; ans.push_back(i + 1); } } cout << d << " " << b << "\n"; cout << c << " " << a << " "; reverse(ans.begin(), ans.end()); for (auto i : ans) { cout << i << " "; } cout << b << " " << d << "\n"; }
#include <bits/stdc++.h> using std::abs; using std::array; using std::cerr; using std::cin; using std::cout; using std::make_pair; using std::map; using std::max; using std::min; using std::pair; using std::set; using std::string; using std::vector; template <typename T> T input() { T res; cin >> res; return res; } int main() { std::iostream::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); uint32_t n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n or n == 4) cout << "-1\n"; else { vector<uint32_t> list; for (uint32_t i = 1; i <= n; ++i) if (i != a and i != b and i != c and i != d) list.push_back(i); assert(list.size() == n - 4); cout << a << " " << c << " "; for (auto v : list) cout << v << " "; cout << d << " " << b << "\n"; cout << c << " " << a << " "; for (auto v : list) cout << v << " "; cout << b << " " << d << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a, b, c, d; scanf("%d %d", &n, &k); scanf("%d %d %d %d", &a, &b, &c, &d); if (n == 4 || k <= n) { printf("%d\n", -1); return 0; } vector<int> z; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { z.push_back(i); } } int x = z.back(); z.pop_back(); printf("%d", a); for (int i = 0; i < (int)z.size(); i++) { printf(" %d", z[i]); } printf(" %d %d %d %d\n", c, x, d, b); printf("%d", c); for (int i = (int)z.size() - 1; i >= 0; i--) { printf(" %d", z[i]); } printf(" %d %d %d %d\n", a, x, b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k; cin >> n >> k; if (k < n + 1 || n == 4) { cout << -1 << endl; return 0; } int a, b, c, d; cin >> a >> b >> c >> d; vector<int> p; for (int i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d) continue; p.push_back(i); } cout << a << " " << c << " "; for (int i = 0; i < n - 4; i++) cout << p[i] << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 0; i < n - 4; i++) cout << p[i] << " "; cout << b << " " << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i; int a, b, c, d; scanf("%d%d", &n, &m); scanf("%d%d%d%d", &a, &b, &c, &d); if (a == c) { if (b == d) { printf("%d ", a); for (i = 1; i <= n; i++) if (i != a && i != b) printf("%d ", i); printf("%d\n", b); printf("%d ", a); for (i = 1; i <= n; i++) if (i != a && i != b) printf("%d ", i); printf("%d\n", b); } else { if (m == n - 1) printf("-1\n"); else { printf("%d ", a); for (i = 1; i <= n; i++) if (i != a && i != b && i != d) printf("%d ", i); printf("%d %d\n", b, d); printf("%d ", a); for (i = 1; i <= n; i++) if (i != a && i != b && i != d) printf("%d ", i); printf("%d %d\n", d, b); } } } else { if (b == d) { if (m == n - 1) printf("-1\n"); else { printf("%d %d ", a, c); for (i = 1; i <= n; i++) if (i != a && i != c && i != b) printf("%d ", i); printf("%d\n", b); printf("%d %d ", c, a); for (i = 1; i <= n; i++) if (i != c && i != a && i != d) printf("%d ", i); printf("%d\n", d); } } else { if (m <= n || n == 4) printf("-1\n"); else { printf("%d %d ", a, c); for (i = 1; i <= n; i++) if (i != a && i != c && i != b && i != d) printf("%d ", i); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (i = 1; i <= n; i++) if (i != a && i != c && i != b && i != d) printf("%d ", i); printf("%d %d\n", b, d); } } } }
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << "[" << *it << " = " << a << "] "; err(++it, args...); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, edges; cin >> n >> edges; long long int a, b, c, d; cin >> a >> b >> c >> d; if (edges == n - 1 || edges == n || (a == c && b == d) || (a == d && b == c) || n < 5) { if ((a == c && b == d) || (a == d && b == c)) { cout << a << " "; for (long long int i = 1; i <= n; i++) { if (i != a && i != b) { cout << i << " "; } } cout << b << '\n' << c << " "; for (long long int i = 1; i <= n; i++) { if (i != c && i != d) { cout << i << ' '; } } cout << d << '\n'; } else { cout << -1 << '\n'; } } else { cout << a << " " << c << " "; for (long long int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { cout << i << " "; } } cout << d << " " << b << '\n'; cout << c << " " << a << " "; for (long long int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { cout << i << " "; } } cout << b << " " << d << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; inline void read(int &first) { first = 0; while (1) { char ch = getchar(); if (ch == ' ' || ch == '\n') break; first = first * 10 + ch - '0'; } } inline void write(int first) { char wr[12]; int k = 0; if (!first) ++k, wr[k] = '0'; while (first) { ++k; wr[k] = char(first % 10 + '0'); first /= 10; } for (int i = k; i >= 1; --i) putchar(wr[i]); } const int N = 1e5; int n, k, a, b, c, d; vector<int> v; bool used[N]; bool dd[1002][1002]; int s; bool f(vector<int> v) { for (int i = 1; i < v.size(); ++i) { int first = v[i - 1]; int second = v[i]; dd[first][second] = dd[second][first] = 1; if (first == a && second == b) { cout << -1; exit(0); } if (first == b && second == a) { cout << -1; exit(0); } if (first == c && second == d) { cout << -1; exit(0); } if (first == d && second == c) { cout << -1; exit(0); } } } vector<int> X, Y; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; cin >> a >> b >> c >> d; v.push_back(a); v.push_back(c); used[a] = used[c] = used[b] = used[d] = 1; while (1) { bool p = 0; for (int i = 1; i <= n; ++i) if (!used[i]) { v.push_back(i); used[i] = 1; p = 1; } if (!p) break; } v.push_back(d); v.push_back(b); for (int i = 1; i < v.size(); ++i) { int first = v[i - 1]; int second = v[i]; if (first == a && second == b) return cout << -1, 0; if (first == b && second == a) return cout << -1, 0; if (first == c && second == d) return cout << -1, 0; if (first == d && second == c) return cout << -1, 0; } for (int i = 0; i < v.size(); ++i) X.push_back(v[i]); Y.push_back(v[1]); Y.push_back(v[0]); for (int i = 2; i < v.size() - 2; ++i) Y.push_back(v[i]); Y.push_back(v.back()); Y.push_back(v[v.size() - 2]); f(X); f(Y); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) s += dd[i][j]; s /= 2; if (s > k) return cout << -1, 0; for (int i = 0; i < X.size(); ++i) cout << X[i] << ' '; cout << "\n"; for (int i = 0; i < Y.size(); ++i) cout << Y[i] << ' '; }
#include <bits/stdc++.h> using namespace std; bool vis[100005]; int main() { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; vis[a] = vis[b] = vis[c] = vis[d] = 1; if (n <= 4 || k <= n) { cout << "-1" << endl; } else { cout << a << " " << c << " "; for (int i = 1; i <= n; i++) if (!vis[i]) cout << i << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 1; i <= n; i++) if (!vis[i]) cout << i << " "; cout << b << " " << d << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == 4 || k < n + 1) { cout << -1 << '\n'; return 0; } int a, b, c, d; cin >> a >> b >> c >> d; int taken[n + 1]; for (int i = 0; i <= n; i++) taken[i] = 0; taken[a] = taken[b] = taken[c] = taken[d] = 1; cout << a << " " << c << " "; for (int i = 1; i <= n; i++) if (!taken[i]) cout << i << " "; cout << d << " " << b << '\n'; cout << c << " " << a << " "; for (int i = 1; i <= n; i++) if (!taken[i]) cout << i << " "; cout << b << " " << d << '\n'; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long M = 1e6 + 5; const long long mod = 1e9 + 7; long long a[505][505], ans[505], x[505]; signed main() { long long n, k; cin >> n >> k; long long a, b, c, d; cin >> a >> b >> c >> d; if (k < n + 1 || n <= 4) { cout << -1; return 0; } cout << a << " " << c << " "; for (long long i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) cout << i << " "; cout << d << " " << b << "\n"; cout << c << " " << a << " "; for (long long i = 1; i <= n; ++i) if (i != a && i != b && i != c && i != d) cout << i << " "; cout << b << " " << d << "\n"; }
#include <bits/stdc++.h> using namespace std; int n, k; int v[101001]; int main() { scanf("%d%d", &n, &k); if (k <= n || n == 4) printf("-1\n"); else { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); v[a] = v[b] = v[c] = v[d] = 1; printf("%d %d ", a, c); for (int i = 1; i <= n; i++) if (!v[i]) printf("%d ", i); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 1; i <= n; i++) if (!v[i]) printf("%d ", i); printf("%d %d\n", b, d); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int nnnnext[N], pos[N]; int main() { int n, k; int a, b, c, d; cin >> n >> k >> a >> b >> c >> d; a--, b--, c--, d--; if (k <= n || n == 4) { puts("-1"); return 0; } for (int i = 0; (i) < (n); ++i) { nnnnext[i] = i; pos[i] = i; } swap(pos[a], pos[0]); swap(nnnnext[a], nnnnext[0]); swap(pos[b], pos[nnnnext[n - 1]]); swap(nnnnext[pos[nnnnext[n - 1]]], nnnnext[n - 1]); swap(pos[c], pos[nnnnext[1]]); swap(nnnnext[pos[nnnnext[1]]], nnnnext[1]); swap(pos[d], pos[nnnnext[n - 2]]); swap(nnnnext[pos[nnnnext[n - 2]]], nnnnext[n - 2]); for (int i = 0; (i) < (n); ++i) { cout << nnnnext[i] + 1 << " "; } cout << '\n'; cout << c + 1 << " " << a + 1 << " "; for (int i = (2); (i) < (n - 2); ++i) cout << nnnnext[i] + 1 << " "; cout << b + 1 << " " << d + 1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, a, b, c, d, now, f[1001]; bool jud[1001]; int main() { cin.sync_with_stdio(false); cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << -1 << endl; return 0; } f[1] = a; f[2] = c; f[n - 1] = d; f[n] = b; jud[a] = jud[b] = jud[c] = jud[d] = true; int now = 1; for (int i = 3; i <= n - 2; i++) { while (jud[now]) now++; f[i] = now; now++; } for (int i = 1; i <= n - 1; i++) cout << f[i] << " "; cout << f[n] << endl; cout << f[2] << " " << f[1] << " "; for (int i = 3; i <= n - 2; i++) cout << f[i] << " "; cout << f[n] << " " << f[n - 1]; }
#include <bits/stdc++.h> using namespace std; int mark[5020]; int main() { int n, k; while (cin >> n >> k) { int a, b, c, d; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) cout << -1 << endl; else { mark[a] = mark[b] = mark[c] = mark[d] = 1; cout << a << ' ' << c << ' '; for (int i = 1; i <= n; ++i) if (!mark[i]) cout << i << ' '; cout << d << ' ' << b << endl; cout << c << ' ' << a << ' '; for (int i = 1; i <= n; ++i) if (!mark[i]) cout << i << ' '; cout << b << ' ' << d << endl; mark[a] = mark[b] = mark[c] = mark[d] = 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; template <typename T> void db(T x) { debug() << ">>> " << x; } template <typename T> void db(T x, T y) { debug() << ">>> " << x << " , " << y; } template <typename T> void db(T x, T y, T z) { debug() << ">>> " << x << " , " << y << " , " << z; } template <typename T> void db(T x, T y, T z, T a) { debug() << ">>> " << x << " , " << y << " , " << z << " , " << a; } const long long xx = 2e5; const long long Mod = 1e9 + 7; const long long inf = 1e18; const long long Maxn = 20010; void _p(vector<long long>& a) { for (long long i = 0; i < (long long)a.size(); i++) { cout << a[i] << " "; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; long long a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) { cout << -1 << '\n'; return 0; } vector<long long> Mid; for (long long i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { Mid.push_back(i); } } cout << a << " " << c << " "; _p(Mid); cout << d << " " << b << '\n'; cout << c << " " << a << " "; _p(Mid); cout << b << " " << d << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) { cout << -1; return 0; } cout << a << " " << c << " "; int visited[1001]; memset(visited, 0, sizeof visited); visited[a] = 1; visited[b] = 1; visited[c] = 1; visited[d] = 1; for (int i = 1; i <= n; i++) { if (visited[i] == 0) { cout << i << " "; } } cout << d << " " << b << endl; memset(visited, 0, sizeof visited); visited[a] = 1; cout << c << " " << a << " "; visited[b] = 1; visited[c] = 1; visited[d] = 1; for (int i = 1; i <= n; i++) { if (visited[i] == 0) { cout << i << " "; } } cout << b << " " << d << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, a, b, c, d; vector<long long> vec; cin >> n >> k >> a >> b >> c >> d; if (n == 4 || n >= k) cout << "-1" << endl; else { for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) vec.push_back(i); } cout << a << " " << c << " "; for (int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << b << " " << d << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 1000000007) x -= 1000000007; if (x < 0) x += 1000000007; return x; } long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long pw(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return ans; } int v1[2002], v2[2002]; bool oki[1002][1002], ps[1002]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, a, b, c, d; cin >> n >> k; cin >> a >> b >> c >> d; v1[1] = a; v1[n] = b; v1[2] = c; v1[n - 1] = d; ps[a] = ps[b] = ps[c] = ps[d] = 1; int len = 3; for (int i = 1; i <= n; ++i) if (!ps[i]) v1[len++] = i, ps[i] = 1; for (int i = 1; i <= n; ++i) v2[i] = v1[i]; swap(v2[1], v2[2]); swap(v2[n], v2[n - 1]); for (int i = 1; i < n; ++i) { oki[v2[i]][v2[i + 1]] = oki[v2[i + 1]][v2[i]] = 1; oki[v1[i]][v1[i + 1]] = oki[v1[i + 1]][v1[i]] = 1; } int nr = 0; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) nr += oki[i][j]; if (oki[a][b] || oki[c][d] || nr > k) { cout << -1; return 0; } for (int i = 1; i <= n; ++i) cout << v1[i] << " "; cout << '\n'; for (int i = 1; i <= n; ++i) cout << v2[i] << " "; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; { long int n, k, i, a, b, c, d, pos; cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << -1; return 0; } long int p[n], v[n]; memset(p, -1, sizeof p); p[0] = a; p[n - 1] = b; p[n - 2] = d; p[1] = c; k = 1; for (i = 0; i < n; i++) { if (p[i] != -1) continue; while (k == a || k == b || k == c || k == d) k++; p[i] = k; k++; } for (long int i : p) cout << i << ' '; cout << '\n'; cout << c << ' ' << a << " "; for (i = 2; i < n - 2; i++) cout << p[i] << " "; cout << b << ' ' << d; cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> used; vector<int> ans; int main() { ios::sync_with_stdio(false); int n, k, a, b, c, d; scanf("%d %d %d %d %d %d", &n, &k, &a, &b, &c, &d); used.resize(n + 1, 0); if (n < 5 || k <= n) { printf("-1"); return 0; } used[a]++; used[b]++; used[c]++; used[d]++; ans.push_back(a); ans.push_back(c); for (int i = 0; i < n; i++) { if (!used[i + 1]) ans.push_back(i + 1); } ans.push_back(d); ans.push_back(b); for (auto v : ans) { printf("%d ", v); } printf("\n%d %d ", ans[1], ans[0]); for (int i = 2; i < n - 2; i++) { printf("%d ", ans[i]); } printf("%d %d\n", ans[n - 1], ans[n - 2]); }
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return a * (b / gcd(a, b)); } long long int power(long long int a, long long int b) { long long int ans = 1; while (b > 0) { if (b & 1) ans = ((ans % 1000000007) * (a % 1000000007)) % 1000000007; a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; b >>= 1; } return ans; } int arr[2000], brr[2000]; int main() { int i, n, k, a, b, c, d, fixed = 5; cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4 || a == b || c == d) cout << "-1" << endl; else { arr[a] = arr[b] = arr[c] = arr[d] = 1; int ind = 0; for (i = 1; i < n + 1; i++) if (!arr[i]) brr[ind++] = i; fixed = brr[0]; arr[fixed] = 1; cout << a << " "; for (i = 1; i < ind; i++) cout << brr[i] << " "; cout << c << " " << fixed << " " << d << " " << b << endl; cout << c << " "; for (i = ind - 1; i > 0; i--) cout << brr[i] << " "; cout << a << " " << fixed << " " << b << " " << d << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int mxn = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, k, a, b, c, d, i; cin >> n >> k >> a >> b >> c >> d; if (k < n + 1 or n == 4) { cout << -1; return 0; } vector<int> loser; loser.push_back(a); for (i = 1; i < n + 1; i++) { if (i != a and i != b and i != c and i != d) loser.push_back(i); } loser.push_back(b); cout << a << " " << c << " "; for (i = 1; i < loser.size() - 1; i++) cout << loser[i] << " "; cout << d << " " << b; cout << "\n"; cout << c << " "; for (i = 0; i < loser.size(); i++) cout << loser[i] << " "; cout << d << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; if (n <= 4 || k < n + 1) cout << "-1\n"; else { int a, b, c, d, ind = 1; cin >> a >> b >> c >> d; vector<int> V(n + 1), order(n); V[a] = V[b] = V[c] = V[d] = 1; order[0] = a, order[1] = c, order[n - 2] = d, order[n - 1] = b; for (int i = 0; i < n; ++i) { if (order[i]) continue; while (V[ind]) ind++; V[ind] = 1; order[i] = ind; } for (int i = 0; i < n; ++i) cout << order[i] << " "; cout << "\n"; cout << c << " " << a << " "; for (int i = 2; i < n - 2; ++i) cout << order[i] << " "; cout << b << " " << d << "\n"; } return 0; }
#include <bits/stdc++.h> const int N = 1000; int e[N + 10]; int main() { int n = 0; int a = 0; int b = 0; int c = 0; int d = 0; int k = 0; scanf("%d%d%d%d%d%d", &n, &k, e + 1, e + 2, e + 3, e + 4); if (k < n + 1 || n == 4) { printf("-1\n"); return 0; } int tot = 0; for (int i = 5; i <= n; i++) { tot++; while (tot == e[1] || tot == e[2] || tot == e[3] || tot == e[4]) tot++; e[i] = tot; } printf("%d %d %d", e[1], e[3], e[n]); for (int i = n - 1; i >= 5; i--) printf(" %d", e[i]); printf(" %d %d\n", e[4], e[2]); printf("%d %d %d", e[3], e[1], e[n]); for (int i = n - 1; i >= 5; i--) printf(" %d", e[i]); printf(" %d %d\n", e[2], e[4]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000; vector<int> path; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; a--; b--; c--; d--; if (k < n + 1) { cout << -1; return 0; } int e = 2, last = -1; for (int i = 0; i < n;) if (i == a || i == b || i == c || i == d) i++; else { last = i; path.push_back(i); bool dif = false; for (int j = i + 1; j < n; j++) if (j != a && j != b && j != c && j != d) { i = j; e++; dif = true; break; } if (!dif) break; } if (n > 4) e += 2; if (last != -1) e += 2; if (e < n + 1) { cout << -1; return 0; } cout << a + 1 << ' ' << c + 1 << ' '; for (int i = 0; i < n - 4; i++) cout << path[i] + 1 << ' '; cout << d + 1 << ' ' << b + 1 << endl; cout << c + 1 << ' ' << a + 1 << ' '; for (int i = 0; i < n - 4; i++) cout << path[i] + 1 << ' '; cout << b + 1 << ' ' << d + 1; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> vi; const int mod = int(1e9) + 7, INF = 0x3fffffff; const int maxn = 1e5 + 13; int main(void) { int n, k; scanf("%d", &(n)), scanf("%d", &(k)); int a, b, c, d; scanf("%d", &(a)), scanf("%d", &(b)), scanf("%d", &(c)), scanf("%d", &(d)); bool ok = false; if (n == 4) { cout << -1 << endl; } else { if (k >= n + 1) ok = true; else cout << -1 << endl; } if (ok) { cout << a << " " << c << " "; for (int i = 1; i <= n; i++) { if (i != a && i != c && i != d && i != b) cout << i << " "; } cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 1; i <= n; i++) { if (i != a && i != c && i != d && i != b) cout << i << " "; } cout << b << " " << d << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; double pi = 3.141592653589793238462; string numkey = "0123456789"; string uni = "abcdefghijklmnopqrstuvwxyz"; long long int dx[4] = {0, 0, 1, -1}; long long int dy[4] = {1, -1, 0, 0}; long long int INF = (1LL << 62); signed main() { long long int n, k; cin >> n >> k; long long int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) { cout << "-1"; return 0; } set<long long int> s({a, b, c, d}); vector<long long int> v; for (long long int i = 1; i <= n; i++) { if (s.count(i) == 0) v.push_back(i); } cout << a << " " << c << " "; for (long long int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << d << " " << b << "\n"; cout << c << " " << a << " "; for (long long int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << b << " " << d << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, c, s, d, i, j; cin >> a >> c; long long a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; if (a == 5) { if (c > 5) { long long sum = 15; sum = sum - a1 - a2 - a3 - a4; cout << a1 << " " << a3 << " " << sum << " " << a4 << " " << a2 << endl; cout << a3 << " " << a1 << " " << sum << " " << a2 << " " << a4 << endl; } else { cout << -1; return 0; } } if (a > 5) { if (c < a + 1) { cout << -1; return 0; } vector<long long> vec(2000, 0); vec[0] = a1; vec[2] = a3; vec[a - 2] = a4; vec[a - 1] = a2; long long col = 0; vector<long long> ch; for (i = 1; i <= a; i++) if ((i != a1) && (i != a2) && (i != a3) && (i != a4)) ch.push_back(i); for (i = 0; i < a; i++) { if (vec[i] == 0) { vec[i] = ch[col]; col++; } } cout << endl; for (i = 0; i < a; i++) cout << vec[i] << " "; cout << endl; for (i = 2; i < a - 2; i++) cout << vec[i] << " "; cout << vec[0] << " "; cout << vec[1] << " "; cout << vec[a - 1] << " "; cout << vec[a - 2] << " "; } if (a < 5) { cout << -1; return 0; } }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, k; int main() { ios_base::sync_with_stdio(0); clock_t _ = clock(); while (scanf("%d%d", &n, &k) == 2) { int a[5]; for (int i = 1; i <= 4; ++i) scanf("%d", a + i); if (n == 4 || n - 4 - 1 + 6 > k) { puts("-1"); continue; } printf("%d %d ", a[1], a[3]); for (int i = 1; i <= n; ++i) { bool ok = true; for (int j = 1; j <= 4; ++j) if (i == a[j]) ok = false; if (!ok) continue; printf("%d ", i); } printf("%d %d\n", a[4], a[2]); printf("%d %d ", a[3], a[1]); for (int i = 1; i <= n; ++i) { bool ok = true; for (int j = 1; j <= 4; ++j) if (i == a[j]) ok = false; if (!ok) continue; printf("%d ", i); } printf("%d %d\n", a[2], a[4]); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; vector<long long> g[3005], vis(3005); set<long long> cycle; stack<long long> s; bool dfs(long long x, long long p) { vis[x] = 1; s.push(x); for (auto i : g[x]) { if (vis[i] && i != p) { while (s.top() != i) { cycle.insert(s.top()); s.pop(); } cycle.insert(i); return 0; } else if (!vis[i]) { if (!dfs(i, x)) return 0; } } s.pop(); return 1; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long a, b, c, d; cin >> a >> b >> c >> d; if (n == 4) { cout << -1 << "\n"; return 0; } if (k < n + 1) { cout << -1 << "\n"; return 0; } vector<long long> v; for (long long i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d) continue; v.push_back(i); } cout << a << " " << c << " "; for (long long i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << d << " " << b << "\n"; cout << c << " " << a << " "; for (long long i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << b << " " << d << "\n"; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long a, b, c, d; cin >> a >> b >> c >> d; if (k <= n) { cout << -1; return; } set<long long> s; for (long long i = 1; i < n + 1; i++) s.insert(i); s.erase(a); s.erase(b); s.erase(c); s.erase(d); if ((long long)s.size() == 0) { cout << -1; return; } cout << a << " " << c << " "; for (auto x : s) cout << x << " "; cout << d << " " << b << '\n'; swap(a, c); swap(b, d); cout << a << " " << c << " "; for (auto x : s) cout << x << " "; cout << d << " " << b << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long TESTS = 1; while (TESTS--) { solve(); } return 0; }
#include <bits/stdc++.h> const int MN = 1001; int n, k, a, b, c, d; int main() { scanf("%d%d%d%d%d%d", &n, &k, &a, &b, &c, &d); if (n == 4) printf("-1\n"); else if (k < n + 1) printf("-1\n"); else { int arr[1001]; int idx = 0; for (int i = 1; i <= n; ++i) { if (i != a && i != b && i != c && i != d) { arr[idx] = i; idx++; } } printf("%d %d ", a, d); for (int i = 0; i < idx; ++i) { printf("%d ", arr[i]); } printf("%d %d\n", c, b); printf("%d %d ", c, b); for (int i = idx - 1; i >= 0; --i) { printf("%d ", arr[i]); } printf("%d %d\n", a, d); } return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) return (gcd(b, a)); if (b == 0) return a; return gcd(b, a % b); } map<int, vector<int>> M; vector<int> ds(1003, 0); vector<int> dt(1003, 0); void BFSs(int root) { queue<int> q; q.push(root); map<int, int> m1; m1[root] = 1; ds[root] = 0; int c = 0; while (!q.empty()) { int x = q.front(); q.pop(); c++; for (int c : M[x]) { if (m1.count(c) == 0) { q.push(c); m1[c] = 1; ds[c] = ds[x] + 1; } } } } void BFSt(int root) { queue<int> q; q.push(root); map<int, int> m1; m1[root] = 1; dt[root] = 0; int c = 0; while (!q.empty()) { int x = q.front(); q.pop(); c++; for (int c : M[x]) { if (m1.count(c) == 0) { q.push(c); m1[c] = 1; dt[c] = dt[x] + 1; } } } } int main() { int n, k, a, b, c, d, C = 0, i; cin >> n >> k >> a >> b >> c >> d; vector<int> v; if (n == 4) { cout << -1; return (0); } for (i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { v.push_back(i); C++; } } if (k >= (n + 1)) { cout << a << " " << c << " "; for (i = 0; i < C; i++) cout << v[i] << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (i = 0; i < C; i++) cout << v[i] << " "; cout << b << " " << d << endl; } else cout << -1; }
#include <bits/stdc++.h> using namespace std; const int inf = 1000000001; const int MOD = 1000000007; void fail() { cout << "-1" << endl; exit(0); } const int N = 1005; bool z[N + 1][N + 1]; int gete(vector<int> a1, vector<int> a2, int n) { for (int i = (0); i <= (n + 1); ++i) for (int j = (0); j <= (n + 1); ++j) z[i][j] = false; for (int i = (0); i <= ((int)((a1).size()) - 2); ++i) z[a1[i]][a1[i + 1]] = z[a1[i + 1]][a1[i]] = true; for (int i = (0); i <= ((int)((a1).size()) - 2); ++i) z[a2[i]][a2[i + 1]] = z[a2[i + 1]][a2[i]] = true; int e = 0; for (int i = (1); i <= (n); ++i) for (int j = (i + 1); j <= (n); ++j) e += z[i][j]; return e; } void pr(vector<int>& a) { for (int i = (0); i <= ((int)((a).size()) - 1); ++i) cout << a[i] << " "; cout << endl; } int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (n <= 5) { vector<int> a1; for (int i = (1); i <= (n); ++i) a1.push_back(i); do { vector<int> a2; for (int i = (1); i <= (n); ++i) a2.push_back(i); do { bool ok = true; if (a1[0] != a || a1.back() != b) ok = false; if (a2[0] != c || a2.back() != d) ok = false; memset(z, false, sizeof(z)); for (int i = (0); i <= ((int)((a1).size()) - 2); ++i) z[a1[i]][a1[i + 1]] = z[a1[i + 1]][a1[i]] = true; for (int i = (0); i <= ((int)((a1).size()) - 2); ++i) z[a2[i]][a2[i + 1]] = z[a2[i + 1]][a2[i]] = true; if (z[a][b] || z[c][d]) ok = false; int e = 0; for (int i = (1); i <= (n); ++i) for (int j = (i + 1); j <= (n); ++j) e += z[i][j]; if (ok && e <= k) { pr(a1); pr(a2); return 0; } } while (next_permutation(a2.begin(), a2.end())); } while (next_permutation(a1.begin(), a1.end())); fail(); } bool rev1 = false, rev2 = false, swp = false; if (a > b) swap(a, b), rev1 = true; if (c > d) swap(c, d), rev2 = true; if (a > c) swap(a, c), swap(b, d), swp = true; vector<int> p1; p1.push_back(a); if (c != a) p1.push_back(c); for (int i = (1); i <= (n); ++i) if (i != a && i != b && i != c && i != d) p1.push_back(i); if (b != d) p1.push_back(d); p1.push_back(b); vector<int> p2; p2.push_back(c); if (c != a) { p2.push_back(a); } else p2.push_back(p1[1]); for (int i = (2); i <= ((int)((p1).size()) - 3); ++i) p2.push_back(p1[i]); if (b != d) p2.push_back(b); else p2.push_back(p1[(int)((p1).size()) - 2]); p2.push_back(d); if (swp) swap(p1, p2); if (rev1) reverse(p1.begin(), p1.end()); if (rev2) reverse(p2.begin(), p2.end()); if (gete(p1, p2, n) > k) fail(); pr(p1); pr(p2); }
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int main() { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (k <= n || n <= 4) { cout << "-1\n"; return 0; } map<int, int> m1; for (int x = 0; x < 2; x++) { cout << a << " " << c; m1[a]++, m1[c]++, m1[b]++, m1[d]++; for (int i = 1; i <= n; i++) { if (!m1[i]) cout << " " << i; } cout << " " << d << " " << b << "\n"; swap(a, c); swap(b, d); m1.clear(); } return 0; }
#include <bits/stdc++.h> const int SZ = 1e3 + 5; using namespace std; int n, m, a, b, c, d, sz = 2; int r1[SZ], r2[SZ]; bool vis[SZ]; int main() { scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &d); vis[a] = vis[b] = vis[c] = vis[d] = 1; for (int i = 1; i <= n; i++) if (!vis[i]) r1[sz] = i, r2[sz] = i, sz++; if (n == 4 || m <= n) { cout << -1; return 0; } r1[0] = r2[1] = a, r1[1] = r2[0] = c; r1[n - 1] = r2[n - 2] = b, r1[n - 2] = r2[n - 1] = d; for (int i = 0; i < n; i++) cout << r1[i] << ' '; cout << '\n'; for (int i = 0; i < n; i++) cout << r2[i] << ' '; cout << '\n'; }
#include <bits/stdc++.h> using namespace std; template <class T> bool sin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool sax(T &a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; ; int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n or n <= 4) return cout << -1, 0; vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = i + 1; auto it = find(ans.begin(), ans.end(), a); int ind = it - ans.begin(); swap(ans[0], ans[ind]); it = find(ans.begin(), ans.end(), b); ind = it - ans.begin(); swap(ans[n - 2], ans[ind]); it = find(ans.begin(), ans.end(), c); ind = it - ans.begin(); swap(ans[1], ans[ind]); it = find(ans.begin(), ans.end(), d); ind = it - ans.begin(); swap(ans[n - 1], ans[ind]); for (int i = 0; i < n; i++) { if (i == n - 2) { cout << ans[n - 1] << " " << ans[n - 2] << "\n"; break; } cout << ans[i] << " "; } swap(ans[0], ans[1]); for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int arr[1005], seq[1005]; int main() { int n, k, a, b, c, d, j, i; scanf("%d", &n); scanf("%d", &k); scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); seq[1] = a; seq[2] = c; seq[n] = b; seq[n - 1] = d; arr[a] = arr[b] = arr[c] = arr[d] = 1; j = 3; for (i = 1; i <= n; i++) { if (!arr[i]) { seq[j] = i; j++; } } if (k < n + 1 || n <= 4) cout << -1 << endl; else { for (i = 1; i <= n; i++) cout << seq[i] << " "; cout << endl; swap(seq[1], seq[2]); swap(seq[n - 1], seq[n]); for (i = 1; i <= n; i++) cout << seq[i] << " "; cout << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; int n, k, a, b, c, d, ans[1111]; int main() { while (~scanf("%d%d", &n, &k)) { scanf("%d%d%d%d", &a, &b, &c, &d); if (n < 5 || k < n + 1) printf("-1\n"); else { ans[1] = a, ans[2] = c, ans[n - 1] = d, ans[n] = b; for (int i = 3, j = 1; i <= n - 2; i++) { while (j == a || j == b || j == c || j == d) j++; ans[i] = j++; } for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' '); printf("%d %d %d ", ans[2], ans[1], ans[3]); for (int i = 4; i <= n - 2; i++) printf("%d ", ans[i]); printf("%d %d\n", ans[n], ans[n - 1]); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d, i; vector<int> v; scanf("%d %d %d %d %d %d", &n, &k, &a, &b, &c, &d); if (n < 5 || k <= n) puts("-1"); else { printf("%d %d ", a, c); for (i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) printf("%d ", i); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) printf("%d ", i); printf("%d %d\n", b, d); } return 0; }
#include <bits/stdc++.h> using namespace std; int edg[1001][1001] = {0}; int vstd[1001] = {0}; vector<int> ans; void dfs(int u) { vstd[u] = 1; ans.push_back(u); int ind = 0; for (int i = 1; i <= 1000 && ind == 0; i++) { if (edg[u][i] && !vstd[i]) { ind = 1; dfs(i); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || n + 1 > m) { cout << -1 << endl; return 0; } edg[a][c] = 1; edg[c][a] = 1; int midVtx; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { midVtx = i; break; } } edg[c][midVtx] = 1; edg[midVtx][c] = 1; edg[d][midVtx] = 1; edg[midVtx][d] = 1; int u = d; for (int i = 1; i <= n; i++) { if (i != a && i != c && i != midVtx && i != d && i != b) { edg[u][i] = 1; edg[i][u] = 1; u = i; } } edg[u][b] = 1; edg[b][u] = 1; dfs(a); for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl; edg[c][midVtx] = 0; edg[midVtx][c] = 0; edg[d][midVtx] = 0; edg[midVtx][d] = 0; edg[a][midVtx] = 1; edg[midVtx][a] = 1; edg[b][midVtx] = 1; edg[midVtx][b] = 1; for (int i = 0; i <= n; i++) { vstd[i] = 0; } ans.clear(); dfs(c); for (int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, a, b, c, d, i; cin >> n >> k >> a >> b >> c >> d; if (n == 4 || k < n + 1) { cout << -1; return 0; } cout << a << " " << c << " "; for (i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { cout << i << " "; } } cout << d << " " << b << endl; cout << c << " " << a << " "; for (i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { cout << i << " "; } } cout << b << " " << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 5100; int n, k, a, b, c, d; vector<int> e; int main() { scanf("%d%d%d%d%d%d", &n, &k, &a, &b, &c, &d); if (k <= n || n == 4) return printf("-1\n"), 0; for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) e.push_back(i); printf("%d %d ", a, c); for (vector<int>::iterator it = e.begin(); it != e.end(); it++) printf("%d ", *it); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (vector<int>::iterator it = e.begin(); it != e.end(); it++) printf("%d ", *it); printf("%d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int f[1010]; template <class T> void read(T &first) { char ch; for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-';) ch = getchar(); first = 0; int t = 1; if (ch == '-') { ch = getchar(); t = -1; } for (; ch >= '0' && ch <= '9'; ch = getchar()) first = first * 10 + ch - '0'; first *= t; } int main() { int n, m; read(n); read(m); int a, b, c, d; read(a); read(b); read(c); read(d); if (n == 4) { puts("-1"); return 0; } if (m < n + 1) { puts("-1"); return 0; } f[1] = a; f[2] = c; f[n - 1] = d; f[n] = b; int k = 1; for (int i = 3; i <= n - 2; i++) { while (k == a || k == b || k == c || k == d) k++; f[i] = k; k++; } for (int i = 1; i < n; i++) printf("%d ", f[i]); printf("%d\n", f[n]); printf("%d %d ", f[2], f[1]); for (int i = 3; i <= n - 2; i++) printf("%d ", f[i]); printf("%d %d\n", f[n], f[n - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; long long a[500005], b[500005], g, m = 1e7, siz, n, r; int main() { ios_base::sync_with_stdio(0); long long k = 0, t = 0, x, sum = 0, q = 0, z = 0, y = 0, i, j, l, x1, y1, x2, y2; cin >> n >> m; cin >> x >> y >> j >> k; if (m < n + 1 || n == 4) { cout << "-1"; return 0; } for (i = 1; i <= n; i++) { if (i != x && i != y && i != j && i != k) { z = i; break; } } a[0] = x; a[1] = j; a[2] = z; a[3] = y; a[4] = k; for (i = 0; i < 5; i++) { t = a[i]; b[t] = 1; } for (i = 0; i < n; i++) { if (a[i] == 0) { for (j = 1; j <= n; j++) if (b[j] == 0) { b[j] = 1; a[i] = j; break; } } } cout << a[0]; cout << " "; cout << a[1]; cout << " "; cout << a[2]; cout << " "; for (i = n - 1; i >= 3; i--) cout << a[i] << " "; cout << endl; cout << a[1]; cout << " "; cout << a[0]; cout << " "; for (i = 5; i < n; i++) cout << a[i] << " "; cout << a[2] << " "; cout << a[3] << " "; cout << a[4]; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, a, b, c, d; int main() { scanf("%d%d", &n, &m); scanf("%d%d%d%d", &a, &b, &c, &d); if ((n <= 4) || (m <= n)) { printf("%d\n", -1); return 0; } printf("%d %d", a, c); for (int i = 1; i <= n; i++) if ((i != a) && (i != b) && (i != c) && (i != d)) printf(" %d", i); printf(" %d %d\n", d, b); printf("%d %d", c, a); for (int i = 1; i <= n; i++) if ((i != a) && (i != b) && (i != c) && (i != d)) printf(" %d", i); printf(" %d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d, i, i2, count; scanf("%d %d", &n, &k); scanf("%d %d %d %d", &a, &b, &c, &d); if (n == 4 || k < 6 + n - 5) { printf("-1"); return 0; } printf("%d %d ", a, c); for (i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) printf("%d ", i); } printf("%d %d\n", d, b); printf("%d %d ", c, a); for (i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) printf("%d ", i); } printf("%d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 5; long long n, k, a, b, c, d, notuseda, notusedb; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k >> a >> b >> c >> d; if (k == n - 1 || k == n || n == 4) { cout << -1; } else if (n == 5) { for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) notuseda = i; cout << a << " " << c << " " << notuseda << " " << d << " " << b << "\n"; cout << c << " " << a << " " << notuseda << " " << b << " " << d << "\n"; } else { for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { if (notuseda == 0) notuseda = i; else notusedb = i; } } cout << a << " " << c << " " << notuseda << " "; for (int i = notuseda + 1; i <= n; i++) { if (i != a && i != b && i != c && i != d && i != notusedb) { cout << i << " "; } } cout << notusedb << " " << d << " " << b << "\n"; cout << c << " " << a << " " << notuseda << " "; for (int i = notuseda + 1; i <= n; i++) { if (i != a && i != b && i != c && i != d && i != notusedb) { cout << i << " "; } } cout << notusedb << " " << b << " " << d << "\n"; } }
#include <bits/stdc++.h> using namespace std; const int N = 1005; int v[N]; int main() { int n, k; int a, b, c, d; scanf("%d%d", &n, &k); scanf("%d%d%d%d", &a, &b, &c, &d); if (k < n + 1) return 0 * puts("-1"); v[1] = a; v[2] = c; v[n - 1] = d; v[n] = b; int t = 2; for (int i = (1); i < (n + 1); ++i) { if (i == a || i == b || i == c || i == d) continue; v[++t] = i; } if (v[3] == b || v[n - 2] == c) return 0 * puts("-1"); for (int i = (1); i < (n + 1); ++i) printf("%d%c", v[i], i == n ? '\n' : ' '); printf("%d %d ", c, a); for (int i = (3); i < (n - 1); ++i) printf("%d ", v[i]); printf("%d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) cout << -1; else { cout << a << ' ' << c << ' '; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) cout << i << ' '; } cout << d << ' ' << b << '\n'; cout << c << ' ' << a << ' '; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) cout << i << ' '; } cout << b << ' ' << d << '\n'; } }
#include <bits/stdc++.h> const int mmax = 1e6 + 10; using namespace std; int main() { long long n, s, a, b, c, d; while (cin >> n >> s) { cin >> a >> b >> c >> d; if (n > s - 1 || n == 4) cout << "-1" << endl; else { cout << a << " " << c << " "; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) cout << i << " "; } cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) cout << i << " "; } cout << b << " " << d << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) { cout << "-1"; return 0; } int z = 1; for (; z <= n; z++) { if (z != a && z != b && z != c && z != d) break; } cout << a << " "; for (int i = 1; i <= n; i++) { if (i != a && i != d && i != c && i != b && i != z) cout << i << " "; } cout << c << " "; cout << z << " "; cout << d << " "; cout << b << endl; cout << c << " "; for (int i = n; i > 0; i--) { if (i != a && i != d && i != c && i != b && i != z) cout << i << " "; } cout << a << " "; cout << z << " "; cout << b << " "; cout << d; return 0; }
#include <bits/stdc++.h> using namespace std; long long mod_v(long long num) { if (num >= 0) return (num % 1000000007); else return (num % 1000000007 + 1000000007) % 1000000007; } long long bigmod(long long b, long long p, long long m) { long long res = 1 % m, x = b % m; while (p) { if (p & 1) res = (res * x) % m; x = (x * x) % m; p >>= 1; } return res; } int main() { int n, k, a, b, c, d; scanf("%d %d", &n, &k); scanf("%d %d %d %d", &a, &b, &c, &d); if (n == 4) { printf("-1\n"); return 0; } if (k <= n) { printf("-1\n"); return 0; } printf("%d %d", a, c); for (int i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d) continue; printf(" %d", i); } printf(" %d %d\n", d, b); printf("%d %d", c, a); for (int i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d) continue; printf(" %d", i); } printf(" %d %d\n", b, d); return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167177216") using namespace std; const int MAXN = 2 * 1000 * 1000 + 500; const double EPS = 1e-9; int main(int argc, char* argv[]) { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; vector<int> ans(n, -1); ans[0] = a; ans[n - 1] = b; set<int> used; used.insert(a); used.insert(b); if (k <= n || n == 4) { cout << -1; return 0; } ans[0] = a; ans[n - 1] = b; ans[1] = c; ans[n - 2] = d; used.insert(a); used.insert(b); used.insert(c); used.insert(d); int curst = 1; for (int i = 0; i < n; i++) { if (ans[i] == -1) { while (used.count(curst)) curst++; ans[i] = curst; used.insert(curst); } } for (int i = 0; i < n; i++) cout << ans[i] << ' '; cout << endl; cout << ans[1] << ' ' << ans[0] << ' '; for (int i = 2; i < n - 2; i++) cout << ans[i] << ' '; cout << ans[n - 1] << ' ' << ans[n - 2]; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, a, b, c, d; int main() { scanf("%d %d %d %d %d %d", &n, &m, &a, &b, &c, &d); if (m <= n || n <= 4) { printf("-1"); return 0; } for (int i = 0; i < 2; i++) { printf("%d %d ", a, c); for (int j = 1; j <= n; j++) { if (j != a && j != b && j != c && j != d) printf("%d ", j); } printf("%d %d\n", d, b); swap(a, c); swap(b, d); } }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1e9 + 7; const int maxn = 1010; int n, k; int a, b, c, d; int path[maxn]; int main() { cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { puts("-1"); } else { int x = 1; for (int i = 1; i <= n; i++) { if (i != a && i != b && i != c && i != d) { x = i; break; } } cout << a << " " << c << " " << x << " " << d << " "; int p = 0; for (int i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d || i == x) { continue; } cout << i << " "; path[++p] = i; if (p == n - 5) break; } cout << b << endl; cout << c << " " << a << " " << x << " " << b << " "; for (int i = p; i >= 1; i--) cout << path[i] << " "; cout << d << endl; } }
#include <bits/stdc++.h> long long int mod = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i, n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (n == 4 || k < n + 1) { cout << "-1"; exit(0); } vector<int> pt; set<int> s; set<int>::iterator it; for (i = 1; i <= n; i++) s.insert(i); s.erase(a); s.erase(b); s.erase(c); s.erase(d); cout << a << " " << c << " "; pt.push_back(a); pt.push_back(c); it = s.begin(); cout << (*it) << " "; pt.push_back(*it); s.erase(*it); cout << d << " "; pt.push_back(d); for (it = s.begin(); it != s.end(); ++it) { cout << (*it) << " "; pt.push_back(*it); } cout << b << "\n"; pt.push_back(b); cout << c << " " << a << " "; cout << pt[2] << " "; for (i = pt.size() - 1; i >= 3; i--) cout << pt[i] << " "; }
#include <bits/stdc++.h> static void print_path(const std::vector<int>& path) { for (int node : path) printf("%d ", node); printf("\n"); } int main() { int cities, max_roads; int A, B, C, D; std::cin >> cities >> max_roads; std::cin >> A >> B >> C >> D; std::set<int> unused; for (int i = 1; i <= cities; i++) unused.insert(i); unused.erase(A); unused.erase(B); unused.erase(C); unused.erase(D); std::vector<int> first_path; std::vector<int> second_path; first_path.push_back(A); first_path.push_back(C); second_path.push_back(C); second_path.push_back(A); int edges_used = 1; for (int i = 0; i < cities - 4; i++) { if (edges_used > max_roads) { std::cout << "-1\n"; return 0; } const int city = *unused.begin(); unused.erase(city); first_path.push_back(city); second_path.push_back(city); if (i == 0) { edges_used += 2; } else { edges_used += 1; } } first_path.push_back(D); first_path.push_back(B); second_path.push_back(B); second_path.push_back(D); edges_used += 3; if (edges_used > max_roads) { std::cout << "-1\n"; return 0; } for (int i = 0; i + 1 < cities; i++) { if (first_path[i] == C && first_path[i + 1] == D) { std::cout << "-1\n"; return 0; } if (second_path[i] == A && second_path[i + 1] == B) { std::cout << "-1\n"; return 0; } } print_path(first_path); print_path(second_path); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n, k; scanf("%d%d", &n, &k); if (n <= 4 || k < n + 1) { puts("-1"); return 0; } int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); vector<int> v; for (int i = 0, u = 1; i < n - 4; i++) { while (u == a || u == b || u == c || u == d) u++; v.push_back(u++); } printf("%d %d ", a, c); for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); printf("%d %d\n%d %d ", d, b, c, a); for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); printf("%d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, a, b, c, d; void prepro() {} int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(17); cin >> n >> k >> a >> b >> c >> d; if (n == 4 || k < n + 1) { cout << -1; } else { vector<int> path; for (auto i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) path.push_back(i); cout << a << " " << c << " "; for (auto itr : path) cout << itr << " "; cout << d << " " << b << " \n"; cout << c << " " << a << " "; for (auto itr : path) cout << itr << " "; cout << b << " " << d << " \n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[4 + 2]; cin >> n >> m; cin >> a[0] >> a[1] >> a[2] >> a[3]; if (n >= m) { cout << -1; return 0; } if (m > ((n * (n - 1)) / 2) - 2) { cout << -1; return 0; } cout << a[0] << " " << a[2] << " "; for (int i = 1; i <= n; i++) { bool t = 1; for (int j = 0; j < 4; j++) { if (a[j] == i) t = 0; } if (t) cout << i << " "; } cout << a[3] << " " << a[1] << endl; cout << a[2] << " " << a[0] << " "; for (int i = 1; i <= n; i++) { bool t = 1; for (int j = 0; j < 4; j++) { if (a[j] == i) t = 0; } if (t) cout << i << " "; } cout << a[1] << " " << a[3]; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 3e5 + 10; const int INF = 1000000000; const int inf = 1e9 + 1; const double eps = 1e-9; int cnt[5005]; int a[5005]; int ans[5005]; bool used[1005]; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; a--; b--; c--; d--; used[a] = used[b] = used[c] = used[d] = true; vector<int> f; for (int(i) = (0); (i) < (n); ++(i)) { if (!used[i]) { f.push_back(i); } } if (n == 4) { cout << -1 << endl; return 0; } int need = n - 5 + 6; if (k < need) { cout << -1 << endl; return 0; } cout << a + 1 << " " << c + 1 << " "; for (auto e : f) cout << e + 1 << " "; cout << d + 1 << " " << b + 1 << endl; cout << c + 1 << " " << a + 1 << " "; for (auto e : f) cout << e + 1 << " "; cout << b + 1 << " " << d + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n || n <= 4) return cout << -1, 0; for (int i = 0; i < 2; i++) { cout << a << " " << c << " "; for (int j = 1; j <= n; j++) { if (j != a && j != b && j != c && j != d) { cout << j << " "; } } cout << d << " " << b << endl; swap(a, c); swap(b, d); } }
#include <bits/stdc++.h> using namespace std; const int N = 2e6; int n, k, a, b, c, d; int main() { ios_base::sync_with_stdio(0); cin >> n >> k >> a >> b >> c >> d; set<int> s; for (int i = 1; i <= n; ++i) { if (i != a && i != b && i != c && i != d) { s.insert(i); } } if (k < n + 1 || n == 4) { cout << -1; return 0; } cout << a << ' ' << c << ' '; for (auto x : s) { cout << x << ' '; } cout << d << ' ' << b << '\n'; cout << c << ' ' << a << ' '; for (auto x : s) { cout << x << ' '; } cout << b << ' ' << d << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; if (k <= n or n <= 4) { cout << -1 << '\n'; return 0; } int a, b, c, d; cin >> a >> b >> c >> d; set<int> nabcd; for (int i = 1; i <= n; i++) { if (i != a and i != b and i != c and i != d) { nabcd.emplace(i); } } cout << a << " " << c << " "; for (int x : nabcd) { cout << x << " "; } cout << d << " " << b << '\n'; cout << c << " " << a << " "; for (int x : nabcd) { cout << x << " "; } cout << b << " " << d << '\n'; }
#include <bits/stdc++.h> using namespace std; int fg[2], n, k, a, b, c, d, per[2][1002], pm[1002]; bool mat[1002][1002]; void brute_force() { int i, j, s, p, q, nk; for (i = 1; i <= n; i++) per[0][i] = per[1][i] = i; for (i = 1; i <= n; i++) { if (per[0][i] == a) swap(per[0][i], per[0][1]); if (per[0][i] == b) swap(per[0][i], per[0][n]); if (per[1][i] == c) swap(per[1][i], per[1][1]); if (per[1][i] == d) swap(per[1][i], per[1][n]); } int it1, it2; for (it1 = 0; it1 < 6; it1++) { for (i = 1; i <= n; i++) pm[i] = per[1][i]; for (it2 = 0; it2 < 6; it2++) { nk = k - (n - 1); for (i = 1; i < n; i++) { if ((per[0][i] == c && per[0][i + 1] == d) || (per[0][i + 1] == c && per[0][i] == d)) break; if ((pm[i] == a && pm[i + 1] == b) || (pm[i + 1] == a && pm[i] == b)) break; } if (i < n) goto orz; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) mat[i][j] = false; for (i = 1; i < n; i++) mat[per[0][i + 1]][per[0][i]] = mat[per[0][i]][per[0][i + 1]] = true; for (i = 1; i < n; i++) { if (!mat[pm[i]][pm[i + 1]]) nk--; } if (nk >= 0) { if (fg[0] == 0) { for (i = 1; i <= n; i++) printf("%d ", per[0][i]); } else { for (i = n; i >= 1; i--) printf("%d ", per[0][i]); } printf("\n"); if (fg[1] == 0) { for (i = 1; i <= n; i++) printf("%d ", pm[i]); } else { for (i = n; i >= 1; i--) printf("%d ", pm[i]); } printf("\n"); return; } orz: next_permutation(pm + 2, pm + n); } next_permutation(per[0] + 2, per[0] + n); } puts("-1"); } int main() { int i, j, s, p, q; scanf("%d%d%d%d%d%d", &n, &k, &a, &b, &c, &d); if (a == b || c == d) { puts("-1"); return 0; } if (a > b) { fg[0] = 1; swap(a, b); } if (c > d) { fg[1] = 1; swap(c, d); } if (n <= 5) { brute_force(); return 0; } for (i = 1; i <= n; i++) per[0][i] = i; for (i = 1; i <= n; i++) { if (per[0][i] == a) swap(per[0][i], per[0][1]); if (per[0][i] == b) swap(per[0][i], per[0][n]); } for (i = 1; i <= n; i++) per[1][i] = per[0][i]; for (i = 1; i <= n; i++) { if (per[1][i] == c) { for (j = i; j > 1; j--) swap(per[1][j], per[1][j - 1]); } if (per[0][i] == c) { for (j = i; j > 2; j--) swap(per[0][j], per[0][j - 1]); } } for (i = 1; i <= n; i++) { if (per[1][i] == d) { for (j = i; j < n; j++) swap(per[1][j], per[1][j + 1]); } if (per[0][i] == d) { for (j = i; j < n - 1; j++) swap(per[0][j], per[0][j + 1]); } } k -= n - 1; memset(mat, false, sizeof(mat)); for (i = 1; i < n; i++) mat[per[0][i]][per[0][i + 1]] = mat[per[0][i + 1]][per[0][i]] = true; for (i = 1; i < n; i++) { if (!mat[per[1][i]][per[1][i + 1]]) k--; } if (k >= 0) { if (fg[0] == 0) { for (i = 1; i <= n; i++) printf("%d ", per[0][i]); } else { for (i = n; i >= 1; i--) printf("%d ", per[0][i]); } printf("\n"); if (fg[1] == 0) { for (i = 1; i <= n; i++) printf("%d ", per[1][i]); } else { for (i = n; i >= 1; i--) printf("%d ", per[1][i]); } printf("\n"); } else puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long double EPS = 1e-8; const long double PI = acos(-1.0L); const int MAXN = 1100; int p[MAXN]; int main() { int n, k; int a, b, c, d; scanf("%d%d", &n, &k); scanf("%d%d%d%d", &a, &b, &c, &d); if (n == 4 || k < n + 1) { cout << -1 << '\n'; return 0; } set<int> s; for (int i = 1; i <= n; ++i) s.insert(i); p[1] = a; p[2] = c; p[n - 1] = d; p[n] = b; s.erase(a); s.erase(b); s.erase(c); s.erase(d); int j = 3; for (auto x : s) { p[j++] = x; } for (int i = 1; i <= n; ++i) printf("%d ", p[i]); printf("\n"); swap(p[1], p[2]); swap(p[n - 1], p[n]); for (int i = 1; i <= n; ++i) printf("%d ", p[i]); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, a, b, c, d, k, arr[1050]; void solve() { if (n <= 4 || k < n + 1) { printf("-1\n"); return; } int m = 0; for (int i = 1; i <= n; i++) if (i ^ a && i ^ b && i ^ c && i ^ d) arr[m++] = i; printf("%d %d", a, c); for (int i = 0; i < m; i++) printf(" %d", arr[i]); printf(" %d %d\n", d, b); printf("%d %d", c, a); for (int i = 0; i < m; i++) printf(" %d", arr[i]); printf(" %d %d\n", b, d); } int main() { while (scanf("%d%d", &n, &k) == 2) { scanf("%d%d%d%d", &a, &b, &c, &d); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; if (n == 4) { cout << "-1\n"; return 0; } int a, b, c, d; cin >> a >> b >> c >> d; if (k <= n) { cout << "-1\n"; return 0; } bool check[n + 1]; for (int i = 0; i <= n; i++) { check[i] = 0; } check[a] = 1; check[b] = 1; check[c] = 1; check[d] = 1; int k1; vector<int> k2; for (int i = 1; i <= n; i++) { if (!check[i]) { k1 = i; check[i] = 1; break; } } for (int i = 1; i <= n; i++) { if (!check[i]) { k2.push_back(i); check[i] = 1; } } cout << a << " " << c << " " << k1 << " " << d << " "; for (int i = 0; i < k2.size(); i++) { cout << k2[i] << " "; } cout << b << "\n"; cout << c << " " << a << " " << k1 << " " << b << " "; for (int i = 0; i < k2.size(); i++) { cout << k2[k2.size() - i - 1] << " "; } cout << d << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void show(vector<T> a, int p = 0) { for (int i = 0; i < a.size(); i++) { if (p == 0) cout << a[i] << endl; if (p == 1 || p == 2) cout << a[i] << ' '; } if (p == 2) cout << endl; } int main() { int n, m, a, b, c, d; cin >> n >> m; vector<int> vec(n); vector<int> used(n + 1); cin >> a >> b >> c >> d; if (n == 4 || n + 1 > m) { cout << -1; return 0; } used[a] = 1; used[b] = 1; used[c] = 1; used[d] = 1; vec[0] = a; vec[1] = c; vec[n - 2] = d; vec[n - 1] = b; vector<int> tmp; for (int i = 1; i < n + 1; i++) { if (!used[i]) tmp.push_back(i); } int k = 0; for (int i = 2; i < n - 2; i++) { vec[i] = tmp[k++]; } show(vec, 2); cout << vec[1] << ' ' << vec[0] << ' '; for (int i = 2; i < n - 2; i++) cout << vec[i] << ' '; cout << vec[n - 1] << ' ' << vec[n - 2]; return 0; }
#include <bits/stdc++.h> using namespace std; const int Inf = 1e9 + 7; const int N = 1007; int n, k; int used[N]; void solve() { cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << "-1" << '\n'; return; } bool ab = true, cd = true; if (a > b) { swap(a, b); ab = false; } if (c > d) { swap(c, d); cd = false; } vector<int> p; p.push_back(a); used[a] = 1; p.push_back(c); used[c] = 1; int x = 1; for (; x <= n; ++x) { if (used[x] == 0 && x != b && x != d) { p.push_back(x); used[x] = 1; break; } } p.push_back(d); used[d] = 1; vector<int> s; for (int y = 1; y <= n; ++y) { if (used[y] == 0 && y != b) { p.push_back(y); s.push_back(y); used[y] = 1; } } p.push_back(b); used[b] = 1; vector<int> q; q.push_back(c); q.push_back(a); q.push_back(x); q.push_back(b); reverse(s.begin(), s.end()); for (auto e : s) q.push_back(e); q.push_back(d); if (!ab) reverse(p.begin(), p.end()); if (!cd) reverse(q.begin(), q.end()); for (auto e : p) cout << e << " "; cout << '\n'; for (auto e : q) cout << e << " "; cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a[4], n, k; cin >> n >> k; if (k <= n || n <= 4) { cout << -1; return 0; } cin >> a[0] >> a[1] >> a[2] >> a[3]; cout << a[0] << " " << a[2] << " "; for (int i = 1; i <= n; i++) { if (i != a[0] && i != a[1] && i != a[2] && i != a[3]) { cout << i << " "; } } cout << a[3] << " " << a[1] << endl << a[2] << " " << a[0] << " "; for (int i = 1; i <= n; i++) { if (i != a[0] && i != a[1] && i != a[2] && i != a[3]) { cout << i << " "; } } cout << a[1] << " " << a[3]; }
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int n, m, a, b, c, d; scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &d); if (m < n - 1 + 2 || n == 4) { printf("-1\n"); return 0; } for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) v.push_back(i); printf("%d %d ", a, c); for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); printf("%d %d\n", b, d); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; c--; d--; int min = N + 1; if (N == 4) min = M + 1; if (M < min) { cout << -1 << endl; } else { vector<int> arr(N, 1); arr[a] = 0; arr[b] = 0; arr[c] = 0; arr[d] = 0; cout << a + 1 << ' ' << c + 1 << ' '; for (int n = (0); n < (N); ++n) if (arr[n]) cout << n + 1 << ' '; cout << d + 1 << ' ' << b + 1 << ' '; cout << endl; cout << c + 1 << ' ' << a + 1 << ' '; for (int n = (0); n < (N); ++n) if (arr[n]) cout << n + 1 << ' '; cout << b + 1 << ' ' << d + 1 << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a, b, c, d; cin >> n >> k >> a >> b >> c >> d; bool t1, t2; t1 = t2 = false; if (a > b) { swap(a, b); t1 = true; } if (c > d) { swap(c, d); t2 = true; } vector<int> res1, res2; if (a == c && b == d) { res1.push_back(a); for (int i = 1; i <= n; i++) if (i != a && i != b) res1.push_back(i); res1.push_back(b); res2 = res1; } else if (a == c) { if (n < 4) { cout << -1 << endl; return 0; } if (k < n) { cout << -1 << endl; return 0; } res1.push_back(a); for (int i = 1; i <= n; i++) if (i != a && i != b && i != d) res1.push_back(i); res2 = res1; res1.push_back(d); res1.push_back(b); res2.push_back(b); res2.push_back(d); } else if (b == d) { if (n < 4) { cout << -1 << endl; return 0; } if (k < n) { cout << -1 << endl; return 0; } swap(a, b); t1 ^= true; swap(c, d); t2 ^= true; res1.push_back(a); for (int i = 1; i <= n; i++) if (i != a && i != b && i != d) res1.push_back(i); res2 = res1; res1.push_back(d); res1.push_back(b); res2.push_back(b); res2.push_back(d); } else { if (n < 5) { cout << -1 << endl; return 0; } if (k <= n) { cout << -1 << endl; return 0; } res1.push_back(a); res1.push_back(c); res2.push_back(c); res2.push_back(a); for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) { res1.push_back(i); res2.push_back(i); } res1.push_back(d); res1.push_back(b); res2.push_back(b); res2.push_back(d); } if (t1) reverse(res1.begin(), res1.end()); if (t2) reverse(res2.begin(), res2.end()); for (int i = 0; i < n; i++) cout << res1[i] << ' '; cout << endl; for (int i = 0; i < n; i++) cout << res2[i] << ' '; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; int main() { int n, k, a, b, c, d, toPrint[1005], i, j; scanf("%d %d", &n, &k); scanf("%d %d %d %d", &a, &b, &c, &d); if (n == 4 || k <= n) { printf("-1\n"); return 0; } toPrint[0] = a; toPrint[1] = c; toPrint[n - 2] = d; toPrint[n - 1] = b; j = 2; for (i = 1; i <= n; i++) { if (i == a || i == b || i == c || i == d) continue; toPrint[j++] = i; } for (i = 0; i < n - 1; i++) printf("%d ", toPrint[i]); printf("%d\n", toPrint[i]); swap(toPrint[0], toPrint[1]); swap(toPrint[n - 2], toPrint[n - 1]); for (i = 0; i < n - 1; i++) printf("%d ", toPrint[i]); printf("%d\n", toPrint[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const int oo = 0x7fffffff; const int sup = 0x80000000; template <typename it> void db(it *begin, it *end) { while (begin != end) cout << (*begin++) << " "; puts(""); } template <typename it> string to_str(it n) { string s = ""; while (n) s += n % 10 + '0', n /= 10; reverse(s.begin(), s.end()); return s; } template <typename it> int o(it a) { cout << a << endl; return 0; } inline long long mul_64(long long x, long long y, long long c) { return (x * y - (long long)((long double)x / c * y) * c + c) % c; } long long ksm(long long a, long long b, long long c) { long long ans = 1; for (; b; b >>= 1, a = a * a % c) if (b & 1) ans = ans * a % c; return ans; } void exgcd(long long a, long long b, long long &x, long long &y) { if (!b) x = 1, y = 0; else exgcd(b, a % b, y, x), y -= (a / b) * x; } int n, k; int a, b, c, d; bool vis[N]; vector<int> g; int main() { cin >> n >> k; cin >> a >> b >> c >> d; vis[a] = vis[b] = vis[c] = vis[d] = 1; if (k <= n || n == 4) return o(-1); for (int i = 1; i <= n; i++) if (!vis[i]) g.push_back(i); cout << a << " " << c << " "; for (int v : g) cout << v << " "; cout << d << " " << b << endl; cout << c << " " << a << " "; for (int v : g) cout << v << " "; cout << b << " " << d << endl; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456") using namespace std; template <typename T> T sqr(const T &x) { return x * x; } template <typename T> T my_abs(const T &x) { return x < 0 ? -x : x; } const int INF = (int)1e9; const long long LINF = (long long)6e18; const long long INF64 = LINF; const long long INFLL = LINF; const long double EPS = 1e-8; const long double PI = 3.1415926535897932384626433832795; const long double ME = 1e-5; const long long MOD = (int)1e9 + 7; const long long MOD2 = (int)1e9 + 21; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; const int N = (int)5e3 + 10; inline void solve() { int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k < n + 1) { cout << -1 << endl; return; } vector<int> p; for (int i = 1; i < int(n + 1); ++i) { if (i != a && i != b && i != c && i != d) { p.push_back(i); } } cout << a << ' ' << c; for (int i = 0; i < int(int(p.size())); ++i) { cout << ' ' << p[i]; } cout << ' ' << d << ' ' << b << endl; cout << c << ' ' << a; for (int i = 0; i < int(int(p.size())); ++i) { cout << ' ' << p[i]; } cout << ' ' << b << ' ' << d << endl; } int main() { std::ios::sync_with_stdio(false); srand((unsigned int)time(NULL)); cout << setprecision(15) << fixed; solve(); cerr << clock() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; int n, k, a, b, c, d; int main() { cin >> n >> k; cin >> a >> b >> c >> d; if (k < n + 1 || n <= 4) { cout << -1 << endl; } else { printf("%d %d ", a, c); for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) { printf("%d ", i); } printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) { printf("%d ", i); } printf("%d %d\n", b, d); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1010; int N, K; bool vis[MAXN]; int ansf[MAXN], anss[MAXN]; int a, b, c, d; int main() { scanf("%d%d", &N, &K); scanf("%d%d%d%d", &a, &b, &c, &d); memset(vis, false, sizeof(vis)); if (N == 4 || (K < N + 1)) puts("-1"); else { memset(ansf, 0, sizeof(ansf)); int pos = -1; ansf[1] = a; vis[a] = vis[b] = vis[c] = vis[d] = true; ansf[2] = c; ansf[4] = d; ansf[N] = b; for (int i = 1; i <= N; i++) { if (!vis[i]) { pos = i; ansf[3] = i; break; } } vis[pos] = true; for (int i = 1; i <= N; i++) { if (ansf[i] != 0) continue; for (int j = 1; j <= N; j++) { if (vis[j] == false) { vis[j] = true; ansf[i] = j; break; } } } for (int i = 1; i <= N; i++) printf("%d ", ansf[i]); puts(""); memset(vis, false, sizeof(vis)); if (pos == -1) { puts("-1"); return 0; } anss[1] = c; anss[N] = d; anss[2] = a; anss[3] = pos; anss[4] = b; for (int i = 5, j = N - 1; i < N; i++, j--) { anss[i] = ansf[j]; } for (int i = 1; i <= N; i++) printf("%d ", anss[i]); puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k < n + 1) { cout << -1 << endl; return 0; } if (n == 4) { cout << -1 << endl; return 0; } vector<int> res; for (int i = 1; i <= n; ++i) { if (i != a && i != b && i != c && i != d) { res.push_back(i); } } cout << a << " " << c << " "; for (int i = 0; i < res.size(); ++i) { cout << res[i] << " "; } cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = 0; i < res.size(); ++i) { cout << res[i] << " "; } cout << b << " " << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& out, const pair<A, B>& a) { return out << "(" << a.first << ", " << a.second << ")"; } template <class A> ostream& operator<<(ostream& out, const vector<A>& a) { out << "["; for (auto it = a.begin(); it != a.end(); ++it) { if (it != a.begin()) out << ", "; out << *it; } return out << "]"; } mt19937 rnd(time(NULL)); mt19937_64 rnd64(time(NULL)); const int INF = 1e9; const long long INF64 = 1e18; const int MOD = 1e9 + 7; const long double PI = acosl(-1.0); const long double EPS = 1e-9; int n, k; int a, b, c, d; bool read() { if (scanf("%d %d", &n, &k) != 2) return false; scanf("%d %d %d %d", &a, &b, &c, &d); return true; } void print(int a, int b, int c, int d) { printf("%d %d ", a, c); for (int i = int(1); i < int(n + 1); ++i) { if (i == a || i == b || i == c || i == d) { continue; } printf("%d ", i); } printf("%d %d", d, b); puts(""); } void solve() { if (n == 4 || k < n + 1) { puts("-1"); return; } print(a, b, c, d); print(c, d, a, b); } int main() { cout << fixed << setprecision(10); cerr << fixed << setprecision(10); if (read()) { solve(); } }
#include <bits/stdc++.h> using namespace std; int path1[1010]; int path2[1010]; bool used[1010]; int main() { ios_base::sync_with_stdio(false); int n, k, a, b, c, d, i, j; cin >> n >> k; cin >> a >> b >> c >> d; if (n == 4 || (k < (n + 1))) { cout << -1 << endl; return 0; } for (i = 1; i <= n; i++) path1[i] = i; path1[1] = a; path1[2] = c; path1[n - 1] = d; path1[n] = b; used[a] = used[b] = used[c] = used[d] = 1; for (i = 3, j = 1; i <= n - 2; i++, j++) { while (used[j] == 1) j++; path1[i] = j; } for (i = 1; i <= n; i++) { path2[i] = path1[i]; } swap(path2[1], path2[2]); swap(path2[n - 1], path2[n]); for (i = 1; i <= n; i++) cout << path1[i] << " "; cout << endl; for (i = 1; i <= n; i++) cout << path2[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (n < 5 || n >= k) { return cout << "-1\n", 0; } vi restric(n + 1, 0); for (int x : {a, b, c, d}) { restric[x] = 1; } cout << a << " " << c; for (int i = 1; i <= n; i++) { if (!restric[i]) { cout << " " << i; } } cout << " " << d << " " << b; cout << '\n'; cout << c << " " << a; for (int i = 1; i <= n; i++) { if (!restric[i]) { cout << " " << i; } } cout << " " << b << " " << d; cout << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T sqr(const T& x) { return x * x; } template <class T> inline void updMin(T& a, const T& b) { if (b < a) a = b; } template <class T> inline void updMax(T& a, const T& b) { if (b > a) a = b; } const int maxn = 100000; int m[maxn]; int n, k, a, b, c, d; int main() { int n, k; scanf("%d %d", &n, &k); if (n == 4 || k <= n) { printf("%d\n", -1); return 0; } scanf("%d %d %d %d", &a, &b, &c, &d); a--, b--, c--, d--; m[0] = a; m[1] = c; int j = 0; for (int i = 2; i < n - 2; i++) { while (j == a || j == b || j == c || j == d) j++; m[i] = j; j++; } m[n - 2] = d; m[n - 1] = b; for (int i = 0; i < n; i++) { printf("%d ", m[i] + 1); } puts(""); printf("%d %d ", c + 1, a + 1); for (int i = 2; i < n - 2; i++) { printf("%d ", m[i] + 1); } printf("%d %d", b + 1, d + 1); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; int setBit(int n, int pos) { return n | (1 << pos); } int resetBit(int n, int pos) { return n & ~(1 << pos); } bool checkBit(int n, int pos) { return n & (1 << pos); } inline long long bigmod(long long p, long long e, long long M) { long long ret = 1; while (e > 0) { if (e % 2) ret = (ret * p) % M; p = (p * p) % M; e /= 2; } return ret; } inline long long power(long long x, long long y) { long long ans = 1; while (y > 0) { if (y % 2) ans *= x; x *= x; y /= 2; } return ans; } template <class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> T lcm(T a, T b) { return a * (b / gcd(a, b)); } int n, k, a, b, c, d; int vis[1003]; int main() { cin >> n >> k >> a >> b >> c >> d; if (k < n + 1 || n == 4) { cout << -1; return 0; } vis[a] = vis[b] = vis[c] = vis[d] = 1; printf("%d %d ", a, c); for (int i = 1; i <= n; i++) { if (vis[i] == 0) { printf("%d ", i); } } printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i = 1; i <= n; i++) { if (vis[i] == 0) { printf("%d ", i); } } printf("%d %d", b, d); }
#include <bits/stdc++.h> int main() { int x[1001], y[1001]; int n, m, i, j; int k, a, b, c, d; scanf("%d %d", &n, &k); scanf("%d %d %d %d", &a, &b, &c, &d); if (n == 4) printf("-1"); else { if (k < n + 1) printf("-1"); else { int t = 2; for (i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) x[t++] = i; x[0] = a; x[1] = c; x[n - 2] = d; x[n - 1] = b; for (i = 0; i < n; i++) printf("%d ", x[i]); printf("\n"); x[0] = c; x[1] = a; x[n - 2] = b; x[n - 1] = d; for (i = 0; i < n; i++) printf("%d ", x[i]); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n || n <= 4) { puts("-1"); return 0; } cout << a << " " << c << " "; for (int p = 1; p <= n; p++) { if (p != a && p != b && p != c && p != d) { cout << p << " "; } } cout << d << " " << b << endl; cout << c << " " << a << " "; for (int p = 1; p <= n; p++) { if (p != a && p != b && p != c && p != d) { cout << p << " "; } } cout << b << " " << d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; int v[1100]; vector<int> maps[1100]; int a, b, c, d; int bs; int nextn[1100], pre[1100]; int dfs(int x, int y) { bs++; v[x] = 1; cout << x << " "; if (x == a) { maps[x].push_back(c); maps[c].push_back(x); pre[c] = x; nextn[x] = c; dfs(c, y); return 0; } if (x == d && bs == n - 1) { maps[x].push_back(y); maps[y].push_back(x); pre[y] = x; nextn[x] = y; dfs(y, y); return 0; } if (x == y) { return 0; } int i = x; if ((x % n) + 1 == y && bs != n - 1) { i++; } if (bs == n - 2) { maps[x].push_back(d); maps[d].push_back(x); pre[d] = x; nextn[x] = d; dfs(d, y); return 0; } for (i = i % n + 1; v[i] || i == a || i == b || i == c || i == d; i = i % n + 1) continue; maps[x].push_back(i); maps[i].push_back(x); nextn[x] = i; pre[i] = x; dfs(i, y); v[x] = 0; return 0; } int lj[1100], pt = 0; int bj = 1; int bl(int x, int y) { lj[pt++] = x; bs++; v[x] = 1; if (bs == n && x == y) { bj = 0; for (int i = 0; i < n; i++) cout << lj[i] << " "; } for (int i = 0; i < maps[x].size() && bj; i++) { if (v[maps[x][i]]) continue; int point = maps[x][i]; bl(point, y); } pt--; bs--; v[x] = 0; return 0; } int main() { while (cin >> n >> m) { cin >> a >> b >> c >> d; if (m < n + 1 || n == 4) { cout << -1 << endl; continue; } else { for (int i = 1; i <= n; i++) maps[i].clear(); dfs(a, b); cout << endl; memset(v, 0, sizeof(v)); bs = 0; int u = nextn[c]; int v = pre[d]; maps[a].push_back(u); maps[u].push_back(a); maps[v].push_back(b); maps[b].push_back(v); bl(c, d); cout << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; bool Visited[1005]; int Path[1005]; int main() { int N, k, i, j, a, b, c, d; scanf("%d%d", &N, &k); scanf("%d%d%d%d", &a, &b, &c, &d); if (N == 4 || k < N + 1) { puts("-1"); return 0; } Path[1] = a; Path[2] = c; Path[4] = d; Path[N] = b; Visited[a] = Visited[b] = Visited[c] = Visited[d] = true; for (i = 1; i <= N; ++i) { if (Visited[i] == false) { Visited[i] = true; Path[3] = i; break; } } for (i = 5, j = 1; i < N; ++j) { if (Visited[j] == false) { Visited[j] = true; Path[i++] = j; } } for (i = 1; i <= N; ++i) printf("%d ", Path[i]); puts(""); printf("%d %d %d %d ", c, a, Path[3], b); for (i = N - 1; i > 3; --i) printf("%d ", Path[i]); puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1111; int n, k, a, b, c, d, pos; int vis[MAXN]; vector<int> e; int main() { scanf("%d%d", &n, &k); scanf("%d%d%d%d", &a, &b, &c, &d); if (n == 4 || k < n + 1) { printf("-1\n"); return 0; } vis[a] = 1; vis[b] = 1; vis[c] = 1; vis[d] = 1; int pos; for (int i = 1; i <= n; i++) if (!vis[i]) { vis[i] = 1; pos = i; break; } for (int i = 1; i <= n; i++) if (!vis[i]) e.push_back(i); printf("%d %d %d %d", a, c, pos, d); for (int i = 0; i < (int)e.size(); i++) printf(" %d", e[i]); printf(" %d\n", b); printf("%d %d %d %d", c, a, pos, b); for (int i = (int)e.size() - 1; i >= 0; i--) printf(" %d", e[i]); printf(" %d\n", d); return 0; }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (n + 1 > k || n == 4) cout << -1 << endl; else { cout << a << " " << c << " "; for (int i = (1); i < (n + 1); ++i) { if (i == a || i == b || i == c || i == d) continue; cout << i << " "; } cout << d << " " << b << endl; cout << c << " " << a << " "; for (int i = (1); i < (n + 1); ++i) { if (i == a || i == b || i == c || i == d) continue; cout << i << " "; } cout << b << " " << d << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { int n, k, a, b, c, d; while (cin >> n >> k >> a >> b >> c >> d) { if (n == 4 || k <= n) puts("-1"); else { cout << a << " " << c << " "; for (int i = 1; i <= n; i++) if (i == a || i == b || i == c || i == d) continue; else cout << i << " "; cout << d << " " << b << "\n"; cout << c << " " << a << " "; for (int i = 1; i <= n; i++) if (i == a || i == b || i == c || i == d) continue; else cout << i << " "; cout << b << " " << d << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1001; int main() { int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if (k <= n || n == 4) cout << -1; else { for (int i = 0; i < 2; i++) { cout << a << ' ' << c << ' '; for (int j = 1; j <= n; j++) if (j != a && j != b && j != c && j != d) cout << j << ' '; cout << d << ' ' << b; swap(a, c); swap(b, d); cout << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; int n, k, a, b, c, d; void solve() { if (n >= 5) { if (k >= n + 1) { vector<int> l; for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) { l.push_back(i); } printf("%d %d ", a, c); for (int i : l) printf("%d ", i); printf("%d %d\n", d, b); printf("%d %d ", c, a); for (int i : l) printf("%d ", i); printf("%d %d\n", b, d); } else printf("-1\n"); } else printf("-1\n"); } int main() { cin >> n >> k >> a >> b >> c >> d; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; bool sortinrev(const pair<int, int>& a, const pair<int, int>& b) { return (a.first > b.first); } long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int root(long long int* Arr, long long int i) { while (Arr[i] != i) { Arr[i] = Arr[Arr[i]]; i = Arr[i]; } return i; } void unin(long long int* Arr, long long int* size, long long int A, long long int B) { long long int root_A = root(Arr, A); long long int root_B = root(Arr, B); if (root_A == root_B) return; else if (size[root_A] < size[root_B]) { Arr[root_A] = Arr[root_B]; size[root_B] += size[root_A]; } else { Arr[root_B] = Arr[root_A]; size[root_A] += size[root_B]; } } long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; long long int a, b, c, d; cin >> a >> b >> c >> d; if (n == 4 || k <= n) { cout << "-1"; return 0; } cout << a << " " << c << " "; for (long long int i = 1; i < n + 1; i += 1) { if (i != a && i != b && i != c && i != d) cout << i << " "; } cout << d << " " << b << endl; cout << c << " " << a << " "; for (long long int i = 1; i < n + 1; i += 1) { if (i != a && i != b && i != c && i != d) cout << i << " "; } cout << b << " " << d << endl; return 0; }