output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, bool>> g[2005];
int a = 0, cnt = 0;
bool vs[2004];
vector<set<int>> h;
void dfs(int u, set<int> &s) {
vs[u] = 1;
s.insert(u);
for (pair<int, bool> v : g[u]) {
if (v.second == 1) {
if (!vs[v.first]) {
dfs(v.first, s);
}
}
... | ### Prompt
Please formulate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
const int tope = 2005;
using namespace std;
int visitados[tope];
int amigos[tope][tope];
int membersComp[tope];
int sizeComp[tope];
int n;
int dfs(int inicio, int nroComp) {
stack<int> s;
s.push(inicio);
int cant = 0;
while (s.empty() == false) {
int top = s.top();
s.pop();
... | ### Prompt
Construct a CPP code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
bool no[2001][2002];
bool vis[2003];
vector<int> vc[2004], tt;
void dfs(int u) {
tt.push_back(u);
vis[u] = 1;
for (int i = 0; i < vc[u].size(); i++) {
int v = vc[u][i];
if (!vis[v]) dfs(v);
}
}
int main() {
int n, m1, m2, u, v;
cin >> n;
cin >> m1;
w... | ### Prompt
Please provide a CPP coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 10, big = 1e18, mod = 1e9 + 7;
vector<long long> a[N], now, ans;
long long n, x, y, m, maxi;
bool vis[N], mp[N][N];
void dfs(long long i) {
vis[i] = 1, now.push_back(i);
for (int j = 0; j < a[i].size(); j++)
if (!vis[a[i][j]]) dfs(a[i][j]);... | ### Prompt
Your task is to create a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<int> adj[(int)3000], vis((int)3000, 0), vis2(3000, 0);
vector<pair<int, int>> p;
void dfs(int i) {
if (vis[i]) return;
vis[i] = 1;
vis2[i] = 1;
for (auto x : adj[i]) {
dfs(x);
}
}
void solve() {
cin >> n >> k;
for (int i = 0; i < k; i++... | ### Prompt
Please formulate a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
vector<int> P(N), R(N), S(N);
int find(int x) {
if (x == P[x]) return x;
return P[x] = find(P[x]);
}
void join(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
if (R[a] > R[b]) {
P[b] = a;
S[a] += S[b];
} els... | ### Prompt
Generate a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int n, t;
struct point {
int x, y;
point() {}
point(int x, int y) : x(x), y(y) {}
bool operator<(const point& a) const {
if (x < a.x) return 1;
if (x == a.x && y < a.y) return 1;
return 0;
}
};
int gcd(int a, int b) {
if (b == 0) return a;
return g... | ### Prompt
Generate a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p[2001], t1, t2, t3, f[2001], s[2001];
int findd(int x1) {
if (p[x1] == x1) return x1;
return p[x1] = findd(p[x1]);
}
int unionn(int x1, int x2) {
if (findd(x1) != findd(x2)) p[findd(x1)] = findd(x2);
}
int main() {
cin >> n;
cin >> m;
for (int i = 1; ... | ### Prompt
Please provide a cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
long long po(long long a, long long b) {
if (b == 0) return 1;
long long ans = 1;
if (b % 2 == 0) {
ans = po(a, b / 2) % 1000000007;
ans = (ans % 1000000007 * ans % 1000000007) % 1000000007;
} else {
ans = po(a, (b - 1) / 2) % 1000000007;
ans = (ans ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int maxx = 0;
vector<int> vf[3000];
vector<int> ve[3000];
stack<int> st;
int known[3000] = {0};
int curr[3000] = {0};
int fl = 1;
void dfs(int i) {
known[i] = 1;
curr[i] = 1;
st.push(i);
maxx++;
int k;
for (k = 0; k < ve[i].size(); k++) {
if (curr[ve[i][k]] ... | ### Prompt
Your task is to create a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1},
ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
long long gcd(long long a, long long b) {
if (!a) return b;
return gcd(b % a, a);
}
long long lcm(long long a, long lo... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int l = 0;
bool yes = true;
set<int> dislike;
void dfs(vector<int> graph[], vector<int> enemy[], bool visited[], bool vi[],
int node) {
visited[node] = true;
vi[node] = true;
l++;
for (auto itr : enemy[node]) {
dislike.insert(itr);
}
for (auto itr :... | ### Prompt
Generate a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, tot, flag, vis[2005];
vector<int> like[2005], dislike[2005];
void dfs(int now, int op) {
vis[now] = op;
tot++;
for (auto to : like[now])
if (!vis[to]) dfs(to, op);
for (auto to : dislike[now])
if (vis[to] == vis[now]) flag = 0;
}
int main() {
... | ### Prompt
Construct a CPP code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
class DisjointSet {
public:
long long int n;
vector<pair<long long int, long long int>> parent;
vector<long long int> rank;
DisjointSet() {
n = 0;
parent = vector<pair<long long int, long long int>>(0);
rank = vector<long long int>(0);
}
DisjointSet... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
long n, m, k, ans, sz[200000], arp[200000], calc, bd[200000];
long q, a, b;
vector<long> g[200000];
void dfs(long v) {
arp[v] = calc;
sz[calc]++;
for (int i = 1; i <= g[v].size(); i++) {
long q = g[v][i - 1];
if (arp[q] == 0) dfs(q);
}
}
int main() {
ios_b... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5;
const long long INF = 1e15;
const long long MOD = 1000000007;
int n, m, k, t;
int f[N], f1[N], a[N];
vector<int> v[N];
void dfs(int u, int x) {
f[u] = x;
t++;
int l = v[u].size();
for (int i = 0; i < l; i++)
if (!f[v[u][i]]) dfs(v[u][i],... | ### Prompt
Construct a cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
int dfs(vector<vector<pair<int, bool> > >& Graph, vector<int>& visited,
vector<bool>& is_enemy, int root, int idx, bool& is_valid) {
if (is_enemy[root]) is_valid = false;
visited[root] = idx;
int count = 1;
for (auto a : Graph[root])
if (!a.second && vis... | ### Prompt
Construct a Cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
inline int rdi() {
int d;
scanf("%d", &d);
return d;
}
inline char rdc() {
scanf(" ");
return getchar();
}
inline string rds() {
string s;
cin >> s;
return s;
}
inline double rddb() {
double d;
scanf("%lf", &d);
return d;
}
template <class T>
inline bo... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
struct UFDS {
int n;
int p[2010], rank[2010], size[2010];
UFDS(int n) : n(n) {
for (int i = 1; i <= n; i++) {
p[i] = i;
rank[i] = 0;
size[i] = 1;
}
}
int findSet(int i) {
if (p[i] == i) return i;
return p[i] = findSet(p[i]);
}
... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
const int MAXX = 2500;
vector<int> G[MAXX];
set<int> D[MAXX];
int color[MAXX];
void DFS(int v, list<int> &A) {
if (color[v]) return;
color[v] = 1;
A.push_back(v);
for (__typeof((G[v]).begin()) a = (G[v]).begin(); a != (G[v]).end(); a++)
DFS(*a, A);
}
int goDFS(i... | ### Prompt
Develop a solution in Cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, u, v;
int p[2048];
void init() {
for (int i = 0; i < 2048; i++) {
p[i] = i;
}
}
int find(int x) { return p[x] == x ? x : find(p[x]); }
void merge(int u, int v) {
if (find(u) == find(v)) {
return;
}
p[find(u)] = find(v);
}
int main() {
cin >>... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<vector<int> > G;
vector<pair<int, vector<int> > > F;
vector<char> used;
int s = 0;
void dfs(int v, vector<int>& f) {
used[v] = 1;
f.push_back(v);
for (int i = 1; i < n; i++)
if (!used[i] && G[v][i] == 1) dfs(i, f);
}
void dfs1(int v) {
vector... | ### Prompt
Generate a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
long long ran[200009];
long long parent[200009];
long long find(long long i) {
if (parent[i] == i) {
return i;
}
return parent[i] = find(parent[i]);
}
void merge(long long i, long long j) {
long long pi = find(i);
long long pj = find(j);
long long r1 = ran[p... | ### Prompt
Please formulate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
long long int find(long long int u, vector<long long int> &par) {
while (par[u] != u) u = par[u];
return u;
}
void _union(long long int u, long long int v, vector<long long int> &par,
vector<long long int> &rank) {
long long int pu = find(u, par);
long l... | ### Prompt
Develop a solution in cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
int par[2010], notinvited[2010];
int root(int i) { return par[i] < 0 ? i : (par[i] = root(par[i])); }
void merge(int x, int y) {
if ((x = root(x)) == (y = root(y))) return;
if (par[y] < par[x]) swap(x, y);
par[x] += par[y];
par[y] = x;
}
int main() {
int n, k, m, ... | ### Prompt
Create a solution in Cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[2010];
vector<int> mark;
vector<pair<int, int> > Bad;
int color = 0;
int good = 0;
int curgood = 0;
void dfs(int v) {
mark[v] = color;
curgood++;
for (int j = 0; j < V[v].size(); j++) {
if (mark[V[v][j]] == 0) dfs(V[v][j]);
}
}
void pr() {
for (i... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int p[2009];
int findset(int x) { return x == p[x] ? x : p[x] = findset(p[x]); }
void unionset(int x, int y) { p[findset(x)] = findset(y); }
bool no[2009], vis[2009];
int cnt[2009];
int main() {
int m, n;
cin >> n;
for (int i = 1; i <= n; i++) p[i] = i;
cin >> m;
... | ### Prompt
Develop a solution in Cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int MOD = 1e9 + 7;
long long int n, m, answer = 0, calc;
long long int deg[200005];
long long int visited[200005], arp[200005], bd[200005], sz[200005];
vector<long long int> comp, like[200005], disli... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9, MOD = 998244353;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long power(long long a, long long b) {
return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));
}
long long mod(long long a) { return... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int maxm = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int n, k, m;
int par[maxn];
int s[maxn];
void init() {
for (int i = 1; i <= n; i++) {
par[i] = i;
s[i] = 1;
}
}
int find(int x) { return x == par[x] ? x : (par[x] = find(par[x])); }
vo... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<int> fr[2005], ht[2005];
int used[2005], tmp, valid;
void dfs(int u) {
used[u] = 1;
tmp++;
for (int j = 0; j < int((ht[u]).size()); ++j)
if (used[ht[u][j]]) valid = 0;
for (int j = 0; j < int((fr[u]).size()); ++j)
if (!used[fr[u][j]]) dfs... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
vector<int> par;
void make_par(int szz) {
for (int i = 0; i < szz; i++) {
par[i] = i;
}
}
int find_set(int x) {
if (par[x] == x) {
return x;
} else {
int result = find_set(par[x]);
par[x] = result;
return result;
}
}
void unionn(int x, int y) {... | ### Prompt
Construct a cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
const int ma1 = 3e5 + 5;
string no = "NO", yes = "YES";
const unsigned int MAX1 = 1000000007;
vector<int> G[1000000];
int ma[100001] = {0};
vector<long long> dis;
int sum = 1;
int root1(int a[], int i) {
while (i != a[i]) {
i = a[a[i]];
}
return i;
}
bool find1(in... | ### Prompt
Create a solution in Cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int f[2005], p[2005], T[2005];
int father(int x) {
if (x != f[x]) {
f[x] = father(f[x]);
}
return f[x];
}
int main() {
int i, j, l, x, y;
scanf("%d", &n);
for (i = 1; i <= n; i++) f[i] = i;
scanf("%d", &m);
for (i = 1; i <= m; i++) {
sca... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans, p[2222], sz[2222], mark[2222];
int root(int x, int p[]) {
while (x != p[x]) p[x] = p[p[x]], x = p[x];
return x;
}
void merge(int u, int v) {
int x = root(u, p);
int y = root(v, p);
if (x == y) return;
if (sz[x] > sz[y])
p[y] = x, sz[x] += s... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int Abs(int x) {
if (x < 0) return -x;
return x;
}
int N, M, K;
bool no[2001][2001] = {false}, visited[2001] = {false}, rooted[2001] = {false},
notgo[2001];
vector<int> G[2001], g[2001];
int cn = 0;
bool run = true;
void dfs(int r) {
if (!run) return;
cn++;
v... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
const long long int mod = 9999999999999983;
long long int primes[6] = {1125899906842597, 1495921043, 1005985879,
1495921043, 1005985879, 1495921043};
using namespace std;
vector<long long int> adj[2000009];
long long int parent[2000009];
long long int siz[200000... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2005;
vector<int> adj[mxN];
bool visited[mxN];
int n;
vector<int> comp;
void pre() {}
void dfs(int v) {
visited[v] = true;
comp.push_back(v);
for (auto x : adj[v]) {
if (!visited[x]) {
dfs(x);
}
}
}
void solve() {
cin >> n;
int m;
... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
vector<int> sz;
map<int, int> ch;
struct DSU {
vector<int> p;
DSU(int n) : p() {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }
void join(int x, int y) { p[root(y)] = root(x); }
};
i... | ### Prompt
Generate a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, a, b, vis[2010];
vector<int> like[2010];
vector<int> dislike[2010];
vector<int> ac;
int is;
void dfs(int x) {
vis[x] = 1;
ac.push_back(x);
for (int i = 0; i < dislike[x].size(); i++) {
if (count(ac.begin(), ac.end(), dislike[x][i])) {
is = 0;
... | ### Prompt
In cpp, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
int n, m, x, y, k, v[2001], X[200000], Y[200000], p[2001], a[2001][2001], ans;
void dfs(int x, int y) {
v[x] = y;
p[y]++;
for (int i = (1); i <= (n); i++)
if (a[x][i] && !v[i]) dfs(i, y);
}
int main() {
scanf("%d", &n);
scanf("%d", &k);
for (int i = (1); i <= (k); i++) {
sca... | ### Prompt
Generate a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int dsu[2001];
int size[2001];
void assign(int n) {
for (int i = 0; i <= n; i++) {
dsu[i] = i;
size[i] = 1;
}
}
int find(int i) {
while (i != dsu[i]) {
dsu[i] = dsu[dsu[i]];
i = dsu[i];
}
return i;
}
void unionn(int x, int y) {
int xx = find(x);
... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 4;
vector<int> fri[MAXN];
int id[MAXN], cnt[MAXN], idx, ans;
bool vis[MAXN], dis[MAXN][MAXN];
void dfs(int u) {
vis[u] = true;
id[u] = idx;
cnt[idx]++;
for (int v : fri[u]) {
if (!vis[v]) {
dfs(v);
}
}
}
int main() {
ios::syn... | ### Prompt
Please provide a cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 10;
vector<int> mat1[MAXN], hv;
int mat2[MAXN][MAXN], n, m, k, ans;
bool isMarked[MAXN];
void input() {
cin >> n;
cin >> m;
for (int i = 0; i < m; ++i) {
int v, u;
cin >> v >> u;
mat1[v].push_back(u);
mat1[u].push_back(v);
m... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
char us[maxn];
int subsize[maxn];
vector<int> gfriend[maxn];
vector<int> genemy[maxn];
int color[maxn], bad_boy[maxn];
bool dfs(int i, int col, int anc = -1) {
subsize[i] = 1;
color[i] = col;
us[i] = true;
for (auto v : genemy[i]) {
if (co... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e8;
const double pi = 3.1415926535897;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
struct edge {
int from, to, w;
edge(int u, int v, int w) : from(u), to(v), w(w) {}
bool operator<(... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int par[2005];
pair<int, bool> arr[2005];
int find_set(int u) {
if (u == par[u])
return u;
else
return par[u] = find_set(par[u]);
}
bool is_same_set(int x, int y) { return (find_set(x) == find_set(y)); }
void union_set(int x, int y) {
x = find_set(x);
y = fi... | ### Prompt
In CPP, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b, long long m) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
long long modInv(long long a, long long m) {
a = a % m;
for (long long x = 1; x < m; x++)
... | ### Prompt
Generate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
bool vis[2009], dis[2009][2009];
vector<int> v[2009];
void bfs(int u) {
int st, x, i;
queue<int> qu;
v[0].clear();
v[0].push_back(u);
vis[u] = 1;
qu.push(u);
while (!qu.empty()) {
st = qu.front();
qu.pop();
for (i = 0; i < v[st].size(); i++) {
... | ### Prompt
Generate a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[3000];
bool ma[3000][3000] = {};
bool vis[3000] = {};
set<long long> like, dislike;
bool val;
void pri(set<long long> s) {
set<long long>::iterator it;
for (it = s.begin(); it != s.end(); it++) cout << *it << " ";
cout << endl;
}
void init(long l... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> used;
vector<int> res;
void dfs(int v) {
used[v] = 1;
res.push_back(v);
for (int i = 0; i < g[v].size(); ++i) {
int to = g[v][i];
if (!used[to]) dfs(to);
}
}
int main() {
int n;
cin >> n;
g.resize(n);
used.resize(n... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, nof, noe, u, v, counter;
cin >> n;
cin >> nof;
int *arr = new int[n + 1];
for (int i = 0; i <= n; i++) {
arr[i] = i;
}
counter = n + 1;
for (int i = 0; i < nof; i++) {
cin >> u >> v;
if (arr[u] == 0 && arr[v] == 0) {
cou... | ### Prompt
Please formulate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[2002];
int mat[2002][2002];
vector<int> te;
int vis[2002];
void go(int i) {
vis[i] = 1;
te.push_back(i);
for (int j = 0; j < G[i].size(); j++) {
int v = G[i][j];
if (vis[v] == 0) {
go(v);
}
}
}
int main() {
int n, m, k;
cin >> n;
... | ### Prompt
In CPP, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
long long *id, cnt, *sz;
map<long long, long long> mp;
void init(long long N) {
cnt = N;
id = new long long[N + 1];
sz = new long long[N + 1];
for (long long i = 1; i <= N; i++) {
id[i] = i;
sz[i] = 1;
}
}
long long find(long long p) {
if (id[p] == p)
... | ### Prompt
Please create a solution in cpp to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
int dx[] = {0, 1, -1, 0, 1, -1, 1, -1, -2, 2, 0, 0},
dy[] = {1, 0, 0, -1, -1, 1, 1, -1, 0, 0, -2, 2};
using namespace std;
vector<vector<int> > g(2005, vector<int>(0));
vector<vector<int> > d(2005, vector<int>(0));
vector<int> nodes;
set<int> dis;
int visited[2005];
void dfs(int cur) {
vi... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
vector<int> fr[100010], en[100010];
int arr[100010], vis[100010], ct[100010], p[100010];
struct UnionFind {
int par[2000], ra[2000];
UnionFind() {
for (int(i) = 0; (i) < (2000); (i)++) par[i] = i, ra[i] = 1;
}
int find(int x) { return par[x] == x ? x : par[x] = ... | ### Prompt
Construct a cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)((1e5) + 10);
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
bool isPrime(int... | ### Prompt
Generate a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, l, ok[100005], x[100005];
int used[100005];
vector<int> g[100005];
vector<int> gg[100005];
void dfs(int v) {
used[v] = l;
ok[l]++;
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (!used[to]) {
dfs(to);
}
}
}
int main() {
... | ### Prompt
In cpp, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
int parent[2000];
int Find(int x) {
if (parent[x] != x) parent[x] = Find(parent[x]);
return parent[x];
}
void Union(int x, int y) {
x = Find(x);
y = Find(y);
parent[x] = y;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) parent[i... | ### Prompt
Develop a solution in Cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
struct pvz {
int now[2002], g[500001], next[500001];
int tot;
void set() { tot = 0; }
void add(int s, int t) {
++tot;
g[tot] = t;
next[tot] = now[s];
now[s] = tot;
}
} e;
int dislike[2002][2002];
int hash[2002], n, m1, m2;
int queue[2002], cl, op, ans = 0;
void put(int... | ### Prompt
Construct a cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, m, u, v;
vector<int> g[2000];
int c[2000];
int d[2000];
vector<int> q;
int t, p;
int z = 0;
bool h[2000];
int b = 0;
cin >> n >> k;
for (int i = 0; i < k; ++i) {
cin >> u >> v;
--u;
--v;
g[u].push_back(v);
g[v... | ### Prompt
Generate a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants t... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > Adj[2001];
bool visited[2001];
int group_size[2001];
bool poss[2001];
int id1 = 0;
void DFS(int u, int p) {
visited[u] = true;
group_size[id1]++;
for (vector<pair<int, int> >::iterator it = Adj[u].begin();
it != Adj[u].end(); it++) {
... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 123, MAXN = 2e5 + 47, MEGAINF = 1e18;
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (auto& i : a) out << ... | ### Prompt
Develop a solution in cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > g(2005);
vector<vector<long long int> > hate(2005, vector<long long int>(2005));
vector<bool> used(2005);
vector<long long int> ans;
void dfs(long long int v) {
used[v] = true;
ans.push_back(v);
for (auto i : g[v]) {
if (!used[i]) df... | ### Prompt
Please create a solution in Cpp to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
int n, like, dislike, a, b, flag[2005], jum[2005];
int main() {
while (scanf("%d", &n) != EOF) {
vector<int> vec1[2005];
vector<pair<int, int> > vec2;
scanf("%d", &like);
for (int i = 0; i < like; i++) {
scanf("%d %d", &a, &b);
vec1[a].push_bac... | ### Prompt
Develop a solution in Cpp to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<int> root;
vector<int> sz;
int GetRoot(int x) {
if (root[x] == x) return x;
root[x] = GetRoot(root[x]);
return root[x];
}
void Union(int x, int y) {
x = GetRoot(x);
y = GetRoot(y);
if (x == y) return;
if (sz[x] > sz[y]) {
sz[y] += sz[x];
root[x]... | ### Prompt
Please provide a CPP coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int n, m, c[2001], col, num[2001], t1, t2, t3;
vector<int> adj[2001];
int dfs(int v) {
int s = 1;
c[v] = col;
for (int i = 0; i < adj[v].size(); i++) {
if (c[adj[v][i]] == 0) {
s += dfs(adj[v][i]);
}
}
return s;
}
int main() {
cin >> n;
cin >> m;... | ### Prompt
Please create a solution in Cpp to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > v(100010);
map<long long, long long> fr;
map<pair<long long, long long>, long long> enemy;
vector<pair<long long, long long> > en;
vector<bool> th(100010), vi(100010);
long long DFS(long long n) {
stack<long long> s;
long long ans = 0;
vecto... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int father[2005];
int c[2005];
int N, M;
int sum[2005];
int getfather(int x) {
return father[x] == x ? x : father[x] = getfather(father[x]);
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) father[i] = i;
for (int i = 1; i <= M; i++) {
int a, b... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
const bool testcases = 1;
unsigned long long int logn(unsigned long long int n,
unsigned long long int r) {
return (n > r - 1) ? 1 + logn(n / r, r) : 0;
}
int powmod(long long int x, unsigned long long int y, long long int p) {
long long int ... | ### Prompt
In cpp, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
int par[100000], rnk[100000], cnt[100000], D[100000], N;
int k, m;
int getRoot(int x) {
if (par[x] == x) return x;
return par[x] = getRoot(par[x]);
}
void unionRoot(int x, int y) {
int r1 = getRoot(x), r2 = getRoot(y);
if (r1 == r2) return;
if (rnk[r1] > rnk[r2])
... | ### Prompt
Please formulate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
unordered_map<long long int, set<long long int>> m;
unordered_map<long long int, set<long long int>> ad;
long long int ver = 0;
int dfs(long long int a, long long int visited[], long long int k) {
visited[a] = k;
ver++;
for (auto j : m[a]) {... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 123, MAXN = 2e5 + 47, MEGAINF = 1e18;
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (auto& i : a) out << ... | ### Prompt
In cpp, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > gr;
vector<int> v, f;
int dfs(int n) {
int i, j, k;
v[n] = 1;
f[n] = 1;
int ret = 1;
for (i = 0; i < gr[n].size(); i++) {
if (v[gr[n][i].first]) {
if (gr[n][i].second == 2) return -1;
} else {
if (gr[n][i].secon... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n;
int mf;
bool gf[2000][2000];
int me;
bool ge[2000][2000];
bool used[2000];
vector<int> cc;
void dfs(int v) {
if (used[v]) return;
cc.push_back(v);
used[v] = true;
for (int i = 0, _n = (n); i < _n; ++i)
if (gf[v][... | ### Prompt
Your task is to create a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
while (b) b ^= a ^= b ^= a %= b;
return (a);
}
template <class T>
T lcm(T a, T b) {
return (a * b / gcd(a, b));
}
using namespace std;
vector<vector<int> > g(2001), p(2001);
bool used[2001];
int ans, use = 0;
void dfs(int x) {
used[x] = 1;
for (int... | ### Prompt
Construct a Cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
void fun() {}
long long mod = 1000000000 + 7;
long long powe(long long x, long long y) {
x = x % mod, y = y % (mod - 1);
long long ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int n, t, a, b, c, k, m, res;
vector<int> Like[2005], Dis[2005], Connect[2005];
bool Free[2005];
void bfs(int cur) {
Connect[c].push_back(cur);
for (int i = 0, _n = (Like[cur].size()); i < _n; i++) {
int tmp = Like[cur][i];
if (Free[tmp]) {
Free[tmp] = fal... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, c[2001], col, num[2001], t1, t2, t3;
vector<int> adj[2001];
int dfs(int v) {
c[v] = col;
int s = 1;
for (int i = 0; i < adj[v].size(); i++) {
if (c[adj[v][i]] == 0) {
s += dfs(adj[v][i]);
}
}
return s;
}
int main() {
cin >> n;
cin >> m;... | ### Prompt
Create a solution in Cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > AdjList;
bool cmp[2009];
int col[2009];
int color;
int cont = 0;
void dfs(int nodo) {
cmp[nodo] = true;
cont++;
col[nodo] = color;
for (int i = 0; i < AdjList[nodo].size(); i++) {
int v = AdjList[nodo][i];
if (!cmp[v]) dfs(v);
}
}
int ... | ### Prompt
Create a solution in cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
bool vis[2005], ver;
int cnt, j;
vector<int> e;
void dfs(vector<pair<int, int> > g[], int t) {
vis[t] = true;
cnt++;
for (int i = 0; i < g[t].size(); i++) {
if (g[t][i].second ... | ### Prompt
Construct a CPP code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 100;
long long n, m, k;
vector<long long> adj[MAXN], path;
bool vis[MAXN], Bad[MAXN][MAXN];
void dfs(long long x) {
vis[x] = true;
path.push_back(x);
for (long long i = 0; i < adj[x].size(); i++) {
if (!vis[adj[x][i]]) {
dfs(adj[... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int p[2010], sz[2010];
int root(int x) { return p[x] != x ? p[x] = root(p[x]) : x; }
void join(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return;
if (sz[x] >= sz[y])
sz[p[y] = x] += sz[y];
else
sz[p[x] = y] += sz[x];
}
int main() {
int n, k, m... | ### Prompt
Construct a Cpp code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100000];
vector<int> s[190000];
int vis[100000], w = 0;
void dfs(int x) {
int j;
vis[x] = 1;
for (j = 0; j < v[x].size(); j++) {
if (vis[v[x][j]] == 0) dfs(v[x][j]);
}
}
int main() {
int n, i, ans = 0, j, m, k, a, b, o, t, e;
cin >> n >> k;
f... | ### Prompt
Create a solution in Cpp for the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p[2001], t1, t2, t3, f[2001], s[2001];
int findd(int x1) {
if (p[x1] == x1) return x1;
return p[x1] = findd(p[x1]);
}
int unionn(int x1, int x2) {
if (findd(x1) != findd(x2)) p[findd(x1)] = findd(x2);
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141593;
const long long mod = 1000000007;
const long long INF = 1e15;
const long long nax = 1e5 + 5;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
string ds = "RLDU";
long long parent[200001] = {0};
long long size[200001] = {0};
lo... | ### Prompt
Please provide a cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = 4 * atan((long double)1);
const long long INF = 1e18;
const long long NINF = -1e18;
long long get_hash(string s) {
long long N = 1000001;
long long base[N], A = 11, MD = 1110111110111;
base[0] = 1;
for (long long... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
static const int INF = std::numeric_limits<int>::max();
struct Node {
std::vector<int> next;
};
int dis[2001][2001];
std::vector<Node> f, d;
std::vector<int> verts, used;
void dfs(int x, int color) {
used[x] = color;
verts.push_back(x);
for (int i = 0; i < (int)f[x].next.size(); ++i) {
... | ### Prompt
Please formulate a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
void solution();
template <class T>
T GCD(T a, T b) {
if (a == 0) return b;
return GCD(b % a, a);
}
template <class T>
T modpow(T x, T p) {
T res = 1;
while (p > 0) {
if (p & 1) res *= x;
x *= x;
p /= 2;
}
return res;
}
template <class T>
void print(... | ### Prompt
Develop a solution in CPP to the problem described below:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
class DisjointSet {
public:
long long int n;
vector<pair<long long int, long long int>> parent;
vector<long long int> rank;
vector<long long int> dsuParents;
map<long long int, long long int> countRoots;
DisjointSet() {
n = 0;
parent = vector<pair<long ... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
int n = 0;
int **relation;
bool *invited;
int *result_set;
int cur_num = 0;
bool canInvite(int x) {
for (int i = 0; i < cur_num; i++) {
if (relation[x][result_set[i]] == -1) {
return false;
}
}
return true;
}
void fill(bool *filled, int x, bool value) {
... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool prime[1000005];
void seive(int n) {
me... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<pair<int, int> > v[2001];
int vis[2001];
int ans = 1;
int cn = 0;
int dfs(int x) {
if (vis[x]) return 0;
cn++;
vis[x] = 1;
for (int i = 0; i < v[x].size(); i++) {
if (v[x][i].second == 0) {
dfs(v[x][i].first);
} else... | ### Prompt
Please create a solution in Cpp to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MAXn = 2000 + 10;
int n;
vector<int> nb[MAXn];
int mark[MAXn], mark2[MAXn], gmark[MAXn];
vector<int> comp[MAXn];
int cc;
bool enem[MAXn][MAXn];
void dfs(int v) {
mark[v] = true;
gmark[v] = true;
comp[cc].push_back(v);
for (__typeof(nb[... | ### Prompt
Your task is to create a Cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
int g[2000][2000] = {0};
int used[2000] = {0};
int n;
int k;
int l;
int count = 0;
std::vector<int> curr;
void init() {
std::cin >> n >> k;
for (int i = 0; i < k; i++) {
int x, y;
std::cin >> x >> y;
g[--x][--y] = 1;
g[y][x] = 1;
}
std::cin >> l;
for (int i = 0; i < l;... | ### Prompt
In Cpp, your task is to solve the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver want... |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, g[2010][2010], ans, res, ok, invited[2010], used[2010];
void f(int cur) {
used[cur] = 1;
invited[cur] = 1;
res++;
for (int i = 0; i < n; i++) {
if (g[cur][i] == 1 && !used[i]) f(i);
if (g[cur][i] == 2 && invited[i]) ok = 0;
}
}
int main() {
... | ### Prompt
Your task is to create a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v, q;
int vis1[2001] = {0};
int f(int k) {
queue<int> z;
int vis[2001] = {0};
int c = 1, i;
z.push(k);
vis[k] = 1;
while (!z.empty()) {
k = z.front();
z.pop();
for (i = 0; i < v[k].size(); i++) {
if (vis[v[k][i]] == 2) retu... | ### Prompt
Please create a solution in CPP to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[2010];
bool visited[2010];
bool p = false;
void dfs(int node, vector<int> &v) {
v.push_back(node);
visited[node] = true;
for (int i = 0; i < adj[node].size(); i++) {
if (adj[node][i].second) {
if (!visited[adj[node][i].first]) {
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Sm... |
#include <bits/stdc++.h>
using namespace std;
int reg = 0, ans = 0;
vector<bool> visited;
vector<int> gaycount;
vector<vector<int> > likes;
bool dislikes[2001][2001];
bool poss[2001] = {true};
vector<vector<int> > region;
void dfs(int node) {
region[reg].push_back(node);
visited[node] = true;
for (int i = 0; i < ... | ### Prompt
Construct a CPP code solution to the problem outlined:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wa... |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> friends;
vector<vector<int>> enemies;
vector<int> parent;
int cnt;
bool dfs(int node, int color) {
parent[node] = color;
cnt++;
bool result = true;
for (int next : friends[node])
if (parent[next] == 0) result = dfs(next, color) && resu... | ### Prompt
Your task is to create a CPP solution to the following problem:
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.