Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> ad[100000]; int ans[100000]; bool used[100000]; int d[4] = {-2, -1, 1, 2}; int n; bool check() { int i, j, k; memset(used, false, sizeof(used)); used[ans[0]] = true; used[ans[1]] = true; used[ans[2]] = true; used[ans[3]] = true; for (i = 2; i < n -...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> adj[100009]; int col[100009], occ[100009]; vector<int> out; int n, u, v; bool solve(int a, int b) { memset(col, (0), sizeof(col)); ; out.clear(); out.push_back((1)); out.push_back((a)); out.push_back((b)); col[1] = col[a] = col[b] = true; for (in...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
// @author Sanzhar import java.io.*; import java.util.*; public class Template { BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; const int oo = 1 << 30; const double PI = M_PI; const double EPS = 1e-15; const int MaxV = 100005; int V, E; vector<int> g[MaxV]; vector<int> answer; bool used[MaxV]; int pos[MaxV]; bool find(int node, int x) { for (int i = 0; i < 4; i++) if (g[node][i] == x) return t...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> ans, a[200000]; map<int, int> was; int p1, p2, pr, pt; int k; int n, x, y; void dfs() { int sz = ans.size(); int x = ans[sz - 1]; int y = ans[sz - 2]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) if (a[x][i] == a[y][j] && !was[a[y][j...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedList; import java.util.StringTokenizer; public class C { static class Scanner{ BufferedReader br=null; StringTokenizer tk=null; public Scanner(){ br=new BufferedR...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &o, vector<T> &v) { for (typeof(v.size()) i = 0; i < v.size(); ++i) o << v[i] << " "; o << endl; return o; } int neigh[112345][4]; int deg[112345], a[112345]; int taken[112345]; void isvalid(bool x) { if (!x) { p...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; vector<int> v[maxn]; vector<int> li[maxn], out; bool vis[maxn]; void dfs(int x) { vis[x] = 1; out.push_back(x); for (int i = 0; i < li[x].size(); i++) { if (!vis[li[x][i]]) dfs(li[x][i]); } } int cnt(int a, int b) { int res = 0;...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#include <bits/stdc++.h> using namespace std; static inline bool get(int &v) { int s = 1, c; while (!isdigit(c = getchar()) && c != '-') { if (c == EOF) break; } if (c == EOF) return 0; if (c == '-') s = 0, v = 0; else v = c ^ 48; for (; isdigit(c = getchar()); v = (v << 1) + (v << 3) + (c ^ 4...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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<...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]; ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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()...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; public class C { ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
/** * Created with IntelliJ IDEA. * User: yuantian * Date: 3/3/13 * Time: 10:57 PM * To change this template use File | Settings | File Templates. */ import java.util.*; public class CircleOfNumbers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nex...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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() { ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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;...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 & (...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
n = input() e = [set() for _ in range(n + 1)] def g(r): if len(r) != n: return False r = r * 3 for i in range(n): if len(e[r[i]] - set(r[i - 2 + n : i + 3 + n])): return False return True def f(): for i in range(n): if len(e[i + 1]) != 4: return [-1] if n == 5: return range(1, 6) for x in e[1]: ...
PYTHON
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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] == ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); ArrayList<Integer>[] adjList = new ArrayList[n + 1]; for(int i = 1; i <= n; ++i) ad...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 == ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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++) { ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 <...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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",...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.*; import java.util.*; public class C { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; HashSet<Integer>[] g; int n; void checkAndOutput(int[] ans) { for (int i = 0; i < n; i++) { int v = ans[i]; int j = i + 1; if (j >= n) j -= n; if (!g[v].contains(ans[...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
/** * Created with IntelliJ IDEA. * User: Venky */ import java.io.*; import java.util.*; public class Main { static void solve() throws IOException { int n = nextInt(); int flag = 1; int[][] edges = new int[n][4]; int[] index = new int[n]; int[] ret = new int[n]; ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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++) { ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]) ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.util.Arrays; import java.util.Scanner; // http://codeforces.com/contest/263/problem/C public class CircleofNumbers { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[][] adj = new int[n + 1][4]; int[] cnt = new int[n ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashSet; public class CodeforcesR162Div2C { public static int[] parseNumbers(String line, int n) { int[] numbers = new int[n]; int idx = 0; for(int i = 0; i < line.leng...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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<...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]) { ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#!/usr/local/bin/python3 from __future__ import print_function import sys DEBUG = '-d' in sys.argv def debug(*args, **kwargs): if DEBUG: print(*args, file=sys.stderr, **kwargs) return None def main(): n = int(input()) cnt = [0] * (n + 1) edge = [] for i in range(0, n + 1): ...
PYTHON3
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.*; import java.math.*; import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } StreamTokenizer in; PrintWriter out; //deb///////////////////////////...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import sun.reflect.generics.tree.Tree; import java.io.*; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; public class Main { static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.util.*; import java.io.*; public class hercules { public static int findNext(HashSet<Integer>over,ArrayList<Integer> []array,int prev,int check[],int ptr){ for(int a:array[prev]){ if(over.contains(a))continue; int cnt=0; for(int b:array[a]){ if(check[ptr-1]==b) cnt++; } ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]] !=...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class C{ // Scanner sc=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int IN...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Random; import java.util.StringTokenizer; public class Solution{ static int n; static HashSet<Inte...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.util.*; import java.io.*; import java.math.BigInteger; import static java.lang.Math.*; public class Main { int [] way; boolean check (int n, int [][] a){ boolean used[] = new boolean[n]; used[0] = used[way[1]] = used[way[2]] = true; for (int i = 3; i < n; i++){ boolean flag = false; ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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(...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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; ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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]) ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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); ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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; ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
from sys import stdin all_in = stdin.readlines() n = int(all_in[0]) pairs = list(map(lambda x: tuple(map(int, x.split())), all_in[1:])) if n == 5: print(1, 2, 3, 4, 5) exit() neigs = {i: set() for i in range(1, n + 1)} for (a, b) in pairs: neigs[a].add(b) neigs[b].add(a) for el in neigs.values(): ...
PYTHON3
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.util.*; import java.io.*; public class Main { BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.ArrayList; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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++...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.List; import java.io.IOException; import java.util.InputMismatchException; import java.util.ArrayList; import java.util.NoSuchElementException; import java.m...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Com...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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] =...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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(...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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++)...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.*; import java.util.*; import java.util.StringTokenizer; public class SolutionC { BufferedReader in; StringTokenizer str; PrintWriter out; String SK; String next() throws IOException { while ((str == null) || (!str.hasMoreTokens())) { SK = in.readLine(); if (SK == null) return n...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.*; import java.util.*; public class C { void run() throws IOException { int n = ni(), m = 2 * n; int[][] a = new int[n][4]; int[] b = new int[n]; boolean[] c = new boolean[n]; for (int i = 0; i < m; i++) { int x = ni() - 1, y = ni() - 1; ...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 = (...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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[...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import sys, array #, time #S = time.time() readInts = lambda : map(int, raw_input().split()) #readArgs = lambda : raw_input().split() #write = lambda *s: sys.stdout.write(' '.join(map(str, s))) #sys.stdin = open('data.txt', 'r') #sys.stdout = open('ans.txt', 'w') n = readInts()[0] if n == 5: print 1, 2, 3, 4, 5 sys.e...
PYTHON
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Task161C { static PrintWriter output; static int[][] points = new int[100000+1][4]; /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { output = ne...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
//package round161; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class C { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int...
JAVA
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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(...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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[...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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; ...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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 (...
CPP
263_C. Circle of Numbers
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 number c, such that a and с are immediate neighbors, and b and c ar...
2
9
#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...
CPP