output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optim...
### Prompt Please formulate a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; class graph { public: bool flag = true; map<long long, list<long long>> adj; vector<long long> pop; vector<long long> hap; vector<long long> par; long long v; long long cit; void init(long long n, long long m) { v = n; pop.resize(n + 1); hap.res...
### Prompt Develop a solution in cpp to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; const double eps = 1e-8; long long p[maxn], h[maxn], flag, total[maxn], good[maxn]; vector<long long> w[maxn]; void add_edge(long long x, long long y) { w[x].push_back(y); w[y].push_back(x); } void dfs(long long x, lon...
### Prompt Your challenge is to write a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = 3.14159265359; const long long MOD = 998244353; void i_o() {} long long n, m; vector<long long> p, h; vector<vector<long long>> adj; bool ans = true; pair<long long, long long> dfs(long long v, long long par = -1) { long lo...
### Prompt Develop a solution in Cpp to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; const int m_x[] = {-1, 0, 0, 1}; const int m_y[] = {0, -1, 1, 0}; template <typename T, typename S> ostream& operator<<(ostream& output, const pair<T, S>& to_print) { output << to_print.first << ":" << to_print.second; return output; } template <typename T, typename S> ...
### Prompt Create a solution in cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; int *p; int *h; int *g; int *a; bool access = true; void dfs(int s, int ancestor = -1) { a[s] = p[s]; int s_g = 0; for (auto to : adj[s]) { if (to == ancestor) continue; dfs(to, s); s_g += g[to]; a[s] += a[to]; } int good =...
### Prompt Your challenge is to write a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; long long int binexp(long long int a, long long int b) { long long int lvl = 1; while (b > 0) { if (b & 1) lvl = lvl * a; a = a * a; } return lvl; } long long int modexp(long long int a, long long int b, long long int m) { long long int lvl = 1; while (b...
### Prompt Your task is to create a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; vector<int> g[maxn]; int p[maxn]; int h[maxn]; long long sub[maxn], good[maxn], bad[maxn]; bool ans; void dfs(int x, int par) { sub[x] = p[x]; for (int i : g[x]) { if (i != par) { dfs(i, x); sub[x] += sub[i]; } } if (ab...
### Prompt Construct a cpp code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; inline long long max(long long x, long long y) { return x > y ? x : y; } inline long long min(long long x, long long y) { return x > y ? y : x; } inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ...
### Prompt Generate a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; long long read() { long long w = 0, f = 1; char c = ' '; while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f; while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar(); return w * f; } long long t, n, m, p[100005], h[100005], siz[100005]; bool fl...
### Prompt Generate a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; vector<long long> adj[N]; long long cnt[N], p[N], h[N], good_cnt[N]; bool dfs(long long u, long long par = 0) { cnt[u] = p[u]; long long good_childs = 0; for (long long v : adj[u]) { if (v == par) { continue; } if (!dfs(v...
### Prompt Construct a Cpp code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; using ll = long long; bool res; vector<int> node_happiness, node_population, subtree_population; vector<vector<int> > adj; int dfs_subtree_count(int u = 0, int p = -1) { subtree_population[u] = node_population[u]; for (const int v : adj[u]) { if (v == p) continue; ...
### Prompt In cpp, your task is to solve the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of an...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; pair<long long, long long> dfs(int node, int par, vector<long long> &p, vector<long long> &hi, vector<long long> &sz, vector<vector<int> > &g) { sz[node] = p[node]; long long...
### Prompt Please provide a cpp coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m; int pop[N], hap[N], subsize[N], sad[N], isLeaf[N]; vector<int> adj[N]; bool ans; void dfs(int cur, int prev) { subsize[cur] = pop[cur]; isLeaf[cur] = 1; for (int nxt : adj[cur]) { if (nxt == prev) continue; dfs(nxt, cur); is...
### Prompt Create a solution in Cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; bool f; const long long N = 100005; bool vis[N]; vector<long long> edge[N]; long long person[N], rperson[N], pp[N]; long long dfs(long long x) { vis[x] = 1; long long sr = 0; for (long long i = 0; i < edge[x].size(); i++) { if (vis[edge[x][i]]) continue; perso...
### Prompt Generate a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; const signed inf = 1000000100; const long long inf64 = 1ll * inf * inf; const long long mod = 1e9 + 7; mt19937 rng(0); int n, m; vector<vector<int>> g; vector<int> cnt_good, cnt_bad; vector<int> p; vector<int> h; bool dfs(int v = 0, int pr = -1) { bool able = 1; int ta ...
### Prompt Generate a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, M = 2e5 + 10; const int inf = 0x3f3f3f3f; int n, m, ok; int p[N], h[N], vis[N]; struct Edge { int nex, to; } edge[M << 1]; int tot, head[N]; int a[N], g[N]; inline void add(int from, int to) { edge[++tot].to = to; edge[tot].nex = head[from]; ...
### Prompt Develop a solution in Cpp to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; struct sans { long long int t1; long long int t2; }; bool func(vector<long long int> s1, vector<long long int> s2) { return s1[1] < s2[1]; } string sub(string s1, long long int i, long long int l) { string s2 = ""; for (long long int j = i; j <= l; j++) { s2 =...
### Prompt Your task is to create a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int T; int n, m; int p[maxn]; int h[maxn]; namespace Graph { struct Node { int to; int next; } edge[maxn << 1]; int head[maxn], cnt; inline void add_edge(int x, int y) { edge[++cnt].next = head[x]; edge[cnt].to = y; head[x] = cnt; } } //...
### Prompt Your challenge is to write a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; double pie = 3.14159265358979323846; bool isPowerOfTwo(long long int n) { if (n == 0) return false; return (ceill(log2l(n)) == floorl(log2l(n))); } vector<long long int> g[100000]; long long int p[100000], ha[100000], h[100000], sc[100000]; long long int see = 0; void d...
### Prompt Your task is to create a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; long long a[200005]; long long h[200005]; vector<long long> adj[100005]; long long cnt[100005]; long long vis[100005]; pair<long long, long long> v[200005]; long long l = 0; void dfs(int node) { vis[node] = 1; cnt[node] = a[node]; long long cnth = 0, cnts = 0; for (...
### Prompt Your task is to create a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAX = 2e5 + 10; const ll inf = 1e12; const ll mod = 1e9 + 7; vector<ll> adj[MAX]; ll h[MAX], p[MAX], bad[MAX], good[MAX], fin[MAX]; bool go = true; void dfs(ll u, ll f) { fin[u] = p[u]; for (ll v : adj[u]) { if (v == f) continue; d...
### Prompt Your challenge is to write a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; long long m; vector<list<long long>> v; vector<long long> q, h, k; bool flag; pair<long long, long long> obh(int u) { pair<long long, long long> pr; long long sum = q[u], alr = 0; k[u] = 1; for (auto i : v[u]) { if (!k[i]) { pr = obh(i); sum += pr.fi...
### Prompt Your task is to create a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mo = 1e9 + 7; long long sx, sy, ex, ey, dx[6] = {0, 1, 0, -1, 0, 0}, dy[6] = {1, 0, -1, 0, 0, 0}, m, n, k, dz[6]{0, 0, 0, 0, -1, 1}, sg; long long p, no, v, ans, w; int par[55]; ...
### Prompt Please provide a cpp coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> const int nn = 1e5 + 5; int t, n, m; long long per[nn], h[nn]; int cnt, prev[nn << 1], last[nn], to[nn << 1]; void addedge(int p, int q) { prev[++cnt] = last[p]; to[last[p] = cnt] = q; } long long sum[nn], rec[nn]; int flag; void dfs(int p, int fa) { sum[p] = per[p]; rec[p] = -per[p]; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; const int CONST = 1e9 + 7; const int MAX = 100005; const double pi = 3.14159265358979323846; int n, m; vector<int> pop(MAX); vector<int> hap(MAX); vector<int> adj[MAX]; vector<int> totals(MAX, 0); vector<bool> vis(MAX, false); vector<int> good(MAX, 0), bad(MAX, 0); bool ans...
### Prompt Please provide a cpp coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; vector<int> ve[100010]; int p[100010], h[100010]; long long gd[100010], bd[100010]; long long g[100010]; int flag = 0; void dfs(int to, int fa) { int sum = 0; for (int i = 0; i < ve[to].size(); i++) { int te = ve[to][i]; if (te == fa) continue; dfs(te, to); ...
### Prompt Generate a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<vector<long long> > v(N); vector<long long> p(N), h(N); long long n, m; bool flag = 1; pair<long long, long long> dfs(int a, int par) { long long x = 0, y = 0; bool leaf = 1; for (int i : v[a]) { if (i == par) continue; pair<long ...
### Prompt Construct a CPP code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; namespace io { inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } template <class I> inline void fr(I &num) { num = 0; register ch...
### Prompt Please create a solution in Cpp to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; vector<long long> h; vector<long long> p; vector<vector<long long> > graph; vector<long long> cnt; bool flag; vector<bool> used; void speed_up() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } struct vect { long long sad = 0; long long good = 0; l...
### Prompt Your challenge is to write a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { ...
### Prompt Create a solution in Cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; void my_dbg() { cout << endl; } template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } using ll = long long; using vi = vector<int>; using vl = vector<ll>; const int inf = INT_MAX; const int ninf = INT_MIN; const int ...
### Prompt Create a solution in Cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using ii = pair<int, int>; using pli = pair<ll, int>; using vi = vector<int>; using vll = vector<ll>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using vvi = ve...
### Prompt Please provide a CPP coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; int p[maxn]; int h[maxn]; vector<int> g[maxn]; int happy[maxn]; bool ans; void dfs(int now, int fa) { int sz = g[now].size(); int hp = 0; for (int i = 0; i < sz; i++) { int v = g[now][i]; if (v == fa) continue; dfs(v, now); ...
### Prompt Develop a solution in cpp to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; vector<int> v[N]; int a[N]; int h[N]; bool visit[N]; int ppl[N]; int happy[N]; int sad[N]; bool visit2[N]; bool flag = true; int happyppl[N]; void dfs(int n) { visit[n] = true; ppl[n] += a[n]; for (int i = 0; i < v[n].size(); i++) { int g...
### Prompt Develop a solution in cpp to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; const int N = 100001; vector<int> a[N]; int n, p[N], h[N], nrd[N], nf[N]; bool viz[N], rez; void dfs(int x) { viz[x] = true; nrd[x] = p[x]; int sum_nf = 0; for (auto y : a[x]) { if (!viz[y]) { dfs(y); nrd[x] += nrd[y]; sum_nf += nf[y]; } ...
### Prompt In cpp, your task is to solve the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of an...
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> Dfs(vector<int> tree[], int node, vector<int> visited, int people[], int happiness[], int* ans) { if ((*ans) == 1) return make_pair(make_pair(-1, -1), -1); int j; pair<pair<int, int>, int> pr1, pr2; pr1.first.f...
### Prompt Your challenge is to write a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; long long pop[100001], h[100001], tot[100001]; bool visited[100001]; vector<long long> adj[100001]; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.second == b.second) return a.first > b.first; return a.second > b.second; } long long countT...
### Prompt Construct a Cpp code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; void lc() { cout << endl; } long long md(long long n) { return n % 1000000007; } vector<vector<long long> > adj; vector<long long> H, P, good; long long f; long long dfs1(long long n, long long par) { long long sum = 0; for (long long i = 0; i < adj[n].size(); i++) { ...
### Prompt Generate a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any c...
#include <bits/stdc++.h> using namespace std; inline int qr() { int f = 0, fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + c - 48; c = getchar(); } return f * fu; } const int N = 1e5 +...
### Prompt Construct a CPP code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; const long long MOD = 1e9 + 7; const long long mxN = 1e5 + 3; vector<long long> g[mxN]; long long good[mxN]; long long total[mxN], people[mxN]; long long h[mxN]; bool ok[mxN]; void dfs1(long long u, long long ...
### Prompt Create a solution in cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; long long p[maxn]; long long h[maxn]; vector<long long> g[maxn]; long long happy[maxn]; bool ans; void dfs(long long now, long long fa) { long long sz = g[now].size(); long long hp = 0; for (long long i = 0; i < sz; i++) { long long...
### Prompt Please provide a cpp coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } vector<int> p(2 * 100000 + 1); vector<int> h(2 * 100000 + 1); vector<int> adj[2 * 100000 + 1]; vector<int> visited(2 * 100000 + 1); vector<int> g(2 * 100000 + 1, 0); ...
### Prompt Construct a cpp code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> V; int p[100007], h[100007], a[100007], g[100007]; bool dfs(int num, int parent = -1) { a[num] = p[num]; int sumg = 0; for (int w : V[num]) { if (parent == w) continue; if (!dfs(w, num)) return false; sumg += g[w]; a[num] += a[w]; ...
### Prompt Your task is to create a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; bool fl; long long creater(long long src, vector<vector<long long>>& adjlist, vector<long long>& visitors, vector<long long>& habitat, vector<long long>& happ_ind, vector<long long>& all_sad, vector<long long>& all_happy...
### Prompt Your challenge is to write a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; long long h[100000 + 1], p[100000 + 1], good[100000 + 1], bad[100000 + 1], pass[100000 + 1]; vector<int> sonCity[100000 + 1]; long long n, m, t; bool dfs_adjudge(int nodeIndex, int parent) { pass[nodeIndex] = p[nodeIndex]; long long sumOfSonGood = 0, sumOfSonBad = 0...
### Prompt Construct a cpp code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int P[N], H[N], T[N], B[N], visited[N]; int dfs(vector<vector<int> >& E, int i) { visited[i] = 1; T[i] = P[i]; for (auto& it : E[i]) if (!visited[it]) T[i] += dfs(E, it); return T[i]; } int main() { ios_base::sync_with_stdio(false); in...
### Prompt In cpp, your task is to solve the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of an...
#include <bits/stdc++.h> using namespace std; const long long MXN = 2e5 + 10; long long q, n, m; long long P[MXN], H[MXN], Hap[MXN], Sad[MXN], sub[MXN]; bool NO = 0; vector<long long> adj[MXN]; inline bool check(long long x, long long t) { return (x >= 0 && x <= t); } void pre_dfs(long long u, long long par) { sub[u]...
### Prompt In cpp, your task is to solve the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of an...
#include <bits/stdc++.h> using namespace std; bool visited[100005]; vector<int> adj[100005]; int arr[100005]; int brr[100005]; long long flag; void bfs(int n) { long long val = 0; visited[n] = true; val -= arr[n]; for (int i = 0; i < adj[n].size(); i++) { if (!visited[adj[n][i]]) { bfs(adj[n][i]); ...
### Prompt Develop a solution in CPP to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; vector<long long> p(n), h(n); long long i; for (i = 0; i < n; i++) { cin >> p[i]; } for (i = 0; i < n; i++) { cin >> h[i]; } vector<vector<long long>> adj(n); for (i = 0; i < n - 1; i++) { long lo...
### Prompt Create a solution in cpp for the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of any...
#include <bits/stdc++.h> using namespace std; long long int n, m, k, x, u, v; vector<long long int> adj[100005]; long long int cnt[100005]; long long int h[100005]; long long int P[100005]; long long int S[100005]; long long int a[100005]; long long int b[100005]; string ans = ""; void reset() { for (long long int i ...
### Prompt Your task is to create a cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Cit...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; vector<int> gr[N]; bool access = true; int p[N], h[N], a[N], g[N]; void dfs(int v, int ancestor = -1) { a[v] = p[v]; int sum_g = 0; for (int to : gr[v]) { if (to == ancestor) continue; dfs(to, v); sum_g += g[to]; a[v] += a[to]; ...
### Prompt Construct a CPP code solution to the problem outlined: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of ...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; int *p; int *h; int *g; int *a; bool access = true; void dfs(int s, int ancestor = -1) { a[s] = p[s]; int s_g = 0; for (auto to : adj[s]) { if (ancestor == to) continue; dfs(to, s); s_g += g[to]; a[s] += a[to]; } int good =...
### Prompt Your challenge is to write a Cpp solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; int *p; int *h; int *g; int *a; bool access = true; void dfs(int s, int ancestor = -1) { if (!access) { return; } a[s] = p[s]; int s_g = 0; for (auto to : adj[s]) { if (ancestor == to) continue; dfs(to, s); s_g += g[to]; ...
### Prompt Please provide a Cpp coded solution to the problem described below: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities....
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, m, asd = 1; cin >> n >> m; vector<long long int> p(n + 5), h(n + 5), visited(n + 5); vector<long long int> edge[n + 5]; for (long long int i = 1; i <= n; i++) { cin >> p[i...
### Prompt Please formulate a CPP solution to the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens ...
#include <bits/stdc++.h> using namespace std; int n, m, ans; vector<int> a[100005]; int p[100005], h[100005], g[100005]; bool flag; void clean(int n) { flag = 1; for (int i = 0; i <= n + 1; i++) { a[i].clear(); g[i] = 0; } } void dfs(int x, int fa) { if (flag == 0) return; bool leaf = 1; int sumg = ...
### Prompt In Cpp, your task is to solve the following problem: Uncle Bogdan is in captain Flint's crew for a long time and sometimes gets nostalgic for his homeland. Today he told you how his country introduced a happiness index. There are n cities and nβˆ’1 undirected roads connecting pairs of cities. Citizens of an...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, n = 0; cin >> t; while (t--) { n = 0; cin >> a >> b; if (a == b) cout << 0 << '\n'; else { if (a > b) swap(a, b); n = (b - a) / 10; if ((b - a) % 10) n++; cout << n << '\n'; } } return 0; ...
### Prompt Construct a Cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int a, b; int main() { int t = 0; cin >> t; while (t--) { cin >> a >> b; if (b == a) cout << "0" << endl; if (b > a) { if ((b - a) % 2 != 0) cout << "1" << endl; if ((b - a) % 2 == 0) cout << "2" << endl; } if (a > b) { if ((a - b...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if (a > b) swap(a, b); int diff = b - a; int q = diff / 10; int rem = diff % 10; if (rem != 0) ++q; cout << q << endl; } return 0; }
### Prompt Create a solution in cpp for the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; long long int a, b; long long int val; if (t >= 1) while (t--) { cin >> a; cin >> b; if (a >= 1) { if (a == b) { cout << 0 << "\n"; ...
### Prompt Please create a solution in CPP to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; long long diff = abs(b - a); if ((diff % 10) != 0) cout << (diff / 10) + 1 << endl; else cout << diff / 10 << endl; } }
### Prompt Construct a CPP code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { long long a, b, ans, answer; scanf("%lld%lld", &a, &b); if (a == b) printf("0\n"); else if (a < b) { ans = b - a; answer = ans / 10; if (ans == answer * 10) printf("%lld\n", answer); e...
### Prompt Create a solution in Cpp for the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k i...
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { long long a, b; scanf("%lld %lld", &a, &b); if (a == b) printf("0\n"); else { if (a > b) { int y = a - b; int rem = y % 10; if (rem > 0) { printf("%d\n", ((y / 10) + 1)); ...
### Prompt In cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; for (int i = 1; i <= tc; i++) { int a, b; cin >> a >> b; if (a == b) cout << 0 << endl; else if (a > b) cout << (a % 2 == b % 2 ? 1 : 2) << endl; else cout << (a % 2 != b % 2 ? 1 : 2) << endl; } ...
### Prompt In cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, n; scanf("%d", &t); for (int i = 0; i < t; ++i) { scanf("%d %d", &a, &b); n = abs(a - b); n % 10 == 0 ? printf("%d\n", n / 10) : printf("%d\n", n / 10 + 1); } return 0; }
### Prompt Generate a cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, a, b, x; cin >> t; while (t--) { cin >> a >> b; if (a == b) { cout << 0 << endl; continue; } if (a < b) { x = (b / 10) - (a / 10); } else { x = (a / 10) - (b / 10); } if (a + x * 10 < b || b...
### Prompt Your task is to create a Cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different v...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b, temp, ans; cin >> a >> b; temp = abs(a - b); if (temp % 10 == 0) { ans = temp / 10; cout << ans << "\n"; } else { ans = temp / 10 + 1; cout << ans << ...
### Prompt In Cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; int cae = 1; long long prime[1000000]; void sieve() { prime[0] = 0; prime[1] = 0; for (int i = 2; i < 1000000; i++) prime[i] = 1; for (int i = 2; i * i < 1000000; i++) if (prime[i] == 1) for (int j = i * i; j < 1000000; j += i) prime[j] = 0; } bool isPrime...
### Prompt Please create a solution in cpp to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values ...
#include <bits/stdc++.h> int main() { int t, i; long a, b, c, d; scanf("%d\n", &t); for (i = 0; i < t; i++) { scanf("%ld %ld", &a, &b); if (a < b) { c = b - a; if (c % 2 != 0) d = 1; else d = 2; } else if (a == b) { d = 0; } else if (a > b) { c = a ...
### Prompt Your challenge is to write a cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; void readArray(vector<ll> &arr); void solve() { ll a, b; cin >> a >> b; if (a == b) { cout << "0\n"; return; } ll diff = abs(a - b); if (diff <= 10) { cout << "1\n"; return; } ll ans = (diff / 10); if (diff % 10 != 0) an...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b; int cnt = 0; cin >> a >> b; long long d = abs(a - b); if (d % 10 == 0) { cout << d / 10 << endl; } else { cout << d / 10 + 1 << endl; } } return 0; }
### Prompt Generate a Cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; if (a == b) cout << "0" << endl; if (b > a && (b - a) % 2 == 1) cout << "1" << endl; if (b > a && (b...
### Prompt Construct a Cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long int x = b - a, ans; if (x > 0) { if (x % 2 == 0) ans = 2; else ans = 1; } else if (x < 0) { if (x % 2 == 0) ...
### Prompt Construct a Cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int solve(int a, int b) { if (a == b) return 0; if (a < b) { if ((a & 1) == (b & 1)) return 2; else return 1; } else { if ((a & 1) == (b & 1)) return 1; else return 2; } } int main() { int t; cin >> t; while (t--) { ...
### Prompt Your challenge is to write a CPP solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int a, b; int C; int odd = 1, even = 0; cin >> C; while (C--) { cin >> a >> b; if (a == b) { cout << 0 << "\n"; } else if (a < b) { int k = b - a; if (k % 2 == odd) { cout << 1 << "\...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int t, a, b; int main() { cin >> t; while (t--) { cin >> a >> b; int k = abs(b - a); if (k % 10 > 0) cout << k / 10 + 1 << endl; else cout << k / 10 << endl; } return 0; }
### Prompt Please create a solution in cpp to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values ...
#include <bits/stdc++.h> int main() { int e, f; int t; scanf("%d", &t); while (t--) { scanf("%d%d", &e, &f); if (e == f) { printf("0\n"); } else if (e < f) { if ((e - f) & 1) { printf("1\n"); } else printf("2\n"); } else { if ((e - f) % 2 == 0) { p...
### Prompt In Cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t, d = 0; cin >> t; while (t--) { long long a, b, c = 0, d; cin >> a >> b; if (a > b) { d = a - b; if (d % 10 != 0) { c = (d / 10) + 1; } else { c = (d / 10) ...
### Prompt Please provide a cpp coded solution to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int T; int a, b; int main() { cin >> T; while (T--) { cin >> a >> b; if (a > b) { swap(a, b); } cout << (b - a) / 10 + (bool)((b - a) % 10) << endl; } }
### Prompt Construct a Cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long diff = abs(a - b); long long ans = diff / 10; if (diff % 10 == 0) cout << ans << endl; else cout << ans + 1 << endl; } return 0; }
### Prompt In CPP, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; const int nxN = 64; int a, b; void solve() { cin >> a >> b; int c = 0; int t; if (a != b) { if (a > b) { t = a; a = b; b = t; } b = b - a; c = b / 10; c = b % 10 != 0 ? c + 1 : c; } cout << c << endl; } int main() { ios::s...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int inp() { int x; cin >> x; return x; } void solve() { int a, b; cin >> a >> b; cout << abs(a - b) / 10 + (abs(a - b) % 10 != 0); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); int T = 1; cin >> T; while (T--) { ...
### Prompt Construct a cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30); unsigned long long __gcd(unsigned long long a, unsigned long long b) { return b == 0 ? a : __gcd(b, a % b); } unsigned long long __lgput(unsigned long long a, unsigned long long b) { unsigned long long res = 1; while (b) { if (b & 1) res...
### Prompt Please provide a CPP coded solution to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> int abs(int a) { return (a < 0) ? (-1) * a : a; } int main() { int T, a, b; int x; scanf("%d", &T); while (T--) { scanf("%d %d", &a, &b); x = abs(b - a); printf("%d\n", (x % 10 != 0) ? x / 10 + 1 : x / 10); } return 0; }
### Prompt Develop a solution in Cpp to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values ...
#include <bits/stdc++.h> using namespace std; int main() { long long test, b, d; cin >> test; while (test--) { cin >> b >> d; long long move = 0, temp = 0, sub; sub = abs(b - d); if (sub % 10 != 0) { move = sub / 10 + 1; } else { move = sub / 10; } cout << move << "\n"; }...
### Prompt In cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("-ffloat-store") long long isprime(long long a) { long long p = 0; for (long long i =...
### Prompt In CPP, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long z = 1000000000; const long long N = 1e5 + 1; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ost...
### Prompt In CPP, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> int main() { int n, a, b, i, def; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &a, &b); if (a == b) printf("0\n"); if (a > b) { def = a - b; if (def % 2 == 0) printf("1\n"); else printf("2\n"); } if (a < b) { def = b ...
### Prompt Construct a cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; int step = abs(a - b); cout << ((step + 9) / 10) << "\n"; } return 0; }
### Prompt Construct a cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, n; cin >> t; for (int i = 0; i < t; ++i) { cin >> a >> b; n = abs(a - b); n % 10 == 0 ? cout << n / 10 << endl : cout << n / 10 + 1 << endl; } return 0; }
### Prompt Your challenge is to write a cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a, b; cin >> a >> b; long long int ans = abs(a - b) / 10; if (abs(a - b) % 10 != 0) ans++; cout << ans << endl; } return 0; }
### Prompt In cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long a, b, res = 0; cin >> a >> b; long long x = abs(b - a); for (int i = 10; i >= 1; i--) { if (x > 0) { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long a, b; cin >> a >> b; cout << (abs(a - b) + 9) / 10 << "\n"; } return 0; }
### Prompt Construct a cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; int ans = (abs(a - b) + 9) / 10; cout << ans << endl; } return 0; }
### Prompt In cpp, your task is to solve the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int exp(long long int x, long long int y) { long long int res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } long long int modinv(long long int x...
### Prompt Construct a CPP code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; void setIO(string name = "contest") { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } ll MOD = 1000000007...
### Prompt Generate a CPP solution to the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k in ...
#include <bits/stdc++.h> const int INF = 1e+9, MAXN = 5005, HELL = 1e+9 + 7; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t, a, b; cin >> t; for (int i = 0; i < t; ++i) { cin >> a >> b; if (a > b) { if ((a - b) % 2 == 0) { cout << "1\n"; } else { ...
### Prompt Create a solution in CPP for the following problem: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of k i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int a, b; cin >> a >> b; if (a == b) { cout << 0 << endl; } else if (a > b) { if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0)) { cout << 1 << endl; } else { cout...
### Prompt Construct a cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, t; cin >> t; while (t--) { cin >> a >> b; c = ceil(abs(a - b) / 10.0); cout << c << endl; } return 0; }
### Prompt Please provide a CPP coded solution to the problem described below: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use differe...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; void solve(int a, int b) { int y = min(a, b); int z = max(a, b); int x = z - y; int counter = 0; counter += x / 10; if (x % 10 != 0) { counter++; } cout << counter << endl; } int main() { int t; cin >> t; int a, b; while (t--) ...
### Prompt Construct a Cpp code solution to the problem outlined: You are given two integers a and b. In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k ∈ [1; 10] and perform a := a + k or a := a - k. You may use different values of ...