output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; int n, x, y, h[100005], w[100005]; bool g, f[100005], c; vector<int> vt[100005]; void back(int p, int u, int r) { w[p] = u; f[u] = true; if (p == n - 1) c = true; ; for (int i = 0; i < 4; i++) if (!f[vt[u][i]]) { g = false; for (int j = 0; j < 4; j...
### Prompt Please formulate a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; vector<int> g[100001], ans; int n; bool used[100001]; void dfs(int v, int p, int d) { used[v] = true; ans.push_back(v); if (++d == n) { if (v == 1) { for (int i = 0; i < ans.size(); ++i) cout << ans[i] << " "; cout << endl; exit(0); } } els...
### Prompt Please provide a cpp coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; int sam(vector<int> a, vector<int> b) { int ret = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i] == b[j]) { ret++; } } } return ret; } vector<int> pat[100000]; vector<int> rin[100000]; int main() { int num; sc...
### Prompt Your challenge is to write a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; vector<int> L[100005], AD[100005], node; bool vis2[100005]; int n; void DFS2(int nodo) { if (vis2[nodo]) return; vis2[nodo] = 1; node.push_back(nodo); for (int i = 0; i < AD[nodo].size(); i++) DFS2(AD[nodo][i]); } map<pair<int, int>, int> edge; bool correct1(vector<...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; int A[200005], B[200005], N; int O[200005][5]; void ucitaj() { scanf("%d", &N); if (N == 5) { printf("1 5 3 4 2\n"); exit(0); } int i, j; for (i = 1; i <= 2 * N; i++) { scanf("%d%d", A + i, B + i); if (O[A[i]][1] == 0) O[A[i]][1] = B[i]; ...
### Prompt Please provide a Cpp coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; const int maxN = 3 * 1000 * 100 + 50; vector<int> v[maxN], path; set<pair<int, int> > p; queue<int> q; bool mark[maxN]; int d[maxN]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < 2 * n; i++) { int a, b; cin >> a >> b; p.i...
### Prompt Your challenge is to write a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; int i, j, k, x, y, z, n, m; int a[200001][10]; int adj[200001][10]; int ans[200001]; int dd[11]; bool t[11]; int be(int S, int x) { return ((x == a[S][1] || x == a[S][2] || x == a[S][3] || x == a[S][4]) ? 1 ...
### Prompt Please provide a cpp coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; struct grana { int p, k; inline bool operator<(const grana &x) const { return p < x.p; } }; grana g[400005]; int poc[100005]; int sol[100005]; bool isedge(int u, int v) { for (int i = poc[u]; i < poc[u + 1]; i++) if (g[i].k == v) return 1; return 0; } int main()...
### Prompt In Cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > adjlst; vector<int> res; int dir[] = {-2, -1, 1, 2}; set<int> vis; bool findRes(int adj, int i, int lim) { for (int d = 0; d < lim; d++) { int idx = (i + dir[d] + n) % n; if (res[idx] == adj) return 1; } return 0; } bool valid() { ...
### Prompt In cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; vector<int> g[100010]; int vis[100010]; int a[200010], b[200010], s[4]; int res[100010]; int n; int f(int s[4]) { memset(vis, 0, sizeof(vis)); res[0] = s[0]; res[1] = s[1]; res[2] = 1; res[3] = s[2]; res[4] = s[3]; for (int i = 2; i <= 4; i++) vis[res[i]] = 1;...
### Prompt Please formulate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const int INF = 0x7f7f7f7f; const int maxn = 111111; const int mod = 9901; template <class T> int countbit(T n) { int t = 0; while (n) n &= n - 1, ++t; return t; } template <class T> T lowbit(T n) { return n & (...
### Prompt Develop a solution in CPP to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, set<int> > m; for (int Q = 0; Q < 2 * n; ++Q) { int x, y; cin >> x >> y; m[x].insert(y); m[y].insert(x); } if (m.size() != n) { cout << -1; return 0; } for (int Q = 1; Q <= n; ++Q) { if (m[Q]...
### Prompt Your task is to create a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; int n, g[100100][5], d[100100], v[100100]; bool in[100100]; bool dfs(int a, int b, int k = 1) { v[k - 1] = a, v[k] = b; if (k < n) { in[b] = 1; for (int i = 0; i < 4; ++i) { int c = g[b][i]; if (in[c]) continue; if ((g[a][0] == c || g[a][1] == ...
### Prompt Generate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; int adj[100000][4]; int adjCounts[100000]; int N; bool was[100000]; int res[100000]; bool tryBuild() { for (int i = 3; i < N; i++) { int next = -1; for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) if (adj[res[i - 1]][j] == adj[res[i - 2]][k]...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; int n, kk, x, y, cnt[111111], to[111111][4], rr[111111]; bool w[111111]; bool go(int pp, int p, int k) { int xx, yy; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) { xx = to[pp][i], yy = to[p][j]; if (xx == yy && (!w[xx] || (k == n - 1 && xx == ...
### Prompt Create a solution in Cpp for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, bool> edge; map<pair<int, int>, bool>::iterator it; vector<vector<int> > graph; vector<int> ans; int vis[100004]; int id = 1; int main() { int n; int a, b; scanf("%d", &n); graph = vector<vector<int> >(n + 1); for (int i = 0; i < 2 * n; i++) { ...
### Prompt Your task is to create a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> std::list<int> edge[100111]; std::list<int>::const_iterator it; std::vector<int> ans; int n, i, j, k, l, max; bool done[100111]; bool dfs(int now) { if (now == l) return true; for (std::list<int>::const_iterator it1(edge[ans[now]].begin()); it1 != edge[ans[now]].end(); ++it1) if ...
### Prompt Please provide a CPP coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; vector<int> a[101011], b[101011]; bool visited[101011]; int ans[101011]; int main() { int n; cin >> n; for (int i = 0; i < n * 2; i++) { int u, v; cin >> u >> v; a[u].push_back(v); a[v].push_back(u); } bool nosolution = false; for (int i = 1; i <...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; int vis[100100], res[100100]; vector<int> Q[100100]; int main() { int n, x, y, p, t; while (cin >> n) { for (int i = (int)0; i < (int)100100; i++) Q[i].clear(), vis[i] = 0; for (int i = (int)0; i < (int)2 * n; i++) cin >> x >> y, Q[x].push_back(y), Q[y].pu...
### Prompt Generate a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; vector<int> tab[100100], ans; int n, ls[10]; bool used[100100]; bool chek(int a, int b) { for (int i = 0; i < 4; i++) if (tab[a][i] == b) return true; return false; } int main() { scanf("%d", &n); for (int i = 0; i < n + n; i++) { int a, b; scanf("%d%d",...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkMax(T& a, const T& b) { if (a < b) a = b; } template <typename T> inline void checkMin(T& a, const T& b) { if (a > b) a = b; } template <typename T> struct LinkedEdge { T data; int dest; LinkedEdge<T>* next; }; template <int ...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> int ao[100000][4]; int connected(int u, int v) { int h; for (h = 0; h < 4; h++) if (ao[u][h] == v) return 1; return 0; } int qq[100000]; int solve(int n, int u, int v, int w) { int h, i, x; qq[0] = u, qq[1] = v, qq[2] = w; for (i = 3; i < n; i++) { for (h = 0; h < 4; h++) { ...
### Prompt Develop a solution in CPP to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int n, x, y, cnt[100001]; bool vis[100001]; vector<vector<int> > v; vector<int> res; bool isGd(int node) { int c = 0; for (int i = (0); i < ((int)v[node].size()); i++) if (v[node][i] == res[(int)res.size() - 1] || v[node][i] == res[(int)res.size() - 2]) ...
### Prompt Create a solution in cpp for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 5; const long long maxm = 500000 + 5; const long long mod = 1000000007; vector<int> e[200010], ans; map<int, bool> vis[200010]; bool mark[200010]; int n; int main() { scanf("%d", &n); for (int i = 0; i < 2 * n; i++) { int x, y; scanf...
### Prompt Develop a solution in cpp to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using u64 = uint64_t; using pi64 = pair<i64, i64>; constexpr i64 MAXN = 3 * 100 * 1000 + 5LL; constexpr i64 MOD = 1000000007LL; constexpr i64 INF64 = MOD * MOD; bool is_possible(const vector<i64>& perm, const i64 N, const vector<vector<...
### Prompt Create a solution in cpp for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100009; int n, i, j, k, a[MAXN][5], s[MAXN], ans[MAXN], first, ct, l, now, re[10]; bool used[MAXN], flag; struct state { int num, co; } S[10]; int ex(int i, int j) { int b, c, d = 1; for (b = 0; b < 4; b++) if (a[i][b] != j) { for (c = 0; c ...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = (int)1e9; const int MAX_N = 200 * 1000 + 100; int n; int adj[MAX_N][4]; int len[MAX_N]; vector<int> ans; int inter(int ii, int jj) { int i = 0, j = 0; int ret = 0; while (i < 4 && j < 4) { if (adj[ii][i] == adj[jj][j]) { ...
### Prompt Create a solution in CPP for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; vector<int> edges[100010], edges2[100010], out; bool marked2[100010]; int marked[100010]; bool dver[100010]; int main() { int n; cin >> n; for (int i = 0; i < 2 * n; i++) { int a, b; cin >> a >> b; edges[a].push_back(b); edges[b].push_back(a); } if...
### Prompt Please provide a cpp coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double EPS = 1e-9; int n; int g[123456][5]; map<int, int> freq; bool vis[123456]; int sol[123456]; bool can(int a, int b, int c, int idx) { sol[idx] = b; if (idx < n) { vis[b] = 1; for (int i = 0; i < 4; i++) { int j = g[b][i...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; vector<int> a[100020]; int n, m, x, y; int v[100020]; int w[100020]; int s[100020]; int ooo = 1e9; int ok(int x) { ooo++; for (int i : a[s[x]]) v[i] = ooo; if (v[s[(x + 1) % n]] != ooo) return 0; if (v[s[(x + 2) % n]] != ooo) return 0; if (v[s[(x - 1 + n) % n]] !=...
### Prompt Please create a solution in Cpp to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int a[100002][5]; int f[100002], ans[100002], v[100002]; int n, ff; void dfs(int l) { if (ff == 1) return; int s = 0; int i; if (l > n) { s = 0; for (i = 0; i < f[ans[n]]; i++) { if (a[ans[n]][i] == 1) { s++; } if (a[ans[n]][i] == a...
### Prompt Generate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; vector<int> vec[100005]; vector<int> ans; int visited[100005]; int main() { long long n, x, y, flag = 0, prev = 1, tempx, tempy, flag2 = 0; cin >> n; for (int i = 0; i < 2 * n; i++) { cin >> x >> y; vec[x].push_back(y); vec[y].push_back(x); } for (int ...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; int n; vector<vector<int> > adj(1e5 + 1); set<int> rem; vector<int> ord; void search(int pred1, int pred2) { if (ord.size() == n) return; int nxt = 0; for (int j = 0; j < 4 && nxt == 0; j++) { for (int k = 0; k < 4; k++) { int x = adj[pred1][j], y = adj[pred...
### Prompt Your task is to create a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; int n, a, b; vector<int> adj[100010]; map<pair<int, int>, int> m; vector<int> res; bool visited[100010]; bool tenta(int a, int b, int c, int size) { visited[a] = visited[b] = visited[c] = true; if (m[pair<int, int>(a, b)] and m[pair<int, int>(b, c)] and m[pair<int...
### Prompt Please provide a Cpp coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; vector<long long> g[N]; long long ans[N]; bool used[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; for (long long i = 0; i < 2 * n; ++i) { long long u, v; cin >> u >> v; g[u].push_back(...
### Prompt In cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n; vector<int> graf[MAXN + 3]; bool odw[MAXN + 3]; int st[MAXN + 3], color[MAXN + 3]; int wyn[MAXN + 3], ind; void wczytaj() { scanf("%d", &n); for (int i = 0; i < 2 * n; i++) { int a, b; scanf("%d %d", &a, &b); graf[a].push_back...
### Prompt Generate a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:65777216") using namespace std; const long double EPS = 1e-11; const int INF = 2000000000; const long long lINF = 9223372036854775807; const long double PI = 3.14159265358979323846; vector<long long> ans; void cans() { for (int i = 0; i < ans.size(); i++) cout ...
### Prompt In Cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> v[N]; int num[N]; bool vis[N]; int len, n; bool Doit() { int i; for (i = 1; i <= n; i++) { if (v[i].size() != 4) return 0; } return 1; } bool DFS(int a, int fa, int th) { if (th == n + 1) return 1; if (!vis[a]) { int j; ...
### Prompt Please create a solution in Cpp to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 10; int n, u, v; int ans[MaxN][5]; int cnt[MaxN]; int vis[MaxN]; int d[MaxN]; bool dfs(int a, int b, int k) { d[k - 1] = a, d[k] = b; if (k == n) return b == 1; vis[b] = 1; for (int i = 1; i <= 4; i++) { int c = ans[b][i]; if (vis[c]) ...
### Prompt In cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; vector<set<int>> g; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; g.assign(n, set<int>()); for (int i = 0; i < 2 * n; ++i) { int u, v; cin >> u >> v; u--, v--; g[u].insert(v); ...
### Prompt Generate a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; vector<int> v[100005], kip[100005], sol; int chk[100005]; set<int> st; inline void cycle(int a) { sol.push_back(a); chk[a] = 1; if (chk[kip[a][0]] == 0) cycle(kip[a][0]); if (chk[kip[a][1]] == 0) cycle(kip[a][1]); return; } inline void PUT(int a) { int j, now; ...
### Prompt Please formulate a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; map<int, int> m[100001]; int ans[100001], vis[100001], n; vector<int> v[100001]; void dfs(int pos) { if (pos == n) { if (m[ans[n - 1]].find(ans[1]) != m[ans[n - 1]].end() && m[ans[n]].find(ans[1]) != m[ans[n]].end() && m[ans[n]].find(ans[2]) != m[ans[n...
### Prompt Please create a solution in CPP to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:256000000") const int kN = 100 * 1000; vector<int> gr[kN]; int cnt[kN]; vector<int> Perm() { int a = 0; for (int i = 0; i < gr[a].size(); ++i) { int u = gr[a][i]; for (int j = 0; j < gr[u].size(); ++j) { if (gr[u][j] == a) c...
### Prompt Create a solution in CPP for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; int n, node[100005][5], ans[100005]; bool vis[100005]; bool ok(int k, int v) { if (!k) return true; for (int i = 1; i <= 4; i++) if (node[k][i] == v) return true; return false; } bool dfs(int u, int num) { if (num == n) return true; for (int i = 1; i <= 4; i++...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> cnt(n); vector<set<int>> g(n); for (int i = 0; i < 2 * n; ++i) { int u, v; cin >> u >> v; --u, --v; g[u].insert(v); g[v].insert(u); cnt[v]++; cnt[u]++; } for (auto elem : cnt) { if (elem...
### Prompt Please formulate a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int n, dem, d[100010], kq[100010], dd[100010]; vector<int> a[100010]; void nhap() { cin >> n; int u, v; for (int i = 1; i <= 2 * n; i++) { scanf("%d%d", &u, &v); a[u].push_back(v); a[v].push_back(u); } } void dfs(int x, int y, int z) { int ok; d[x] =...
### Prompt Your task is to create a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; int n, a, b, ans[100100], used[100100]; vector<int> adj[100100]; bool con(int a, int b) { int i; if (a == 0 || b == 0) return true; for (i = 0; i < 4; i++) if (adj[a][i] == b) return true; return false; } void dfs(int p) { int i; if (p == n) { if (!(con(...
### Prompt Generate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; bool ok = 1; bool vis[100001] = {0}; vector<int> ng[100001], g[100001]; void print(int v, bool p) { vis[v] = 1; if (p) printf("%d ", v); ok &= ng[v].size() == 2; for (int i = 0; i < ng[v].size(); ++i) { int u = ng[v][i]; if (!vis[u]) print(u, p); } } inlin...
### Prompt Your task is to create a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; int A[100001][5]; int C[100001]; vector<int> V; int n, flag; void solve(int indx) { int i, sz, temp[4], a, j; if (flag) return; if (A[indx][0] != 4) { flag = 1; printf("-1\n"); return; } sz = V.size(); if (V.size() == n) { for (i = 0; i < n; i++)...
### Prompt Please create a solution in CPP to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const long long OO = 1e9; int n; vector<int> c[100005]; int vis[100005]; int ans[100005]; int cot[100005]; bool _find(int x, int cc) { for (int i = 0; i < c[x].size(); i++) if (cc == c[x][i]) return 1; return 0; } bool dfs(int x, int indx) { if (indx == n) return ...
### Prompt Construct a Cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; pair<int, int> ke[100005]; vector<int> a[100005], res; map<pair<int, int>, int> mm; int n, sl[100005], b[100005]; bool dd[100005]; void process() { for (int i = (1); i <= (n); i++) if (a[i].size() != 4) { cout << -1 << endl; exit(0); } for (int i = (...
### Prompt Please create a solution in CPP to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; vector<int> deg; vector<vector<int> > adj; set<long long> mat; int N, depth = 0; int vis[(int)1e5 + 5]; bool dfs(int f, int s, int t) { if (depth == N - 3) return 1; depth++; for (int j = 0; j < ((int)adj[t].size()); j++) { int nxt = adj[t][j]; if (mat.count(1...
### Prompt Develop a solution in Cpp to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int n, a, b, bylo[100007], uzyte[100007], t[100007]; vector<int> v[100007]; bool mozna; bool check(int x) { bylo[t[(x - 1 + n) % n]] = 1; bylo[t[(x - 2 + n) % n]] = 1; bylo[t[(x + 1) % n]] = 1; bylo[t[(x + 2) % n]] = 1; for (__typeof((v[t[x]]).begin()) it = ((v[t[...
### Prompt Construct a cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; map<pair<int, int>, int> mp; vector<int> v[maxn << 1]; int cnt[maxn], sta[maxn], tot; bool vis[maxn]; int n; int dfs(int fa, int u, int t) { if (vis[t]) return 0; sta[++tot] = t; if (tot == n) return 1; vis[u] = 1; for (int i = 0; i < 4; i...
### Prompt Your task is to create a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; vector<int> e[100010]; int bfs[100010], v[100010], used[100010], an[100010], ha[100010], n, tt; bool con(int x, int y) { for (int i = 0; i < e[x].size(); i++) { if (e[x][i] == y) return 1; } return 0; } bool check() { int i; for (i = 0; i < n; i++) { if (i...
### Prompt In CPP, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; vector<int> e[100006]; int n; bool nei(int a, int b) { for (int i = 0; i < 4; i++) { if (e[a][i] == b) return 1; } return 0; } bool is(int ans[], int x, int y) { bool v[100006] = {0}; int i, j; ans[0] = 1; v[1] = 1; ans[1] = e[1][x]; v[ans[1]] = 1; a...
### Prompt Your challenge is to write a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; vector<int> v[100010], ans; int in_d[100010], flag[100010], col; bool no_flag; int main() { int n, i, m, a, b; scanf("%d", &n); m = 2 * n; for (i = 1; i <= m; i++) { scanf("%d %d", &a, &b); in_d[a]++; in_d[b]++; v[a].push_back(b); v[b].push_back(...
### Prompt Construct a cpp code solution to the problem outlined: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<vector<int> > G(n); set<pair<int, int> > kraw; for (int i = 0; i < 2 * n; ++i) { int a, b; scanf("%d %d", &a, &b); --a; --b; G[a].push_back(b); G[b].push_back(a); if (a > b) swap(a, b); kr...
### Prompt Your task is to create a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; vector<int> v[1 << 20]; int n, a, b, sol[1 << 20]; map<pair<int, int>, bool> hashy; bool vi[1 << 20], is[10][10]; void dfs(int x, int pos) { if (sol[pos] != -1) return; vi[x] = 1; sol[pos] = x; int sz = v[x].size(), nxt; for (int j = 0; j < sz; j++) { nxt = v[...
### Prompt Please formulate a Cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int max_n = 100005; int n; vector<int> a[max_n]; int res[max_n]; bool visited[max_n]; int same(int x, int y) { int r = 0; map<int, int> m; for (int i = 0; i < 4; i++) { m[a[x][i]]++; } for (int i = 0; i < 4; i++) { if (m[a[y][i]] == 1) r++; } ret...
### Prompt Please formulate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int adj[200011][30], deg[200011], V[200011], ans[200011], ok, cnt = 3; map<pair<int, int>, int> vst; void dfs(int u, int fa1) { int vv = 0; for (int i = 0; i < 4; i++) { int v = adj[u][i]; if (V[v]) continue; if (vst[pair<int, int>(v, fa1)]) { V[v] = 1...
### Prompt Develop a solution in Cpp to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int n; vector<int> g[100005]; int nb[100005][2]; bool visited[100005]; void solve6() { int p[7], i, j; memset(p, 0, sizeof(p)); for (i = 1; i <= 6; ++i) { if (g[i].size() != 4) { printf("-1\n"); return; } sort(g[i].begin(), g[i].end()); for...
### Prompt Your task is to create a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; vector<int> v[100001]; int check(int p, int q) { int k = 0, u = 0, t = 0; while (u < 4 && t < 4) { if (v[p][u] == v[q][t]) k++, u++, t++; else if (v[p][u] < v[q][t]) u++; else t++; } return k; } int main() { int n, a, b; cin >> n; ...
### Prompt In cpp, your task is to solve the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is n...
#include <bits/stdc++.h> using namespace std; int n; vector<int> a[100000 + 5], v; bool vis[100000 + 5]; void DFS(int u) { if (v.size() == n) { for (int i = 0; i < v.size(); i++) printf("%d ", v[i]); exit(0); } for (int i = 0; i < a[u].size(); i++) { int k = a[u][i]; if (vis[k]) continue; if (...
### Prompt Please create a solution in Cpp to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int maxn = 100017; int n, deg[maxn], arr[maxn], res[maxn]; vector<int> a[maxn]; bool free1[maxn]; bool check() { int c, v; memset(free1, 1, sizeof(free1)); for (int i = 1, _c = 3; i <= _c; i++) free1[arr[i]] = 0; arr[n + 1] = arr[1]; arr[n + 2] = arr[2]; a...
### Prompt Please formulate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int MAX_V = 100000; vector<int> adjlist[MAX_V + 5]; int N, x, y, component, sz, deg[MAX_V + 5], A[MAX_V + 5]; bool visit[MAX_V + 5]; void dfs(int u) { visit[u] = 1; for (int i = 0; i < (int)adjlist[u].size(); i++) { int v = adjlist[u][i]; if (!visit[v]) df...
### Prompt Generate a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is numb...
#include <bits/stdc++.h> using namespace std; vector<int> a[100020]; int edgeu[100020 * 2], edgev[100020 * 2]; bool chose[100020]; vector<int> apart[100020]; int cnt[100020], ans[100020]; bool vis[100020]; int n, m = 0; void Read() { int i, u, v; scanf("%d", &n); for (i = 1; i <= n * 2; i++) { scanf("%d%d", &...
### Prompt Create a solution in cpp for the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is nu...
#include <bits/stdc++.h> using namespace std; int i, j, n, k, c, x, y, c1, c2, c3, z; bool u[100009]; vector<int> a[100009]; int ans[100009]; bool res; bool cmp(int a, int b) { return a < b; } void search() { int i, j, k; bool p1, p2; for (i = 0; i < 100009; i++) { if (a[i].size() != 0) { c1 = i; ...
### Prompt Your task is to create a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or...
#include <bits/stdc++.h> using namespace std; int n; int ans[100100]; vector<int> g[100100]; int vis[100100]; bool judge1(int cur, int val) { if (cur <= 2) return true; int i, j; int pre = cur - 2; int k = ans[pre]; for (i = 0; i < 4; i++) { if (g[k][i] == val) { return true; } } return fals...
### Prompt Please create a solution in cpp to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int a[500500], n, x, y, used[500500]; vector<int> g[500500]; set<pair<int, int> > s; int main() { scanf("%d", &n); for (int i = 0; i < n + n; i++) { scanf("%d%d", &x, &y); --x; --y; g[x].push_back(y); g[y].push_back(x); s.insert(make_pair(x, y));...
### Prompt Please provide a CPP coded solution to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; vector<int> road[100011]; bool vis[100011]; bool find(int p, int a, int b, int c, int d) { for (int i = 0; i < 4; i++) if (road[p][i] != a && road[p][i] != b && road[p][i] != c && road[p][i] != d) return 0; return 1; } int now[100011] = {0}; int main()...
### Prompt Develop a solution in CPP to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; set<int> G[maxn]; bool v[maxn]; int cnt[maxn]; vector<int> ans; void dfs(int now, int p) { v[now] = true; ans.emplace_back(now); for (int u : G[now]) if (!v[u]) { if (p && G[p].count(u) == 0) continue; int cnt = 0; for ...
### Prompt Please formulate a cpp solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, head[N], pre[N << 2], nxt[N << 2], e, deg[N], ans[N]; bool vis[N]; set<pair<int, int> > st; void init() { memset(head, -1, sizeof(head)); e = 0; } void add(int u, int v) { pre[e] = v, nxt[e] = head[u], head[u] = e++; } bool judge() { int i...
### Prompt Develop a solution in Cpp to the problem described below: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there...
#include <bits/stdc++.h> using namespace std; int adj[111111][4]; int edge[222222][2]; int n; void build() { memset(adj, 0, sizeof(adj)); for (int i = 0; i < n + n; i++) { for (int j = 0; j <= 1; j++) { int f = edge[i][j]; int t = edge[i][1 - j]; if (adj[f][0] == 0) adj[f][0] = t; ...
### Prompt Your challenge is to write a CPP solution to the following problem: One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if ((n / 2) % 2 > 0) { cout << -1; return 0; } for (int i = 1; i <= n / 4; i++) { cout << i * 2 << ' ' << n - (i - 1) * 2 << ' '; } if (n % 2 != 0) cout << (n + 1) / 2 << ' '; for (int i = n / 4; i >= 1; i--) { c...
### Prompt Please formulate a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int N, res; int ar[MAXN]; int main() { cin >> N; if (N % 4 > 1) { cout << -1 << endl; return 0; } for (int i = 1, k = 0; k + 4 <= N; i += 2, k += 4) { ar[i] = i + 1; ar[i + 1] = N - i + 1; ar[N - i + 1] = N - i; ar[N...
### Prompt Your challenge is to write a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int temp = n / 2; if (temp % 2 != 0) { cout << -1 << endl; return 0; } int arr[100010]; if (n % 2 == 1) { arr[(n / 2) + 1] = n / 2 + 1; } for (int i = 1; i <...
### Prompt Your challenge is to write a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int g[100100]; int main() { int n; scanf("%d", &n); if (((n & 1) && (n - 1) % 4 != 0) || ((n & 1) == 0 && n % 4 != 0)) printf("-1\n"); else { int ini = n / 2; for (int i = 1; i < n + 1; ++i) g[i] = -1; if (n & 1) g[n / 2 + 1] = ini + 1; for (int ...
### Prompt Please provide a Cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int N, P[200001]; int main() { cin >> N; if (N & 1) { if (N % 4 == 1) { for (int i = 1; i <= N / 2; i += 2) { P[i] = i + 1; P[i + 1] = N - i + 1; P[N - i + 1] = N - i; P[N - i] = i; } P[N / 2 + 1] = N / 2 + 1; ...
### Prompt Your task is to create a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) cout << "-1"; else { int a[n + 1]; a[n / 2 + 1] = n / 2 + 1; for (int i = 1; i < n / 2; i += 2) { a[i] = i + 1; a[i + 1] =...
### Prompt Your challenge is to write a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int A[111111]; int main(void) { int n; int a = 2, b; cin >> n; if (n % 4 > 1) { cout << -1 << endl; return 0; } b = n; for (int i = 0; i < n / 2; i++) { if (i % 2 == 0) { A[i] = a; a += 2; } else { A[i] = b; b -= 2; ...
### Prompt Develop a solution in CPP to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; bool vis[1000 * 100 + 100]; bool vis2[1000 * 100 + 100]; int val[1000 * 100 + 100]; int main() { int n; cin >> n; if (n % 4 > 1) { cout << -1 << endl; return 0; } if (n == 1) { cout << 1 << endl; return 0; } int v = 2; for (int i = 1; i <= n;...
### Prompt Develop a solution in cpp to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; int main() { int i, t, j, tmp, n, m, k, cnt, fl, ind; cin >> n; if (n % 4 != 0 and n % 4 != 1) { printf("-1\n"); return 0; } vector<int> ar(n); ar[n / 2] = n / 2 + 1; i = 0; j = n - 1; while (i < j) { ar[i] = i + 2; ar[i + 1] = j + 1; a...
### Prompt Your challenge is to write a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int i, j, k, x, y, z, n, m; bool found; int a[100001]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return 0; } if (n % 2 == 1) { for (i = 1; i < n / 2 + 1; i += 2) a[i] = i + 1; for (i = n / 2 + 3; i <= n; i += 2) a[i] ...
### Prompt Your task is to create a cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } if (n <= 3) { cout << -1 << endl; return 0; } if (n % 2 == 0) { if (n % 4 != 0) { cout << -1 << endl; return 0; } for (int i = 1; ...
### Prompt In CPP, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; scanf("%d", &n); if (n % 4 > 1) printf("-1\n"); else { for (int i = 1; i <= n >> 1; i++) { if (i % 2) printf("%d ", i + 1); else printf("%d ", n - i + 2); } int m = n >> 1; if (n % 4 == 1) { ...
### Prompt Create a solution in CPP for the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You h...
#include <bits/stdc++.h> using namespace std; int a[100100]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } if (n % 2) a[n / 2 + 1] = n / 2 + 1; int num1 = 2; int num2 = n; for (int i = 1; i <= n / 2; i += 2) { a[i] = num1; a[n - i + 1] =...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; const int N = 111111; int rec[N]; int main() { int n; while (cin >> n) { if ((n & 3) >= 2) { puts("-1"); continue; } int hf = n >> 1; for (int i = 1; i <= hf; i++, i++) { rec[i] = i + 1; rec[n - i] = i; } for (int i = 2; i...
### Prompt Please formulate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int n, v[100010]; int p[100010]; bool flag, z = 0; void dfs(int id, int s, int ci) { if (ci == 5) { flag = 1; retur...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int n; int ans[100010]; bool vst[100010]; void dfs(int pos) { if (!vst[ans[pos]]) { vst[ans[pos]] = 1; ans[ans[pos]] = n - pos + 1; dfs(ans[pos]); } else return; } int main() { while (scanf("%d", &n) != EOF) { memset(ans, 0, sizeof(ans)); memse...
### Prompt Generate a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You hav...
#include <bits/stdc++.h> using namespace std; int perm[100001]; int main() { ios_base::sync_with_stdio(false); cout.precision(30); int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return 0; } if (n % 4 == 1) perm[(n + 1) / 2] = (n + 1) / 2; for (int i = 1; i <= n / 2; i += 2)...
### Prompt Construct a Cpp code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> using namespace std; int N; int main() { scanf("%d", &N); if (N % 4 == 2 || N % 4 == 3) { printf("-1\n"); return 0; } for (int i = 1; i <= N / 2; i += 2) { printf("%d %d ", i + 1, N - i + 1); } if (N % 4 == 1) printf("%d ", (N + 1) / 2); for (int i = (N + 3) / 2; i <= ...
### Prompt Your task is to create a CPP solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> using namespace std; int p[100010]; int N; int main() { cin >> N; int pre; for (int i = 0; i < N / 4; i++) p[2 * i + 1] = 2 * i + 2; if (N % 4 == 1) p[N / 2 + 1] = N / 2 + 1; if (N % 4 != 0 && N % 4 != 1) { cout << -1 << endl; return 0; } for (int i = 1; i < N; i++) { ...
### Prompt Please create a solution in CPP to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> int clock0 = clock(); using namespace std; template <class _T> inline _T sqr(const _T &first) { return first * first; } template <class _T> inline string tostr(const _T &a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795L; con...
### Prompt In Cpp, your task is to solve the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You ...
#include <bits/stdc++.h> int n, i, k, a[100100]; int main() { scanf("%d", &n); if (n % 4 > 1) { puts("-1"); return 0; } for (i = k = 0; k + 4 <= n; i += 2, k += 4) { a[i + 1] = i + 2; a[i + 2] = n - i; a[n - i] = n - i - 1; a[n - i - 1] = i + 1; } if (k + 1 == n) a[i + 1] = i + 1; ...
### Prompt Please provide a cpp coded solution to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int n, i, ara[100009], cnt; unordered_map<int, bool> q; cin >> n; for (i = 1, cnt = 1; i <= n / 2; i++) { if (cnt++ % 2) { if (q[i + 1]) cout << "-1" << '\n', exit(0); ara[i]...
### Prompt Develop a solution in CPP to the problem described below: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238463; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; } if (n % 4 == 3 || n % 4 == 2) { cout << -1 << endl; return 0;...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i...
#include <bits/stdc++.h> int a[100000 + 1]; int main() { int n; scanf("%d", &n); if (n % 4 < 2) { for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n + 1 - i; a[n + 1 - i] = n - i; a[n - i] = i; } if (n % 4 == 1) a[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n...
### Prompt Construct a CPP code solution to the problem outlined: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. Yo...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; long double sqr(long double a) { return a * a; } const long long int inf = 1000000000000000LL; long double mpow(long double a, long long int b) { if (b == 0) return 1.0; if (b % 2 == 0) { long double c = mpow(a, b / 2); return c *...
### Prompt Your task is to create a Cpp solution to the following problem: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i...