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 |
import java.io.DataInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
public class Circle_of_numbers {
static LinkedList<Integer>[] g;
static boolean[] visited;
public static void main(String[] args) throws Exception {
Cir... | 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 N = 100100;
int n, u, v, i, vis[N];
vector<int> ans;
set<int> edges[N];
bool check(int u, int v, int p) {
if (p > 0 && !edges[p].count(v)) return 0;
int cnt = 0;
for (int x : edges[v]) cnt += edges[u].count(x);
return (cnt >= 2);
}
void solve(int u = 1, 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 | #include <bits/stdc++.h>
using namespace std;
vector<int> d[111111];
int i, n, m, v1, v2, h[111111], s[111111];
bool ok() {
int v = 0;
for (int t = 0; t < 4; t++) {
if (d[h[n]][t] == h[1]) ++v;
if (d[h[n]][t] == h[2]) ++v;
if (d[h[n - 1]][t] == h[1]) ++v;
}
if (v == 3)
return true;
else
re... | 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>
const int MAXN = 100005;
const int MAXM = MAXN * 4;
struct Edge {
int v, next;
} edge[MAXM];
int n, num[MAXN], head[MAXN], e, ans[MAXN];
bool vis[MAXN];
void addedge(int u, int v) {
edge[e].v = v;
edge[e].next = head[u];
head[u] = e++;
}
bool dfs(int u, int p, int k) {
if (k == n) 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;
struct node {
int v, next;
} a[500000];
int h[100005], s = 0, n, p[100005], l[100005] = {0}, m, u, v;
bool e, f[100005] = {false}, g = true, q, w;
bool back(int u, int c, int d) {
if (d == n) return true;
if (!f[u]) {
f[u] = true;
p[d] = u;
if (c == -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 | import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
public class CircleOfNumbers {
public static void main(String[] args) {
FasterScanner sc = new FasterScanner();
int N = sc.nextInt();
... | 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 = 2e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
vector<int> pnt[maxn];
int loc[maxn], vis[maxn];
map<int, bool> flag[maxn];
int main() {
int n;
cin >> n;
int a, b;
for (int i = 0; i < 2 * n; i++) {
cin >> a >> b;
pnt[a].push_b... | 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<vector<int> > E;
vector<int> nodes;
bitset<100001> bs;
int n;
bool connected(int a, int b) {
bool ans = false;
for (int i = 0; i < 4; ++i) {
if (E[a][i] == b) {
ans = true;
break;
}
}
return ans;
}
bool dfs(int a, int b, int k, int lim) {
... | 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.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class C {
public ArrayList<Integer> getIntersection(int[] list1, int[] list2){
ArrayList<Integer> ret = new ArrayList<Integer>();
for(int i = 0; i < list1.length; i++){
for(int j = 0; ... | 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;
int in[100003], g[100003][5], d[100003], v[100003];
int dfs(int a, int b, int f = 0, int k = 1) {
v[k - 1] = a;
v[k] = b;
if (k < n) {
in[b] = 1;
for (int i = 0; i < (int)4; i++) {
int c = g[b][i];
if (f == c || in[c] == 1) continue;
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 = 100000 + 10;
int n;
int a[maxn];
int g[maxn][5];
bool b[maxn];
int x, y;
int i;
int dep;
void print() {
for (int i = 1; i <= n; i++) printf("%d ", a[i]);
exit(0);
}
bool ok(int u, int x) {
if (!u) return true;
if (a[u] == g[x][1] || a[u] == g[x][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 | #include <bits/stdc++.h>
using namespace std;
int N;
int deg[100010];
vector<int> ngh;
set<int> f[100010];
void read();
void soups_on();
int main() {
read(), soups_on();
return 0;
}
void read() {
int u, v;
cin >> N;
for (int i = 0; i < 2 * N; ++i) {
cin >> u >> v;
++deg[u], ++deg[v];
f[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;
int n, m, ans[100005];
vector<int> graph[100005];
int u, v;
int used[100005];
int check(int u, int v) {
for (int i = 0; i < graph[u].size(); ++i)
if (graph[u][i] == v) return 1;
return 0;
}
bool solve() {
for (int i = 1; i <= n; ++i) used[i] = 1;
used[ans[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 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static int MOD = 1000000007;
// After writing solution, quick scan for:
// array out of bounds
// special cases e.g. n=1?
//
// Big numbers arithmetic bugs:
// int overflow
// sorting, or tak... | 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 | from collections import defaultdict
ri = lambda: map(int, raw_input().split())
edges = [[] for _ in xrange(200001)]
def dfs(n, k0, k1, k2):
path = [k0, k1, k2]
l = 3
while l < n:
dk = next((i for i in edges[k1] if i != k0 and i in edges[k2]), None)
if dk is None: return None
path.ap... | 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;
long long n, u, v, i, vis[100005];
vector<long long> ans;
set<long long> edges[100005];
bool check(int u, int v, int p) {
if (p > 0 && !edges[p].count(v)) return 0;
long long cnt = 0;
for (int x : edges[v]) cnt += edges[u].count(x);
return (cnt >= 2);
}
void solve(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>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-5;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
vector<vector<long long> > g;
long long n, p[11], h[100005], used[100005]... | 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 | import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
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 is... | 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.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
public class CircleOfNumbers {
public static void main(String[] args) {
FasterScanner sc = new FasterScanner();
int N = sc.nextInt();
... | 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 mod = 1e9 + 7;
vector<int> graph[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a, b;
for (int i = 0; i < 2 * n; i++) {
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
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 | #include <bits/stdc++.h>
using namespace std;
int n, i, j, x, y, ev, l, p, u, sel[100005], q[100005];
vector<int> G[100005];
int DF() {
while (p <= u) {
int x = q[p], y = q[p - 1];
for (int i = 0; i < 4; ++i) {
int aux = G[x][i];
int ev = 0;
for (int j = 0; j < 4; ++j)
if (G[aux][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 = 2e5 + 5;
vector<int> a[maxn];
bool used[maxn];
void solve() {
vector<pair<int, int> > v;
bool jin[10] = {};
for (int i = 1; i <= 6; ++i) {
if (jin[i]) continue;
jin[i] = true;
used[i] = true;
for (int j = 0; j < a[i].size(); ++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;
int n, p[100005], ady[100005][4], cnt = 1;
bool used[100005];
bool dfs(int nd, int t) {
used[nd] = true;
if (++cnt == n) {
p[nd] = 1;
bool ok = true;
while ((t = p[t]) > 1 && ok) {
ok = false;
for (int j = 0; j < 4; ++j)
if (t == ady[p[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;
priority_queue<long long int, vector<long long int>, greater<long long int>> ti;
vector<long long int> s[300005], f(300005, 0), a(300005, 0);
set<long long int> p[300005];
vector<long long int> d(300005, 0);
map<pair<long long int, long long int>, long long int> mp;
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 | import java.util.*;
import static java.lang.System.*;
public class B263 {
Scanner sc = new Scanner(in);
int[] path;
boolean[] used;
int[][] link;
public void run() {
int n=sc.nextInt();
path=new int[n+1];
used=new boolean[n+1];
link=new int[n+1][4];
for(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;
int n;
vector<int> adj[100005];
set<pair<int, int> > S;
bool vis[100005], sol[100005];
bool solve(int f, int s, int t, bool print, int depth = 0) {
if (depth == n - 3) return 1;
for (int i = 0; i < (int)adj[t].size(); i++) {
if (S.count(make_pair(s, adj[t][i])) && f... | 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>
const int maxn = 100100;
std::vector<int> adj[maxn];
std::vector<int> ans;
std::map<int, bool> mp[maxn];
bool vis[maxn];
int n, u, v;
int main() {
scanf("%d", &n);
for (int i = 0; i < 2 * n; i++) {
scanf("%d %d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
mp[u][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;
int countCommon(int a, int b, int temp2[][5]);
int countCommon(int a, int b, int temp2[][5]) {
int count = 0;
int common = 0;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
if (temp2[a][i] == temp2[b][j]) {
count++;
if (count >... | 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 = 100010;
vector<int> G[MAXN];
bool vis[MAXN];
int ans[MAXN];
int N, M;
bool dfs(int u, int fa, int val) {
vis[u] = true;
ans[val] = u;
if (val == N) return true;
if (fa == -1) {
for (int i = 0; i < (int)G[u].size(); i++) {
int v = G[u][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.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class NumbersRange {
static int n;
static int[] path;
static boolean[] vis;
static int[][] a;
public static void main(... | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHel... | 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 N = 100005;
vector<int> a[N];
int u[N];
vector<int> s;
int neighbor(int x, int y) {
static int P[2 * N];
int nP = 0;
for (__typeof((a[x]).begin()) it = (a[x]).begin(); it != (a[x]).end(); it++)
P[nP++] = *it;
for (__typeof((a[y]).begin()) it = (a[y]).b... | 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 = 1e5 + 2;
int n, cir[N];
vector<int> adj[N];
bool mark[N], flag;
bool contain(int base, int num) {
for (int i = 0; i < adj[cir[base]].size(); i++)
if (adj[cir[base]][i] == cir[num]) return true;
return false;
}
void bt(int k);
int main() {
scanf("%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 | #include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 5;
int n, u, v;
bool vis[N];
vector<int> ans, adj[N];
bool find_swap(int u, int x, int to) {
for (int i = to; i < 4; i++) {
if (adj[u][i] == x) {
swap(adj[u][i], adj[u][to]);
return true;
}
}
return false;
}
int main() {
ios_b... | 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 static java.util.Arrays.*;
import java.io.*;
import java.lang.reflect.*;
public class C {
final int MOD = (int)1e9 + 7;
final double eps = 1e-12;
final int INF = (int)1e9;
int [][] L;
int N;
public C () {
N = sc.nextInt();
L = new int [N+1][4];
int [] C = new int [N+1];
if (N == 5)
ex... | 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 <class T>
T two(T x) {
return 1 << x;
}
template <class T>
void Min(T &x, T y) {
if (y < x) x = y;
}
template <class T>
void Max(T &x, T y) {
if (y > x) x = y;
}
const int maxn = 100010;
const int mod = 1000000007;
vector<int> edge[maxn];
int ans[maxn];
bool ... | 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<int, bool> num[100005];
vector<int> num2[100005];
vector<int> resp;
int vis[100005];
int main() {
int i, j, n, comum, a, b;
scanf(" %d", &n);
for (i = 0; i < 2 * n; i++) {
scanf(" %d %d", &a, &b);
num2[a].push_back(b);
num2[b].push_back(a);
num[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;
const int MAXN = 100001;
const int MAXM = MAXN * 4;
struct Edge {
int v, next;
} edge[MAXM];
int head[MAXN], edgeNumber;
void initEdge() {
edgeNumber = 0;
memset(head, -1, sizeof(head));
}
void addEdge(int u, int v) {
edge[edgeNumber].v = v;
edge[edgeNumber].next ... | 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 cmp[100009];
vector<int> ans;
vector<vector<int> > AdjList_ans, AdjList;
void dfs(int nodo) {
ans.push_back(nodo);
cmp[nodo] = true;
for (int i = 0; i < AdjList_ans[nodo].size(); i++) {
int v = AdjList_ans[nodo][i];
if (!cmp[v]) dfs(v);
}
}
set<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 int maxn = 100000 + 5;
int n, m;
int ans[maxn];
bool used[maxn];
bool exist = false;
vector<int> e[maxn];
bool dfs(int u, int v, int depth) {
if (depth == n) return true;
if (used[v]) return false;
used[v] = true;
ans[depth] = v;
if (u == -1) {
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 | #include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<char> q;
vector<int> p;
int n;
vector<char> u;
int dfs(int f) {
for (int z = 0; z < 4; ++z) {
int t = v[f][z];
if (!u[t]) {
int x = 0;
for (int i = 0; i < 4; ++i) {
int c = v[t][i];
if (c == f) continue;
... | 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[100005][5], b[100005], c[100005];
bool visit[100005];
bool dfs(int t, int x, int y) {
int i, k;
b[t - 1] = x;
b[t] = y;
if (t == n) {
if (y == 1)
return true;
else
return false;
}
visit[y] = true;
for (i = 0; i < 4; i++) {
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 | #include <bits/stdc++.h>
using namespace std;
vector<set<int> > g;
vector<int> ans;
vector<bool> used;
void dfs(int v, int p) {
used[v] = true;
ans.push_back(v);
for (set<int>::iterator i = g[v].begin(); i != g[v].end(); i++) {
if (!used[*i] && g[*i].count(p)) dfs(*i, v);
}
}
int main() {
int n;
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 | #include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
vector<int> mp[100100];
vector<int> v;
int checkk[111111];
int cntt[111111];
int get_n(int a, int b) {
int res = 0;
for (int i = 0, maxi = (int)mp[a].size(); i < maxi; i++) {
for (int j = 0, maxj = (int)mp[b].size(); j < m... | 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
n = input()
e = [[] for _ in xrange(n)]
for i in xrange(2 * n):
a, b = map(int, raw_input().split())
e[a - 1].append(b - 1)
e[b - 1].append(a - 1)
for i in xrange(n):
if len(e[i]) < 4:
print -1
sys.exit(0)
if n <= 5:
print ' '.join(map(str, range(1, n + 1)))
sys... | 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;
vector<int> a[100003];
int n, u, v;
int ok[100003];
int b[100003];
void nhap() {
cin >> n;
for (int i = 1; i <= 2 * n; i++) {
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
}
}
bool kt(int u, int v) {
for (int i = 0; i < a[u].size(); i++)
if (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>
const int INF = 2000 * 1000 * 1000;
using namespace std;
void output(const vector<int>& a) {
for (int i = 0; i < a.size(); ++i) {
cout << a[i] + 1 << " ";
}
cout << endl;
}
bool check(const vector<int>& cycle, const vector<set<int> >& a) {
int n = cycle.size();
for (int i = 0; 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> 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class circleNums {
static ArrayList<Integer> path = new ArrayList<Integer>();
static ArrayList<Integer>[] graph = ... | 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[100005];
int ans[100005] = {0}, n, used[100005] = {0};
bool con(int x, int y) {
for (int i = 0; i < 4; i++)
if (a[x][i] == y) return 1;
return 0;
}
bool dfs(int p) {
if (p == n) {
if (con(ans[n - 1], ans[1]) && con(ans[n], ans[1]) && con(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 | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 * 1000 + 4, Inf = 1e9 + 10;
vector<int> adj[Maxn], ans;
int p[Maxn];
bool mark[Maxn];
int uu = 0;
bool Is(int i) {
return (count(adj[uu].begin(), adj[uu].end(), i) && !mark[i]);
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
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;
pair<int, int> pairs[2 * 100000 + 10];
vector<int> adj[100000 + 10];
bool done[100000 + 10];
int result[100000 + 10];
void check(int N) {
bool adj[N + 2][N + 2];
memset(adj, false, sizeof(adj));
for (int i = 1; i <= 2 * N; i++) {
scanf("%d %d", &pairs[i].first, &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;
map<int, bool> cnx[maxn];
vector<int> cnx2[maxn];
vector<int> res;
int visited[maxn];
int n, comun, u, v;
int main() {
cin >> n;
for (int i = 0; i < 2 * n; i++) {
cin >> u >> v;
cnx[u][v] = true;
cnx[v][u] = true;
cnx2[u].push_ba... | 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.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.InputMismatchException;
/**
* Actual s... | 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 sys
n = input()
e = [[] for _ in xrange(n)]
for i in xrange(2 * n):
a, b = map(int, raw_input().split())
e[a - 1].append(b - 1)
e[b - 1].append(a - 1)
for i in xrange(n):
if len(e[i]) < 4:
print -1
sys.exit(0)
if n <= 5:
print ' '.join(map(str, range(1, n + 1)))
sys... | 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 | //package codeforces;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.StreamTokenizer;
public class CodeForces {
public void run() throws IOException {
MyScanner sc ... | 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 = 100100;
int head[MAXN], app[MAXN], ans[MAXN];
;
int n, a, b, num, tot;
bool ok, vis[MAXN];
void print() {
if (ok) return;
cout << "-1" << endl;
exit(0);
}
struct Edge {
int to, from;
int nxt;
} edge[4 * MAXN];
void add_edge(int from, int to) {
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> G[100010];
int a[100010], b[4];
bool vis[100010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n + n; i++) {
int a, b;
scanf("%d %d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
if (G[... | 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")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double Pi = acos(-1);
using namespace std;
int debug = 0;
int main() {
int n;
cin >> n;
vector<int> v[n + 1];
int x, y;
for (int i = 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;
int n;
vector<vector<int> > con;
vector<pair<int, int> > edge;
void func(int b, int c) {
stack<int> ans;
ans.push(b);
ans.push(c);
vector<char> vis(n);
vis[0] = vis[b] = vis[c] = true;
while (ans.size() < n) {
if (ans.size() + 1 == n) vis[0] = false;
boo... | 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.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
public class cf26... | 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 Round161Div2 {
public static void main(String[] args) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
n = Integer.parseInt(rd.readLine());
G = new ArrayList[n+1];
f... | 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;
int f[111111][10];
int a[111111], num[5];
bool use[111111], found;
bool getRem() {
for (int i = 3; i <= n - 1; ++i) {
int u, v;
found = false;
for (int p = 1; p <= 4; ++p) {
u = f[a[i - 1]][p];
if (use[u]) continue;
for (int q = 1; 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 | #include <bits/stdc++.h>
using namespace std;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
vector<int> e[100001];
vector<char> vis(100001, false);
int ans[100001], n;
bool sv(int a, int b) {
if (!a || !b) return true;
for (int i = 0; i < 4; i++)
if (e[a][i] == b) return true;
return false;
}
void 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> ed;
set<pair<int, int>> hv;
vector<vector<int>> g(n);
for (int i = 0; i < 2 * n; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].push_back(b);
... | 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.util.Comparator;
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.NoSuchEl... | 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;
int 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 nmax = 100005;
int x[nmax][10];
int y[nmax];
bool flag[nmax], checksum = false, checksum2 = true;
int n, cnt;
int temp1, temp2;
int i, j;
void run(int i, int j) {
memset(flag, true, sizeof(flag));
y[2] = x[1][i];
flag[y[2]] = false;
y[3] = x[1][j];
flag[... | 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<bool> mark;
int n;
vector<int> circle;
vector<vector<int>> graph;
int order[48] = {0, 1, 2, 3, 0, 1, 3, 2, 1, 0, 2, 3, 1, 0, 3, 2,
0, 2, 1, 3, 0, 2, 3, 1, 2, 0, 1, 3, 2, 0, 3, 1,
1, 2, 0, 3, 1, 2, 3, 0, 2, 1, 0, 3, 2, 1, 3, 0};
int o... | 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.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
public class CircleOfNumbers {
public static void main(String[] args) {
FasterScanner sc = new FasterScanner();
int N = sc.nextInt();
... | 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, x, y;
vector<vector<int> > adjList(100009, vector<int>());
bool vis[100009];
vector<int> ans;
bool check_valid_edges(vector<vector<int> > &a, int n) {
for (size_t i = 1; i <= n; i++)
if (a[i].size() != 4) return false;
return true;
}
int comp(int node1, int 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.*;
import java.util.*;
public class C implements Runnable {
private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
private BufferedReader in;
private PrintWriter out;
private StringTokenizer tok = new StringTokenizer("");
private void init() 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;
char connected[100005];
int countOccurance[100005];
int edges[4 * 100005][2];
int rightSibling[4 * 100005], leftChild[2 * 100005], dist[100005],
parent[100005];
void addEdge(int index) {
int u = edges[index][0];
rightSibling[index] = leftChild[u];
leftChild[u] = 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 random_long(int digit = 8) {
int len = digit;
int x = 0;
for (int i = 0; i < len; ++i) {
int dig = rand() % 10;
while (x == 0 && dig == 0) dig = rand() % 10;
x = x * 10 + dig;
}
return x;
}
int random(int l, int r) {
int diff = r - l + 1;
retur... | 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);
deque<int>* data = new deque<int>[n + 1];
for (int i = 0; i < 2 * n; i++) {
int left, right;
scanf("%d %d", &left, &right);
data[left].push_back(right);
data[right].push_back(left);
}
for (int i = 1; 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 | //package codeforces.contests.cf161;
import java.io.*;
public class ProblemC {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
int[] readInts() throws IOException {
String[] strings = reader.re... | 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 = 100100;
int head[MAXN], app[MAXN], ans[MAXN];
;
int n, a, b, num, tot;
bool ok, vis[MAXN];
void print() {
if (ok) return;
cout << "-1" << endl;
exit(0);
}
struct Edge {
int to, from;
int nxt;
} edge[4 * MAXN];
void add_edge(int from, int to) {
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;
const int inf = 0x3f3f3f3f;
const int maxn = 100005;
int ans[maxn], link[maxn][5];
bool vis[maxn];
bool mark;
int n;
bool has(int arry[], int x) {
for (int i = 1; i <= 4; i++) {
if (arry[i] == x) return true;
}
return false;
}
void dfs(int id, int cnt) {
if (cnt... | 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 | // practice with rainboy
import java.io.*;
import java.util.*;
public class CF263C extends PrintWriter {
CF263C() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF263C o = new CF263C(); o.main(); o.flush();
}
int[][] ao;
int[] qq;
boolean connected(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;
int n;
vector<int> G[1 << 20], ans;
int vis[1 << 20];
set<pair<int, int> > E;
void dfs(int u, int p) {
if (((int)ans.size()) == n) return;
ans.push_back(u);
vis[u] = 1;
for (int v : G[u])
for (int t : G[p])
if (v == t && !vis[t]) return dfs(t, u);
}
bool 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.util.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class test{
// ArrayList<Integer> lis = new ArrayList<Integer>();
// ArrayList<String> lis = new ArrayList<String>();
// PriorityQueue<Integer... | 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>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 1e5 + 5;
int n;
set<int> g[maxn];
deque<int> f(vector<int> v) {
deque<int> res;
set<int> done;
for (int x : v) {
res.push_back(x);
done.insert(x);
}
while (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;
void ERR() {
cout << "-1\n";
exit(0);
}
int N;
int a[100100][5], sol[100100], lan[100100], univ[100100];
inline bool have(int x, int y) {
for (int i = 1; i <= 4; i++) {
if (a[x][i] == y) return true;
}
return false;
}
inline int bth(int x, int y) {
int 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 n, d = 0;
int b[10], ds[100010];
vector<int> a[100010];
set<int> dd;
void nhap() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) a[i].clear();
for (int i = 1; i <= 2 * n; i++) {
int u, v;
scanf("%d%d", &u, &v);
a[u].push_back(v);
a[v].push_back(u);... | 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 <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T binPow(T p, int q, int MOD) {
if (q == 1) return p % MOD;
if (q & 1)
return p * (binPow(p, q - 1, MOD) % MOD) % MOD;
else
return sqr(binPow(p, q / 2, MOD) % MOD) % MOD;
}
const double PI = ... | 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> d[111111];
int i, n, m, v1, v2, h[111111], s[111111];
bool ok() {
int v = 0;
for (int t = 0; t < 4; t++) {
if (d[h[n]][t] == h[1]) ++v;
if (d[h[n]][t] == h[2]) ++v;
if (d[h[n - 1]][t] == h[1]) ++v;
}
if (v == 3)
return true;
else
re... | 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;
int n;
vector<int> edge[MaxN + 5];
int ind[MaxN + 5];
int ansa, ansb, ansc;
bool OK = false;
bool vis[MaxN + 5];
struct PP {
int x, p;
} ans[MaxN + 5];
void dfs(int a, int b, int c, int cnt, int x, int y, int z) {
if (OK) return;
if (cnt > n) 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 n;
vector<int> adj[100010];
vector<int> ans;
bool d = 0;
bool v[100010];
void solve(int node, int par) {
if ((ans.size()) == n) {
if (count(adj[par].begin(), adj[par].end(), 1)) d = 1;
return;
}
for (int i = 0; i < 4; ++i) {
int child = adj[node][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 N = 2e5 + 100;
int n;
int que[N][4], f[N];
int con[N][2], fcon[N];
struct node {
int x;
int y;
} edge[N], prove[N];
int pro = 0;
int ans[N], ansf = 0;
bool operator<(node a, node b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
void add(int x, 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 | #include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
vector<int> G[N], vt[N], pr;
int cnt[11], num[11], n, vis[N];
bool is_adj(int u, int v) {
for (int i = 0; i < G[u].size(); i++)
if (G[u][i] == v) return true;
return false;
}
bool check(int u) {
if (G[u].size() != 4) return false;
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 | 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.*;
// Circle of Numbers
// 2013/01/17
public class P263C{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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 | import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.Collection;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException... | 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.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
// Circle of Numbers
// 2013/01/17
public class C{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
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 | #include <bits/stdc++.h>
using namespace std;
set<int> m[100001];
vector<int> adj[100001];
int res[100001], vis[100001], rp;
int main() {
int n, a, b, now = 1, last = -1;
scanf("%d", &n);
int tv = n;
for (int i = 0; i < 2 * n; ++i) {
scanf("%d%d", &a, &b);
m[a].insert(b);
m[b].insert(a);
}
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;
const int N = 100100;
int n, n1, n2, nr, x[N];
vector<int> v[N];
bool ver[N];
bool sol() {
int i, j;
for (i = 1; i <= n; ++i) ver[i] = 0;
ver[n1] = 1;
ver[n2] = 1;
nr = 0;
x[++nr] = 1;
x[++nr] = n1;
int vvv = 0;
while (n2 != 1 && !vvv) {
if (n2 == x[nr... | 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> node[100001];
int n;
vector<int> ans;
bool solve(int grand, int parent, int now) {
ans.push_back(now);
int sum = 0;
bool foundpre = false;
int real = 0;
for (int i = 0; i < 4; i++) {
int next = node[parent][i];
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;
int a[1000000], b[1000000];
vector<vector<int> > adjlist;
int main() {
int n;
cin >> n;
adjlist.assign(n + 1, vector<int>());
map<int, int> mp;
for (int i = 0; i < 2 * n; i++) {
cin >> a[i] >> b[i];
adjlist[a[i]].push_back(b[i]);
adjlist[b[i]].push_bac... | 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<vector<int> > g;
vector<bool> us;
vector<int> ans, cnt;
int n, n2;
bool con(int a, int b) {
for (int& i : g[a])
if (i == b) return true;
return false;
}
bool build(int i) {
if (i == n) {
return (con(ans[n - 2], 1) && con(ans[n - 1], 1) &&
co... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.