output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; const int N = 2020; namespace Gause { static const int N = ::N; int equ, var; bitset<N> a[N]; int x[N]; int free_x[N]; int free_num; int l[N]; void ini(int n) { for (int i = (0); i < (n); ++i) x[i] = 0; for (int i = (0); i < (n); ++i) a[i].reset(); } int Gauss() { int...
### Prompt Please formulate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; bitset<2020> a[2020]; int n; void gauss() { for (int i = 1; i <= n; i++) { int j = i; while (!a[j][i] && j <= n) j++; if (j <= n && j != i) swap(a[i], a[j]); for (int j = 1; j <= n; j++) if (i != j && a[j][i]) a[j] ^= a[i]; } } int t, m, i, x, y; i...
### Prompt Please provide a CPP coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 2000; const int MAXM = 10000; const int MAXROWS = MAXN; const int MAXCOLS = MAXN + 1; const int MAXWORDS = (MAXCOLS + 63) / 64; struct BinaryGaussJord { int R, C, W; unsigned...
### Prompt Create a solution in Cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int N = 2005; struct graph { vector<int> deg; bitset<N> con[N]; int n; graph(int n) : n(n) {} void add_edge(int a, int b) { con[a][b] = con[b][a] = 1; } pair<set<int>, set<int>> partition() { set<int> A, B; for (int i = 1; i <= n; i++) A.insert(i);...
### Prompt Develop a solution in CPP to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" using namespace std; const int N = 2002; const int INF = (int)1e9 + 41; const long long MD = (long long)1e9 + 7; bool D = false; bool u[N][N]; bool isDed[N]; int deg[N]; int col[N]; int n; void go() { int v = -1; for (int i = 0; i < n; i++) {...
### Prompt Please provide a cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; bitset<N> A[N]; int n, m; int ans[N], deg[N]; void init() { for (int i = 0; i < n; ++i) { for (int j = 0; j <= n; ++j) A[i].reset(j); } } void print() { for (int i = 0; i < n; ++i) { for (int j = 0; j <= n; ++j) if (A[i][j]) ...
### Prompt Create a solution in cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; int n, m; int d[2010]; bitset<2010> bt[2010]; void init() { memset(d, 0, sizeof(d)); for (int i = 0; i < n; ++i) { bt[i].reset(); } } void guss() { for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { if (bt[j][i]) { swap(bt[j], bt[i]); ...
### Prompt Your challenge is to write a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int ans[N], deg[N]; bitset<2010> mat[N]; int main(void) { int t; cin >> t; while (t--) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { mat[i].reset(); ans[i] = 0; deg[i] = 0; } for (int i = 0;...
### Prompt Generate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; int N, M; bitset<2020> mat[2020]; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d%d", &N, &M); vector<pair<int, int> > E; int deg[2020] = {}; for (int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); deg[x]++; ...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2001; void solve_test(istream &cin = std::cin, ostream &cout = std::cout) { int n, m; cin >> n >> m; vector<bitset<N>> g(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; g[u][v] = g[v][u] = 1; ...
### Prompt In Cpp, your task is to solve the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in suc...
#include <bits/stdc++.h> using namespace std; int n, m; const int maxN = 2005; vector<int> g[maxN]; int deg[maxN]; struct myBitset { vector<unsigned long long> v; myBitset(int n) { v.resize(n / 64 + 1); } inline bool operator[](int q) const { int pos = q >> 6, val = q & 63; return (v[pos] >> val) & 1; }...
### Prompt In CPP, your task is to solve the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in suc...
#include <bits/stdc++.h> using namespace std; unsigned long long eq[2000][32]; bool res[2000]; int pos[2000]; int ans[2000]; bool vis[2000]; int n, m; void solve() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j <= ((n - 1) >> 6); j++) { eq[i][j] = 0; } res[i] = vis[i] = 0; } ...
### Prompt Your task is to create a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r st...
#include <bits/stdc++.h> #pragma GCC optimize "-O3" using ll = long long; using ld = long double; using ull = uint64_t; using namespace std; int n, m; bitset<2010> ed[2010]; int go[2010]; int cl[2010]; void solve() { cin >> n >> m; for (int i = 0; i < n; ++i) ed[i].reset(); for (int i = 0; i < m; ++i) { int a...
### Prompt Create a solution in CPP for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 5; int N, M; bitset<MAXN> mat[MAXN]; int deg[MAXN]; void load() { scanf("%d%d", &N, &M); for (int i = 0; i < N; i++) mat[i].reset(); while (M--) { int x, y; scanf("%d%d", &x, &y); x--; y--; mat[x].set(y); mat[y].set(x); ...
### Prompt Develop a solution in cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int n, m; vector<int> gph[MAXN]; bitset<MAXN> bs[MAXN]; int col[MAXN], active[MAXN]; void upload(bitset<MAXN> v, int c) { for (int i = 0; i < n; i++) { if (v[i]) { if (!active[i]) { active[i] = 1; col[i] = c; bs[i] ...
### Prompt Develop a solution in CPP to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int n; vector<int> e[2022]; int res[2022]; bitset<2001> a[2022]; int main() { int _, m; for (scanf("%d", &_); _--;) { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) e[i].clear(); while (m--) { int x, y; scanf("%d%d", &x, &y); --x; ...
### Prompt Create a solution in cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int N = 2005; int t, n, m, u, v, cnt, ans[N]; bitset<N> bit[N]; int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); cnt = 0; for (int i = 1; i <= n; i++) { ans[i] = 0; bit[i].reset(); } while (m--) { scanf("%d%d...
### Prompt Generate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int t, n, m, u, v; vector<int> G[N]; bitset<N> b[N]; void gauss() { for (int i = 1; i <= n; i++) { int p = 0; for (int j = i; j <= n; j++) { if (b[j][i]) { p = j; break; } } if (!p) continue; swap(b[i], b...
### Prompt Generate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; int n, m; vector<bitset<2010> > a; vector<int> g[2010]; int an[2010]; void gauss() { int row = 0; int mx = n; for (int i = 0; i < n && row < n; i++) { bool ok = false; for (int j = row; j < n; j++) { if (a[j].test(i)) { swap(a[row], a[j]); ...
### Prompt Please create a solution in CPP to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-9; const long double pi = acos(-1); const int oo = 1 << 30; const long long...
### Prompt Create a solution in cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int MN = 2010; int N, M; vector<int> adj[MN]; bitset<MN> A[MN], B[MN]; int ans[MN]; void gauss() { for (int i = 0; i < N; i++) { B[i].reset(); B[i][i] = 1; } for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { if (A[j][i]) { swa...
### Prompt Please formulate a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10; bitset<N> a[N]; int n, m, deg[N]; void gauss() { for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { if (a[j][i]) { if (i ^ j) { swap(a[i], a[j]); } break; } } for (int j = 1; j <=...
### Prompt Develop a solution in Cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> const int MAXN = 2000 + 10; int n, m; std::bitset<MAXN> g[MAXN]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { g[i].reset(); } static int deg[MAXN]; memset(deg, 0, sizeof deg); for (int i = 1; i <= m;...
### Prompt Construct a cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 5; int r[maxn], ans[maxn]; vector<int> g[maxn]; bitset<maxn> b[maxn]; int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) g[i].clear(); for (int i = 0; i < m; ++i) { ...
### Prompt Generate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; bitset<2021> a[2021]; int n, T, m, d[2021]; int main() { ios::sync_with_stdio(false); cin >> T; while (T--) { cin >> n >> m; for (int i = 1; i <= n; i++) { a[i].reset(); d[i] = 0; } for (int x, y, i = 1; i <= m; i++) { cin >> x >> y; ...
### Prompt Construct a cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int MX = 2005; int n, m, a[10005], b[10005], cn[MX], res[MX]; bitset<MX> bs[MX]; void solve() { cin >> n >> m; for (int i = 0; i < (n); i++) bs[i].reset(), cn[i] = 0, res[i] = 0; for (int i = 0; i < (m); i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; cn...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, m; bitset<N> bi[N], sta[N], tar, tag[N], ans; void ins(bitset<N> a, int id) { bitset<N> rec; rec[id] = true; for (int i = (1); i <= (n); ++i) if (a[i]) { if (bi[i].none()) { bi[i] = a, tag[i] = rec; break; } e...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 2); template <class c> char dud(...); struct debug { template <class c> ...
### Prompt Please provide a CPP coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; int read() { int X = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar(); return X * w; } const int N = 2000 + 10; const int mod = 998244353; i...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int INF_of_int = 1e9; const long long INF_of_ll = 1e18; template <typename T> void Read(T &x) { bool w = 1; x = 0; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') w = 0, c = getchar(); while (isdigit(c)) { x = (x << 1) ...
### Prompt Please create a solution in CPP to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int N = 2002; const int INF = (int)1e9 + 41; const long long MD = (long long)1e9 + 7; bool D = false; bool u[N][N]; bool isDed[N]; int deg[N]; int col[N]; int n; void solve1() { int v = -1; for (int i = 0; i < n; i++) { if (!isDed[i] && deg[i] % 2 == 1 && v ==...
### Prompt Your challenge is to write a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; vector<int> voisins[2000]; int main() { ios_base::sync_with_stdio(false); int nbTests; cin >> nbTests; for (int iTest = 0; iTest < nbTests; iTest++) { int nbVilles, nbRoutes; cin >> nbVilles >> nbRoutes; vector<bitset<2001>> lignes(nbVilles, 0); for ...
### Prompt Create a solution in CPP for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; bitset<2000> A[2000]; bitset<2000> id[2000]; vector<int> G[2000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a ...
### Prompt Your challenge is to write a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> #pragma GCC optimize "-O3" using namespace std; const int N = 2e3 + 1; void solve() { bitset<N> E[N]; int n, m, c[N]; cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = 0; j <= n; ++j) E[i][j] = 0; c[i] = -1; } while (m--) { int x, y; cin >> x >> y; --x; ...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long large = 2000000000000000000LL; int main() { int testcase; cin >> testcase; while (testcase--) { int n, m; cin >> n >> m; vector<vector<int> > adj(n, vector<int>()); vector<int> deg(n, 0); for (int i = 0; i < m;...
### Prompt Create a solution in Cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> unsigned int a[2001][64], t; int n, d[2001], T, m, x, y; int main() { scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 0; j < 64; j++) a[i][j] = 0; d[i] = 0; } for (int i = 1; i <= m; i++) { scanf("%d%d", &x,...
### Prompt Your challenge is to write a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int MX = 2005; int n, m, ans[MX], h[MX]; bitset<MX> A[MX]; vector<int> G[MX]; bool ck1() { for (int i = 1; i <= n; i++) if (G[i].size() & 1) return false; return true; } void solve() { int it = 1; for (int i = 1; i <= n; i++) { int j; for (j = it; ...
### Prompt Please formulate a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int N = 2005; struct graph { vector<int> deg; bitset<N> con[N]; int n; graph(int n) : n(n) {} void add_edge(int a, int b) { con[a][b] = con[b][a] = 1; } pair<set<int>, set<int>> partition() { set<int> A, B; for (int i = 1; i <= n; i++) A.insert(i);...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; int const INF = (int)1e9 + 1e3; long long const INFL = (long long)1e18 + 1e6; mt19937 tw(9450189); uniform_int_distribution<long long> ll_distr; long long rnd(long long a, long long b) { return ll_distr(tw) % (b - a + 1) + a; } void setbit(vector<unsigned long long>& arr,...
### Prompt Please create a solution in cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int tt, n, m; bitset<2050> a[2050]; int c[2050], ans[2050], id[2050]; int main() { scanf("%d", &tt); while (tt--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) a[i].reset(), c[i] = ans[i] = id[i] = 0; for (int i = 1; i <= m; i++) { int x, y; ...
### Prompt Your challenge is to write a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; int n, m, bo[100000], ans; bitset<2005> a[2005]; void gauss() { for (int i = 1; i <= n; i++) { int p = i; while (p <= n && (!a[p][i])) ++p; if (p <= n) swap(a[p], a[i]); for (int j = 1; j <= n; j++) if (i != j && a[j][i]) a[j] ^= a[i]; } } int main...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return f ? -a : a; } const int MAXN = 2010; ...
### Prompt Create a solution in CPP for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; int a[2005][2005], b[2005]; int n, m; bool kec(basic_string<int> v) { for (int i : v) { int z = 0; for (int j : v) z += a[i][j]; if (z & 1) return false; } return true; } void solve(basic_string<int> v) { if (kec(v)) { for (int i : v) b[i] = 1; r...
### Prompt Please create a solution in CPP to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int n, m, du[2100]; bool check() { for (int i = 1; i <= n; i++) if (du[i] % 2 == 1) return false; printf("1\n"); for (int i = 1; i < n; i++) printf("1 "); printf("1\n"); return true; } bitset<2100> s[2100]; void gauss() { int x = 1; for (int j = 1; j <= n;...
### Prompt Your challenge is to write a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 2002; using bit = bitset<MAX + 1>; bit basis[MAX]; bit solve[MAX]; int id[MAX]; int rk, n; void insert(bit mask, int line = -1) { if (line == -1) line = rk; bit cur; cur[rk] = 1; ...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2003; int n, m; bitset<MAXN> a[MAXN]; int b[MAXN]; int f[MAXN]; vector<int> e[MAXN]; void run() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) a[i] = 0, e[i].clear(); for (int i = 0; i < m; ++i) { int x, y; scanf("%d%d", &x, &y); --x...
### Prompt Create a solution in Cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; bool con[2000][2000]; bool c[2200]; int main() { ios::sync_with_stdio(0); int ncase, casen = 0; for (cin >> ncase; ncase--;) { int n, m; cin >> n >> m; bitset<2000> a[2200]; for (int i = 0; i < n; i++) a[i].reset(); bitset<2000> c; for (int i =...
### Prompt Please formulate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getchar(); bool positive...
### Prompt Create a solution in Cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int sz = 2e3 + 10; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, m; cin >> n >> m; bitset<sz> ma[n]; int ch[n], an[n]; for (int a = 0; a < n; a++) ch[a] = 0, an[a] = 0; for (int a = 0; a < m; a++) { int u, v; ...
### Prompt Your task is to create a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r st...
#include <bits/stdc++.h> using namespace std; int get() { char ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; if (ch == '-') { int s = 0; while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return -s; } int s = ch - '0'; while (ch = getchar(), ch >= '0' &...
### Prompt Please create a solution in CPP to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int input() { int x = 0, f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |= ch == '0', ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x; } int n, m, du[2100]; bool Check() { for (int i = 1; i <= n...
### Prompt Please formulate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x * f; } void write(long long x) { if (x < 0) put...
### Prompt Develop a solution in Cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int T, N, M; vector<int> connections[2001]; bool ind[2001]; int sol[2001]; int main() { scanf("%d", &T); for (int t = 0; t < T; t++) { scanf("%d %d", &N, &M); vector<bitset<2001> > bitSets(N + 1); for (int i = 1; i <= N; i++) { connections[i].clear(); ...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long oo = 1e18; const int N = 10010; int n, m, t, ans[N]; vector<bitset<N> > all; vector<int> g[N]; void guass(bitset<N> bt) { int j = 0; for (int i = 0; i < all.size(); ++i) { while (all[i][j] == 0 && bt[j] == 0) j++; if (...
### Prompt Please provide a cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; bitset<2010> b[2010]; int d[2010]; int main() { int t, n, m; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) b[i].reset(); memset(d, 0, sizeof d); for (int i = 1, x, y; i <= m; i++) { scanf("%d%d", &x, &y); ...
### Prompt Please provide a Cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(b...
### Prompt Please provide a cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int N = 2333; int n, m; bool deg[N]; bitset<N> eq[N]; void Reverse(bitset<N> &bs, int bit) { if (bs.test(bit)) bs.reset(bit); else bs.set(bit); } void Init() { scanf("%d%d", &n, &m); memset(deg, 0, sizeof deg); for (int i = 0; i < n; i++) eq[i].reset...
### Prompt Please provide a CPP coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int N = 2007; int n, m; bool res[N]; bitset<N> edge[N]; void solve() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) for (int j = 0; j < N; ++j) edge[i][j] = false; for (int i = 1; i <= m; ++i) { int u, v; scanf("%d %d", &u, &v); edge[u][v...
### Prompt Develop a solution in CPP to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2010; int t, n, m, x, y, deg[MAXN], ans[MAXN]; bitset<MAXN> b[MAXN]; int main() { scanf("%d", &t); for (int ii = 1; ii <= t; ii++) { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { deg[i] = ans[i] = 0, b[i].reset(); } for (in...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 2; const int M = 1e4 + 2; int x[M], y[M], cnt[N], ans[N]; bitset<N> bs[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, i, j, k, l, t; cin >> t; while (t--) { cin >> n >> m; for (i = 0; i < n; i++) { cnt[i] = ans...
### Prompt Generate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; int T, N, M; int main() { scanf("%d", &T); for (; T--;) { scanf("%d%d", &N, &M); vector<vector<int> > G(N); for (int i = 0; i < M; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; G[u].push_back(v); G[v].push_back(u); } ...
### Prompt Please formulate a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int max_N = 2e3 + 10; bitset<max_N> E[max_N]; bitset<max_N> inv[max_N]; int sto[max_N]; pair<vector<int>, vector<int> > solve(vector<int> rem, int d); int N; int main() { int T; cin >> T; while (T--) { int M; cin >> N >> M; for (int i = 1; i <= N; ++...
### Prompt Your challenge is to write a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 2005; bitset<MAX> basis[MAX]; bitset<MAX> solve[MAX]; int rk, n; void insert(bitset<MAX> mask, int line) { bitset<MAX> cur; cur[line] = 1; for (int i = n - 1; i >= 0; i--) if ((...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000 + 10; int T, N, M; bitset<MAXN> a[MAXN]; int d[MAXN]; inline void Gauss() { register int i, j; for (i = 1; i <= N; ++i) { j = i; while (!a[j][i] && j <= N) ++j; if (j <= N && j != i) swap(a[i], a[j]); for (j = 1; j <= N; ++j) ...
### Prompt Generate a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 5; int r[maxn], ans[maxn]; vector<int> g[maxn]; bitset<maxn> b[maxn]; int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) g[i].clear(); for (int i = 0; i < m; ++i) { ...
### Prompt Please create a solution in cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; struct bs { int size; vector<bitset<100> > data; const int block_size = 100; bs(int size) : size(size) { data.assign((size + block_size - 1) / block_size, 0); } bool test(int pos) const { return data[pos / block_size].test(pos % block_size); } void s...
### Prompt Your challenge is to write a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 2007; int n, m; vector<int> es[MAXN]; bitset<MAXN> bs[MAXN]; bool hv[MAXN]; int dp[MAXN]; void init(); void input...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; int N, M, ans[2018], deg[2018], specialC[2018]; bitset<2018> gs[2018]; vector<int> v[2018]; int main() { int tests; scanf("%d", &tests); while (tests--) { for (int i = 1; i <= N; i++) deg[i] = 0; for (int i = 1; i <= N; i++) v[i].clear(); scanf("%d %d", &N...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 2002; using bit = bitset<MAX + 1>; bit basis[MAX]; bit solve[MAX]; int id[MAX]; int rk, n; void insert(bit mask, int line = -1) { bit cur; if (line != -1) cur[rk] = 1; for (int i = ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m; bitset<N> S[N]; vector<int> e[N]; void solve() { scanf("%d%d", &n, &m); for (int i = (int)(1); i <= (int)(n); i++) e[i].resize(0); for (int i = (int)(1); i <= (int)(m); i++) { int x, y; scanf("%d%d", &x, &y); e[x].push_back(y)...
### Prompt Please provide a Cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 5; int r[maxn], ans[maxn]; vector<int> g[maxn]; bitset<maxn> b[maxn]; int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) g[i].clear(); for (int i = 0; i < m; ++i) { ...
### Prompt Please create a solution in CPP to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const long long INF = 1e18L + 7; template <class n, class second> ostream &operator<<(ostream &p, pair<n, second> x) { return p << "<" << x.first << ", " << x.second << ">"; } template <class n> auto operator<<(ostream &p, n y) -> typename ena...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") using namespace std; const int N = 2020; namespace Gause { static const int N = ::N; int equ, var; bitset<N> a[N]; int x[N]; int free_x[N]; int free_num; int l[N]; void ini(int n) { for (int i = (0);...
### Prompt Construct a cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; inline int read() { int a = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { a = (a << 3) + (a << 1) + (c ^ '0'); c = getchar(); } return f ? -a : a; } const int MAXN = 2010; ...
### Prompt Construct a CPP code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; bitset<2001> v[2000]; vector<bitset<2001> > g; int main() { int t; scanf("%d", &t); while (t--) { int n, e; scanf("%d%d", &n, &e); for (int i = 0; i < n; ++i) for (int j = 0; j <= n; ++j) v[i].reset(j); for (int i = 0, a, b; i < e; ++i) { s...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 2005; bitset<MAX> basis[MAX]; bitset<MAX> solve[MAX]; int rk, n; void insert(bitset<MAX> mask, int line) { bitset<MAX> cur; cur[line] = 1; for (int i = n - 1; i >= 0; i--) if ((...
### Prompt Construct a Cpp code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; int id[2200]; int main() { ios::sync_with_stdio(0); int ncase, casen = 0; for (cin >> ncase; ncase--;) { int n, m; cin >> n >> m; bitset<2000> a[2200]; for (int i = 0; i < n; i++) a[i].reset(); bitset<2000> c; for (int i = 0; i < m; i++) { ...
### Prompt Develop a solution in Cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int t, n, m; bitset<2005> a[2005]; int read() { int x = 0, fl = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fl = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); ...
### Prompt Construct a CPP code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int a[maxn][maxn]; int col[maxn]; int deg[maxn]; bool vis[maxn]; int n; void recurse() { int piv = -1; for (int i = 1; i <= n; i++) { if (vis[i]) continue; if (deg[i] % 2 == 1) { piv = i; break; } } if (piv == -1) { ...
### Prompt Your task is to create a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r st...
#include <bits/stdc++.h> using namespace std; const int N = 2001; int n, m, ans[N]; bitset<2002> temp; vector<int> g[N]; vector<bitset<2002>> v; void fix(int u) { temp = 0; for (auto i : g[u]) temp[i] = 1; if (g[u].size() & 1) temp[u] = temp[n] = 1; } void add() { int at = 0; for (int i = 0; i < v.size(); i++...
### Prompt Generate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> int T, a, b, i, j, x, y; int main() { scanf("%d", &T); while (T--) { std::bitset<2020> A[2020]; std::vector<int> G[2020]; int ans[2020] = {}; int bit[2020] = {}; scanf("%d%d", &a, &b); for (i = 0; i < b; i++) { scanf("%d%d", &x, &y); G[x].push_back(y); ...
### Prompt Your challenge is to write a cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") template <class T> void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> void chkmin(T &a, T b) { if (a > b) a = b; } const double pi = 3.1415926535897932384626433832795028841971l; int t, n, m; bitset<202...
### Prompt Construct a CPP code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; int n, m, bo[100000], ans; bitset<2005> a[2005]; void gauss() { for (int i = 1; i <= n; i++) { int p = i; while (p <= n && (!a[p][i])) ++p; if (p <= n) swap(a[p], a[i]); for (int j = 1; j <= n; j++) if (i != j && a[j][i]) a[j] ^= a[i]; } } int main...
### Prompt Your challenge is to write a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; int n, m, T, deg[2010], b[2010]; bitset<2010> flag[2010], a[2010]; void solve() { scanf("%d%d", &n, &m); fill(deg + 1, deg + n + 1, 0); fill(b + 1, b + n + 1, 0); for (int i = 1; i <= n; i++) flag[i].reset(), a[i].reset(); for (int i = 1, ti, tj; i <= m; i++) { ...
### Prompt Generate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such a...
#include <bits/stdc++.h> void work(void) { int n, m; scanf("%d%d", &n, &m); constexpr int N(2005); static std::bitset<N> a[N]; for (int i(1); i <= n; ++i) a[i].reset(); for (int i(0), x, y; i < m; ++i) { scanf("%d%d", &x, &y); a[x][x].flip(), a[x][y].flip(), a[x][0].flip(); a[y][x].flip(), a[y][...
### Prompt Create a solution in cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m, ans[N], h[N]; bitset<N> a[N]; vector<int> e[N]; bool check1() { for (int i = (int)(1); i <= (int)(n); i++) if (e[i].size() & 1) return 0; return 1; } void gauss() { int it = 1; for (int i = (int)(1); i <= (int)(n); i++) { int j ...
### Prompt Please provide a Cpp coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; const int NN = 2000; bitset<NN> a[NN], f; int b[NN], d[NN]; int main() { int T, n, m, k; scanf("%d", &T); while (T--) { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) a[i].reset(), d[i] = 0; f.reset(); for (int u, v; m--;) { scanf("%d %d", &...
### Prompt Please formulate a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2001; using bs = bitset<N>; vector<int> work(vector<bs> mat) { const int n = (int)mat.size(); vector<int> x(n, -1); int cur = 0; for (int i = 0; i < n; i++) { int where = -1; for (int j = cur; j < n; j++) { if (mat[j...
### Prompt Develop a solution in Cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast", "inline") using namespace std; const long long mo = (long long)1e9 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } bitset<2100> gauss[2100]; int ans[2100]; void work() { int n, m; cin >> n >> m; int x, y; for (int i = ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> using namespace std; bitset<2005> a[2005]; int n, m, i, j, deg[2005], t, ans[2005], z[2005]; int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) { a[i].reset(); deg[i] = 0; } for (i = 1; i <= m; i++) { int x, y; ...
### Prompt In Cpp, your task is to solve the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in suc...
#include <bits/stdc++.h> using namespace std; const signed long long llf = (signed long long)(~0ull >> 1); const signed int inf = (signed)(~0u >> 1); template <typename T> T __abs(T x) { return (x < 0) ? (-x) : (x); } template <typename T> void pfill(T* pst, const T* ped, T val) { for (; pst != ped; *(pst++) = val)...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; int n; int value[MAXN]; bitset<MAXN> adj[MAXN]; pair<vector<int>, vector<int>> solve(vector<int> graph) { int u = -1; for (int v : graph) { if (adj[v].count() & 1) { u = v; break; } } if (u == -1) { return {graph, {}}; ...
### Prompt Please create a solution in Cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> void work(void) { int n, m; scanf("%d%d", &n, &m); constexpr int N(2005); static std::bitset<N> a[N]; for (int i(1); i <= n; ++i) a[i].reset(); for (int i(0), x, y; i < m; ++i) { scanf("%d%d", &x, &y); a[x][x].flip(), a[x][y].flip(), a[x][0].flip(); a[y][x].flip(), a[y][...
### Prompt Develop a solution in cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d %d", &n, &m); vector<vector<int> > g(n); while (m--) { int x, y; scanf("%d %d", &x, &y); x--, y--; g[x].push_back(y); g[y].push_back(x); } bool...
### Prompt Construct a CPP code solution to the problem outlined: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in s...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << "["; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; counter--; r...
### Prompt Please provide a CPP coded solution to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into ...
#include <bits/stdc++.h> template <typename Y> inline bool updmin(Y &a, Y b) { if (a > b) { a = b; return 1; } return 0; } template <typename Y> inline bool updmax(Y &a, Y b) { if (a < b) { a = b; return 1; } return 0; } template <typename Y> inline Y abs(Y a) { if (a < 0) a = -a; return...
### Prompt Please create a solution in cpp to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; using LL = long long; void err() { cout << "" << endl; } template <template <typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x : a) cout << x << ' '; err(args...); } template <typename T, typename... Args> void err(T a, Arg...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; const int VARS = 2005; void gauss_jordan_z2(vector<bitset<VARS>>& M) { for (int i = 0, j = 0; i < M.size() && j < VARS; j++) { int idx = -1; for (int k = i; k <= M.size() - 1; k++) { if (M[k][j]) { idx = k; break; } } if (idx ==...
### Prompt Create a solution in Cpp for the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states in such...
#include <bits/stdc++.h> using namespace std; struct bs { vector<uint64_t> a; size_t sz; bs() {} bs(size_t sz) : sz(sz), a((sz + 63) >> 6) {} bool operator[](size_t i) const { return (a[i >> 6] >> (63 - (i & 63))) & 1; } bool operator>(const bs& rhs) const { return a > rhs.a; } void set(size_t i) { a[i >>...
### Prompt Please formulate a CPP solution to the following problem: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...
#include <bits/stdc++.h> using namespace std; bitset<2010> a[2010]; bool x[2010]; int n, m, d[2010]; void gaosi(int n) { for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) if (a[j][i] == 1) { swap(a[j], a[i]); break; } if (!a[i][i]) continue; for (int j = i + 1; j <= n...
### Prompt Develop a solution in Cpp to the problem described below: Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them. The president of Berland decided to split country into r states i...