output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, m;
char mat[300][300];
long long dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
long long dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
bool isvalid(long long x, long long y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
void dfs(long long x, long long y, vector<pair<long long, ... | ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares... |
#include <bits/stdc++.h>
using namespace std;
int H, W;
char board[260][260];
bool used[260][260];
int xmax, xmin, ymax, ymin, summax, summin, diffmax, diffmin, cnt;
int dx[] = {1, 1, 1, 0, -1, -1, -1, 0}, dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool one(int x, int y) {
return (x >= 0 && x < H && y >= 0 && y < W && board... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with ... |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 300;
char str[NMAX][NMAX];
int field[NMAX][NMAX];
int n, m;
int cur_lab = 2;
bool not_quad[NMAX * NMAX];
struct Vec2 {
int x, y;
Vec2(int x, int y) : x(x), y(y) {}
void operator+=(const Vec2 &that) {
x += that.x;
y += that.y;
}
void operat... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squ... |
#include <bits/stdc++.h>
using namespace std;
long long a[100010], b[101010] = {0};
char s[520][520] = {0};
int t, n, m;
int X[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1},
Y[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1};
int dfs(int x, int y, int &t) {
if (s[x][y] != '1') return 0;
s[x][y] = '2';
t++;
for (int i = 1; i <= 8;... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with ... |
#include <bits/stdc++.h>
#pragma warning(disable : 4786)
using namespace std;
int cnt;
int grid[300][300];
char word[300][300];
int CNT;
void check_adj(int rr, int cc) {
if (grid[rr][cc] == 1) {
cnt++;
grid[rr][cc] = 2;
} else
return;
check_adj(rr + 1, cc);
check_adj(rr - 1, cc);
check_adj(rr + 1,... | ### Prompt
Develop a solution in cpp to the problem described below:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with ... |
#include <bits/stdc++.h>
using namespace std;
const int X[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
Y[8] = {0, 0, -1, 1, -1, 1, 1, -1};
char ar[256][256];
int n, m, t, cnt, ans;
void dfs(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= m || ar[x][y] != '1') return;
ar[x][y] = '2';
++cnt;
for (int i = 0; i... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with ... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char mm[260][260];
int tc;
bool used[260][260];
int qy[260 * 260], qx[260 * 260];
int nq;
bool valid(int y, int x) { return (y >= 0 && y < n && x >= 0 && x < m); }
void bfs(int y, int x) {
nq = 1;
qy[0] = y;
qx[0] = x;
used[y][x] = true;
int it;
for (i... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with ... |
#include <bits/stdc++.h>
using namespace std;
char table[251][251];
vector<pair<int, int> > pos;
int n, m;
void go(int x, int y) {
pos.push_back(make_pair(x, y));
table[x][y] = '0';
for (int dx = -1; dx <= 1; ++dx)
for (int dy = -1; dy <= 1; ++dy) {
if (x + dx < 0 || x + dx == n) continue;
if (y +... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squ... |
#include <bits/stdc++.h>
using namespace std;
bool check1(vector<pair<int, int> > &a) {
if (a.size() == 0) return false;
if (a.size() % 4) return false;
int d = a.size() / 4 + 1;
sort(a.begin(), a.end());
for (int i = 1; i < d; ++i)
if (a[i].first != a[i - 1].first)
return false;
else if (a[i].s... | ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squ... |
#include <bits/stdc++.h>
using namespace std;
int T, ans;
int num[255][255];
int n, m;
int tx[10] = {0, 1, 0, -1, 0, 1, 1, -1, -1};
int ty[10] = {0, 0, 1, 0, -1, 1, -1, -1, 1};
queue<pair<int, int> > que;
bool safe(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
int check1(int x, int y) {
int cnt1 = 0,... | ### Prompt
Construct a CPP code solution to the problem outlined:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with eac... |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int n, m;
char a[300][300];
int u[300][300];
void dfs(int x, int y, int& t) {
t++;
u[x][y] = 1;
a[x][y] = '2';
for (int i = 0; i < 8; i++) {
int nx = x + dx[i], ny = y + dy[i];
i... | ### Prompt
In cpp, your task is to solve the following problem:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2 × 2. We are only interested in two types of squares:
1. squares with each ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int SIZE = 500;
set<pair<int, int> > now, pre;
struct Node {
int u, v, fa, dep;
};
stack<Node> s;
int n, m;
int op[N], x[N], y[N];
struct DSU {
int fa[N], dep[N];
void init(int n) {
for (int i = 1; i <= n; i++) fa[i] = i, dep[i] = 1;
... | ### Prompt
Create a solution in Cpp for the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such ... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
a += b;
if (a < 0) a += MOD;
if (a >= MOD) a -= MOD;
}
vo... | ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = 600;
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
inline int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
int const N = 200000 + 10;
int const B = 500;
int n, m, f[N], st[N], top, ans[N], x[N], y[N], z[N], s[N];
set<pair<int, int> > mat, mt, se;
set<pair<int, int> >::iterator p;
pair<int, int> edge[N][2];
int inline find(int x) {
while (x != f[x]) x = f[x];
return x;
}
int ... | ### Prompt
Create a solution in Cpp for the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such ... |
#include <bits/stdc++.h>
using namespace std;
const int BUF = 10 * 1000 * 1000 + 13;
const int N = 300 * 1000 + 13;
const int M = 300 * 1000 + 13;
const int P = 400;
struct query {
int t, x, y;
int e0, e1;
};
int n, m;
query q[M];
int p[N], rk[N];
int cnt;
int *where[BUF];
int val[BUF];
void rollback() {
while (c... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
const int bs = 3000;
struct PDSU {
vector<int> par, sub;
stack<pair<int, int>> chngs;
PDSU(int n) {
par.resize(n);
sub.resize(n, 0);
for (int i = 1; i < n; i++) par[i] = i;
}
inline int rootFast(int x) {
par[x] = par[x] != x ? ... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = 700;
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
inline int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root... | ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5;
struct Query {
int op, u, v;
};
int N, Q;
Query q[Maxn + 5];
set<pair<int, int> > g1, g2;
int fa[Maxn + 5], siz[Maxn + 5];
stack<pair<int, int> > stk;
void check(int u, int v) {
if (u > v) swap(u, v);
pair<int, int> p = make_pair(u, v);
if (g1.... | ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
int n, m;
struct query {
int id, x, y;
query() {}
query(int ID, int X, int Y) : id(ID), x(X), y(Y) {}
} q[N], nq[400];
int sz = 300, t = ... | ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
const int BUF = 10 * 1000 * 1000 + 13;
const int N = 300 * 1000 + 13;
const int M = 300 * 1000 + 13;
const int P = 400;
struct query {
int t, x, y;
int e0, e1;
};
int n, m;
query q[M];
int p[N], rk[N];
int cnt;
int *where[BUF];
int val[BUF];
void rollback() {
while (c... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
stack<pair<int *, int> > stk;
int parent[400010], siz[400010];
int getParent(int cntPt) {
if (parent[cntPt] == cntPt) return cntPt;
return getParent(parent[cntPt]);
}
bool merge(int fstPt, int sndPt) {
fstPt = getParent(fstPt), sndPt = getParent(sndPt);
if (fstPt ==... | ### Prompt
Create a solution in Cpp for the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such ... |
#include <bits/stdc++.h>
long long int const MOD = 1000000007;
long long int const N = 1000005;
long long int const LN = 20;
long long int const inf = 8e18;
using namespace std;
long long int n, m, a[N];
struct query {
long long int tp, x, y;
long long int e0, e1;
};
long long int const Block = 400;
query q[N];
pai... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 2e5 + 5;
const int BS = 450;
int n, m;
int dsu[N];
int find_old(int v) { return dsu[v] < 0 ? v : dsu[v] = find_old(dsu[v]); }
void merge_old(int u, int v) {
u = find_old(u), v = find_old(v);
if (u == v) return;
if (dsu[v] < dsu[u])... | ### Prompt
In Cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = 500;
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
inline int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root... | ### Prompt
Generate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
const int P = 400, N = 4e5 + 5;
string ans;
struct Q {
int t, x, y;
};
bool inGameE[N], inGameV[N];
vector<pair<int, int>> edges;
int n, m, last = 0;
int w[N], mem[N], isOn[N];
int findSet(int v) { return w[v] < 0 ? v : w[v] = findSet(w[v]); }
void connect(int a, int b) {... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int E[2][N], U[N], V[N], typ[N], nxt[2][N], lst[N], f[N], par[N], sz[N], q, tot,
ans;
vector<int> seg[4 * N], his;
map<pair<int, int>, int> mp;
int get(int u, int v) {
if (v < u) swap(u, v);
if (mp[make_pair(u, v)]) return mp[make_pair(u, v)]... | ### Prompt
Create a solution in CPP for the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such ... |
#include <bits/stdc++.h>
using namespace std;
int const maxn = 2e5 + 5, k = 700;
set<int> g[maxn];
multiset<int> G[maxn];
int cur, numb;
int used[maxn];
int ok, what;
int number[maxn];
void dfs(int v) {
used[v] = cur;
number[v] = numb;
for (auto u : g[v])
if (used[u] != cur) dfs(u);
}
void dfs1(int v) {
use... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m;
const int maxN = 2 * (int)1e5 + 100;
set<int> ed[maxN];
const int BLOCK = 2000;
int x[maxN], y[maxN], tp[maxN];
int cmp[maxN];
vector<int> g[maxN];
int sz = 0;
void dfs(int v) {
cmp[v] = sz;
for (int to : g[v]) {
if (cmp[to] == 0... | ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1 << 18;
int par[MAXN];
int sz[MAXN];
vector<pair<int, int>> history;
void init() {
iota(par, par + MAXN, 0);
fill(sz, sz + MAXN, 1);
}
int find(int v) { return v == par[v] ? v : find(par[v]); }
int merge(int v, int u) {
v = find(v);
u = find(u)... | ### Prompt
Develop a solution in Cpp to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int RT = 450;
struct hist {
int ind, val, ind2, sz;
hist() {}
hist(int a, int b, int c, int d) : ind(a), val(b), ind2(c), sz(d) {}
};
struct UF {
int par[N];
int sz[N];
bool frozen = false;
vector<hist> history;
UF() {
memset(... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
long long int const MOD = 1000000007;
long long int const N = 1000005;
long long int const LN = 20;
long long int const inf = 8e18;
using namespace std;
long long int n, m, a[N];
struct query {
long long int tp, x, y;
long long int e0, e1;
};
long long int const Block = 400;
query q[N];
pai... | ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
a += b;
if (a < 0) a += MOD;
if (a >= MOD) a -= MOD;
}
vo... | ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
a += b;
if (a < 0) a += MOD;
if (a >= MOD) a -= MOD;
}
vo... | ### Prompt
Generate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
int N, Q, last;
int T[202020], X[202020], Y[202020];
template <int um>
class UF_pop {
public:
vector<int> par, rank;
vector<vector<int>> hist;
UF_pop() {
par = rank = vector<int>(um, 0);
for (int i = 0; i < um; i++) par[i] = i;
}
void reinit() {
int i... | ### Prompt
Generate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <typename T>
void chmin(T &a, T b) {
if (a > b) a = b;
}
template <typename T>
void chmax(T &a, T b) {
if (a < b) a = b;
}
template <typename T>
void add(T &a, T b) {
a += b;
if (a < 0) a += MOD;
if (a >= MOD) a -= MOD;
}
vo... | ### Prompt
Generate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
int const maxn = 2e5 + 5, k = 800;
set<int> g[maxn];
multiset<int> G[maxn];
int cur, numb;
int used[maxn];
int ok, what;
int number[maxn];
void dfs(int v) {
used[v] = cur;
number[v] = numb;
for (auto u : g[v])
if (used[u] != cur) dfs(u);
}
void dfs1(int v) {
use... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
stack<int> sta;
map<pair<int, int>, bool>::iterator it;
map<pair<int, int>, bool> MAP;
const int KUAI = 450;
int N, M;
int OP[2010], U[2010], V[2010];
struct EDGE {
int u, v;
} queding[400010];
int qd_cnt;
int fa[200010], sz[200010];
int fin(int u) {
if (fa[u] == u) ret... | ### Prompt
Develop a solution in cpp to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = 444;
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
inline int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root... | ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
const int P = 500, N = 4e5 + 5;
string ans;
struct Q {
int t, x, y;
};
bool inGameE[N], inGameV[N];
vector<pair<int, int>> edges;
int n, m, last = 0;
int w[N], mem[N], isOn[N];
int findSet(int v) { return w[v] < 0 ? v : w[v] = findSet(w[v]); }
void connect(int a, int b) {... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
inline int read();
const int maxn = 4e5 + 5;
int n;
int id[maxn][2], last;
pair<int, int> q[maxn], edge[maxn << 1];
vector<int> v[maxn << 2];
struct EDGE {
int tim, ty, first, second;
} e[maxn << 1];
bool operator<(const EDGE& a, const EDGE& b) {
if (a.first != b.first)... | ### Prompt
Construct a Cpp code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
multiset<int> gd[300005];
int vis[300005];
bool dfs(int x, int y, int vi) {
if (x == y) {
return true;
}
vis[x] = vi;
for (int xx : gd[x]) {
if (vis[xx] != vi) {
if (dfs(xx, y, vi)) return true;
}
}
return false;
}
class DSU {
public:
int p[... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
struct DSU {
int getSize(int x) { return -getPar(x); }
int getPar(int x) {
int st = op.size();
while (par[x] >= 0) {
op.emplace_back(x, par[x]);
x = par[x];
}
for (int i = st... | ### Prompt
In cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 10;
const int MXM = 4e5 + 10;
const int MXS = MXN * 4;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 +... | ### Prompt
Develop a solution in cpp to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < '0' && c != '-') c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
const int SIZE = 2e5 + 100;
int... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
namespace _ {
bool rEOF = 1;
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && rEOF &&
(p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? (rEOF = 0, EOF)
: *p1++;
}
template <class _... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10, mod = 1e9 + 7, inf = 1e18, siz = 500;
struct ds {
int t, x, y;
};
vector<pair<int, int> > edge, cur_edge;
vector<int> G[maxn], CG[maxn];
int n, m, on[maxn], root[maxn], tplt, mark[maxn], visit[maxn], last = 0;
vector<ds> query;
vector<pair... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m;
set<pair<int, int> > ed;
const int maxN = 2 * (int)1e5 + 100;
const int BLOCK = 1500;
int x[maxN], y[maxN], tp[maxN];
int cmp[maxN];
vector<int> g[maxN];
int sz = 0;
void dfs(int v) {
cmp[v] = sz;
for (int to : g[v]) {
if (cmp[to... | ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int P = 200, N = 4e5 + 5;
string ans;
struct Q {
int t, x, y;
};
bool inGameE[N], inGameV[N];
vector<pair<int, int>> edges;
int n, m, last = 0;
int w[N], mem[N], isOn[N];
int findSet(int v) { return w[v] < 0 ? v : w[v] = findSet(w[v]); }
void connect(int a, int b) {... | ### Prompt
In cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair<int, int>;
using pLL = pair<ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2>
inline void chadd(T1 &x, T2 y, int Mod = mod) {
x += y;
while (x >= Mod) x -= Mod;
... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
const int MN = 200005, MQ = 200005, MS = 524288;
int N, Q;
int op[MQ], qu[MQ], qv[MQ], nxp0[MQ], nxp1[MQ];
inline void Prework() {
std::map<std::pair<int, int>, int> Edg;
for (int i = Q; i >= 1; i--) {
if (op[i] == 2) continue;
int u0 = qu[i], v0 = qv[i], u1 = u0 % N + 1, v1 = v0 % ... | ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
struct DS {
vector<int> Parent;
vector<int> Cont;
vector<pair<int, int>> UndoCont;
vector<pair<int, int>> UndoParent;
void clear() {
UndoCont.clear();
UndoParent.clear();
for (int i = 0; i < Parent.size(); i++) {
Parent[i] = i;
Cont[i] = 1;... | ### Prompt
Construct a cpp code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const int N = 200500;
const int bl = 3000;
vector<int> g[N];
map<pair<int, int>, bool> ok, bad;
int n, q, last, timer, p[N], h[N], u[N], x[N], y[N], tp[N];
int get(int v) { return p[v] = (v == ... | ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
struct Dsu {
std::vector<int> ps;
std::vector<int> ds;
Dsu(size_t size) : ps(size), ds(size) {
for (int i = 0; i < size; ++i) {
ps[i] = i;
}
}
int parent(int i) { return ps[i] == i ? i : ps[i] = parent(ps[i]); }
bool same(int i, int j) { return parent(i) == parent(j); ... | ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
struct UF {
int n;
vector<int> par, sz;
vector<int> ops;
void init(int _n) {
n = _n;
par = sz = vector<int>(n);
for (int i = (0); i < (n); ++i) par[i] = i, sz[i] = 1;
ops.... | ### Prompt
Your task is to create a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 5;
const int LOG = 20;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
bool mark[2 * maxN];
int n, par[maxN], sz[maxN];
int q, type[maxN], lvl = 0;
int N = 0, last = 0;
pair<int, int> E[maxN], iQ[2 * maxN];
stack<int> st[LOG];
map<pair<int,... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans, tot;
unordered_map<long long, int> id;
int op[400010], d[400010], fa[400010], rk[400010], lg[400010], hs[400010];
struct node {
int u, v;
long long h;
void bb() {
if (u > v) swap(u, v);
h = (long long)u << 30 | v;
}
} e[400010], g[400010]... | ### Prompt
Create a solution in cpp for the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such ... |
#include <bits/stdc++.h>
using namespace std;
const int P = 200, N = 4e5 + 5;
string ans;
struct Q {
int t, x, y;
};
bool inGameE[N], inGameV[N];
vector<pair<int, int>> edges;
int n, m, last = 0;
int w[N], mem[N], isOn[N];
int findSet(int v) { return w[v] < 0 ? v : w[v] = findSet(w[v]); }
void connect(int a, int b) {... | ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = 300;
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root[u];
}
... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int P = 300, N = 4e5 + 5;
string ans;
struct Q {
int t, x, y;
};
bool inGameE[N], inGameV[N];
vector<pair<int, int>> edges;
int n, m, last = 0;
int w[N], mem[N], isOn[N];
int findSet(int v) { return w[v] < 0 ? v : w[v] = findSet(w[v]); }
void connect(int a, int b) {... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
const int bs = 1500;
struct PDSU {
vector<int> par, sub;
vector<array<int, 2>> chngs;
PDSU(int n) {
par.resize(n + 1);
sub.resize(n + 1, 0);
for (int i = 1; i <= n; i++) par[i] = i;
}
int rootFast(int x) {
par[x] = par[x] != x ... | ### Prompt
In CPP, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
const int N = 2e5 + 5;
struct Query {
int t, x, y;
};
int n, m;
Query qs[N];
int color[N], used[N], cur_used = 10;
unordered_set<int> g[N];
unordered_multiset<int> h[N];
int qq[4 * N], ql, qr;
void read() {
cin >> n >> ... | ### Prompt
Please provide a cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * power(a * a % md, b / 2, md) % md
: power(a * a % md, b / 2, md) % md));
}
const int xn = 2e5 + 10;
const int xm = -20;
const int sq = 320;
const int... | ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
const int SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
struct state {
int u, v, ru, rv;
state(int u, int v, int ru, int rk) : u(u), v(v), ru(ru), rv(rv){};
};
struct DSU {
vector<int> uf, rk;
stack<state> UPD;
DSU(int n) : uf(n... | ### Prompt
In Cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
In cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
T f = 1;
x = 0;
char ch = getchar();
while (0 == isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (0 != isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
x *= f;
}
template <typ... | ### Prompt
Please create a solution in CPP to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, SQ = 5555;
unordered_map<int, int> ed[N];
set<pair<int, int>> edge, bad;
int n, m, k, last, par[N];
struct Query {
int t, u, v;
} qu[SQ];
bool mark[N];
queue<int> q;
int gg(int u) { return ~par[u] ? par[u] = gg(par[u]) : u; }
void merge(int u, int v... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
class DSU_with_rollback {
int *p, *d;
class rollback {
public:
int a, b;
int pa, pb;
int da, db;
rollback(int A, int B, int PA, int PB, int DA, int DB)
: a(A), b(B), pa(PA), pb(PB), da(DA), db(DB) {}
};
vector<rollback> r;
public:
DSU_... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
multiset<int> gd[300005];
int vis[300005];
bool dfs(int x, int y, int vi) {
if (x == y) {
return true;
}
vis[x] = vi;
for (int xx : gd[x]) {
if (vis[xx] != vi) {
if (dfs(xx, y, vi)) return true;
}
}
return false;
}
class DSU {
public:
int p[... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <c... | ### Prompt
Develop a solution in Cpp to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
std::vector<std::pair<int, int> > v[801000];
std::vector<int> w[801000];
std::map<std::pair<int, int>, int> mp;
int opt[801000], x[2][801000], y[2][801000];
int ans = 0;
int fa[801000], siz[801000];
int nxt[2][801000];
bool lst[2][801000];
int n, m;
int Find(int x) { return fa[x] == x ? x : Fin... | ### Prompt
Construct a cpp code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 100;
int n, m, lastans = 0;
map<int, int> E[N];
int fa[N], sz[N], ans[N];
int top;
struct pi {
int x, y;
} st[N];
struct OP {
int op, x, y;
} o[N];
struct node {
int l, r;
int op, x, y;
vector<OP> id;
} t[N << 2];
int find(int x) { return x == ... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
int lstans, fa[200005], top = 0, sz[200005], n, Q;
struct abc {
int op, x, y, bg[2], ed[2], csx;
} q[200005];
vector<pair<int, int> > g[200005 << 2];
map<pair<int, int>, int> mmp;
struct qwq {
int u, v, fa;
} st[200005 * 20];
int find(int x) { return fa[x] == x ? x : fi... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
const int N = 200005;
int n, m, f[N], s[N], tim, pos[N], bel[N], sz, top, rev[N * 2], ans[N];
std::pair<int, int> stack[N];
std::map<std::pair<int, int>, int> ma;
std::vector<std::pair<int, int> > tag[N * 4];
std::vector<int> vec[N * 2];
struct data {
int op, x, y;
} p[N];
struct edge {
int... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const int N = 200500;
const int bl = 4000;
vector<int> g[N];
map<pair<int, int>, bool> ok, bad;
int n, q, last, timer, p[N], h[N], u[N], x[N], y[N], tp[N];
int get(int v) { return p[v] = (v == ... | ### Prompt
In cpp, your task is to solve the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such... |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1 << 18;
int par[MAXN];
int sz[MAXN];
vector<pair<int, int>> history;
void init() {
iota(par, par + MAXN, 0);
fill(sz, sz + MAXN, 1);
}
int find(int v) { return v == par[v] ? v : find(par[v]); }
int merge(int v, int u) {
v = find(v);
u = find(u)... | ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
struct DSU {
int getSize(int x) { return -getPar(x); }
int getPar(int x) {
int st = op.size();
while (par[x] >= 0) {
op.emplace_back(x, par[x]);
x = par[x];
}
for (int i = st... | ### Prompt
Please formulate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
}
int fix(int x) {
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int pw(int a, int b) {
int ret = 1;
while (b) {
... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
struct union_find {
vector<int> p;
vector<tuple<int, int, int>> s;
union_find(int n) : p(n, -1) {}
bool join(int u, int v) {
if ((u = root(u)) == (v = root(v))) {
s.push_back({-1, 0, 0});
return false;
}
if (p[u] > p[v]) swap(u, v);
s.pus... | ### Prompt
Please formulate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2E5;
const int K = 2000;
set<pair<int, int> > edges;
map<int, int> ccg[N];
int p[N];
int parent(int a) { return p[a] == a ? a : p[a] = parent(p[a]); }
bool join(int a, int b) {
p[a = parent(a)] = parent(b);
return p[a] != a;
}
bool dfs(set<int> &vis, int c... | ### Prompt
Generate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long mod = 998244353;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acosl(-1.0);
long long mod_pow(long long x, long long n, lo... | ### Prompt
Generate a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
istream &op... | ### Prompt
Please create a solution in Cpp to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 400500, P = 1000;
int n, m, X[N], Y[N], curm, ... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXL = 18;
const int MAXN = 200005;
struct node {
node *l, *r, *p;
int x, y, subSize;
char mask;
node() {
l = r = p = NULL;
x = y = subSize = 0;
mask = 0;
}
node(int _x, int _y) {
l = r = p = NULL;
x = _x;
... | ### Prompt
Generate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
struct RollbackUF {
vector<int> fa;
vector<tuple<int, int, int>> history;
RollbackUF(int n) : fa(n, -1) {}
int root(int x) { return fa[x] < 0 ? x : root(fa[x]); }
int size(int x) { return -fa[root(x)]; }
bool sam... | ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int MAXN = 200010;
struct DSU {
int par[MAXN], rank[MAXN];
stack<pair<int*, int>> stk;
DSU() {
for (int i = 1; i < MAXN; i++) par[i] = i;
}
int get(int x) {
if (par[x] == x) return x;
return get(par[x]);
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int MAGIC = 400;
struct query {
int type, u, v, id[2], trueId;
query(int _type = 0, int _u = 0, int _v = 0) : type(_type), u(_u), v(_v) {
id[0] = id[1] = trueId = 0;
}
} q[200005];
int n, numQ, numE;
pair<int, int> e[200005 * 2];
void whatt(int u, int v, int... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6;
const int bs = 3000;
struct PDSU {
vector<int> par, sub;
vector<array<int, 2>> chngs;
PDSU(int n) {
par.resize(n + 1);
sub.resize(n + 1, 0);
for (int i = 1; i <= n; i++) par[i] = i;
}
int rootFast(int x) {
par[x] = par[x] != x ... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int n, q;
int p[maxn], siz[maxn];
int type[maxn], X[maxn], Y[maxn];
int now_ans = 0;
vector<pair<int, int> > A[maxn * 4];
vector<pair<pair<pair<int, int>, int>, pa... | ### Prompt
Develop a solution in CPP to the problem described below:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int S = 5000;
const int maxn = 2e5 + 10;
namespace has {
template <... | ### Prompt
Generate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int M = sqrtl(N);
int a[N];
int b[N];
int typ[N];
int flag[N];
int root[N];
int tmp[N];
int q[N];
int qn;
int find_root(int u) {
if (u == root[u]) {
return u;
}
root[u] = find_root(root[u]);
return root[u... | ### Prompt
Construct a cpp code solution to the problem outlined:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first su... |
#include <bits/stdc++.h>
using namespace std;
const int B = 500;
int n, m;
int T[200001];
int X[200001];
int Y[200001];
vector<pair<int, int> > es;
int par[200001];
int find(int x) {
if (par[x]) return par[x] = find(par[x]);
return x;
}
bool merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return 0... | ### Prompt
Please formulate a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first... |
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 10, bl = 900;
vector<pair<int, int> > sv[sz];
vector<pair<pair<int, int>, int> > sv2[sz];
int main() {
int n, m, last = 0;
cin >> n >> m;
int sp[m][3];
set<int> se[n];
for (int a = 0; a < m; a++) {
for (int b = 0; b < 3; b++) scanf("%d", &... | ### Prompt
Your task is to create a CPP solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const int N = 200500;
const int bl = 6000;
vector<int> g[N];
map<pair<int, int>, bool> ok, bad;
int n, q, last, timer, p[N], h[N], u[N], x[N], y[N], tp[N];
int get(int v) { return p[v] = (v == ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before... |
#include <bits/stdc++.h>
using namespace std;
namespace trcyx {
int pa[65536 * 4], size[65536 * 4];
vector<int> vx, vp, vs;
void init() {
for (int i = 0; i < 65536 * 4; i++) pa[i] = i, size[i] = 1;
}
int find(int x) {
if (pa[x] == x) return x;
return find(pa[x]);
}
void save(int x) {
vx.push_back(x);
vp.push_... | ### Prompt
Generate a cpp solution to the following problem:
You are given an undirected graph with n vertices numbered from 1 to n. Initially there are no edges.
You are asked to perform some queries on the graph. Let last be the answer to the latest query of the second type, it is set to 0 before the first such qu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.