output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(int n, int pos) { return (bool)(n & (1 << pos)); }
inline int countBit(long long n) { return __builtin_popcountll(n); }
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
const int MAX = 100010;
vector<int> ed[MAX]... | ### Prompt
Generate a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 61);
const int MX = 3e5 + 9;
int n, sub[MX], depth[MX], blocked[MX], par[MX], sz[MX], dis[MX], vis[MX];
long long ans = 0;
vector<int> v[MX];
void dfs(int x, int p, int d = 0) {
par[x] = p;
dis[x] = d;
for (auto pp : v[x]) {
if (pp ==... | ### Prompt
In CPP, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
struct edge_t {
int v, w, next_id;
edge_t(int _v, int _w, int _next_id) : v(_v), w(_w), next_id(_next_id) {}
};
void add_edge(vector<int>& LE, vector<edge_t>& E, int v, int w) {
E.push_back(edge_t(v, w, LE[v]));
LE[v] = E.size() - 1;
}
bool multihedgehog(int n, vect... | ### Prompt
Construct a cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647;
const long long Inf = 9223372036854775807ll;
const string file = "";
int n, m, g[100005], g2[100005], c[100005], d[100005];
vector<int> v[100005];
queue<int> q;
bool ok[100005];
void dfs(int x, int pred = 0) {
ok[x] = 0;
d[x] = d[pred] + 1;
... | ### Prompt
Generate a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
vector<int> dis[100002];
vector<int> v[100002];
int don[100002] = {0};
int ans = 0;
int dfs(int r) {
int i;
int maxx = 0;
don[r] = 1;
for (i = 0; i < v[r].size(); i++) {
if (don[v[r][i]] == 0) {
int d = dfs(v[r][i]);
maxx = max(maxx, d);
dis[r]... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > mv;
int cen, k;
int bus(int cu, int fa) {
int i, s = mv[cu].size(), b, ma = 0;
for (i = 0; i < s; i++)
if (mv[cu][i] != fa) {
b = bus(mv[cu][i], cu);
if (b == k) cen = cu;
if (b > ma) ma = b;
}
return ma + 1;
}
bool che(i... | ### Prompt
In CPP, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<vector<int>> graph;
int N, K;
int next(int v, int p) {
int n = 0;
if (graph[v][0] == p) {
n = 1;
}
return graph[v][n];
}
struct itframe {
int v;
int p;
vector<int> bestd;
int pc;
int i;
int u;
};
vector<int> rec(int v, in... | ### Prompt
Construct a cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> adj[(int)1e5 + 7];
int vis[(int)1e5 + 7];
int deg[(int)1e5 + 7];
int cnt[(int)1e5 + 7];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
scanf("%d %d", &n, &k);
for (int i = 1; i <= n - 1; i++) {
int u, v;
scanf("%d... | ### Prompt
Develop a solution in cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
const int lim = 1e5 + 5;
long long n, k, u, v, cn;
map<long long, long long> deg;
set<long long> adj[lim];
int main() {
cin >> n >> k;
for (int i = 1; i <= n - 1; i++) {
cin >> ... | ### Prompt
Develop a solution in CPP to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, maxn = 1e5 + 213, N = 4e6 + 20, mod = 998244353;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const double eps = 1e-5, pi = 3.14159265359;
const pair<unsigned long long, unsigned long long> base = make_pair(1171, 3307);
const long long INF = 1e... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double PI = acos(-1);
long long fast_exp(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1LL) {
res *= a;
res %= 1000000007;
}
b >>= 1LL;
a *= a;
a %= 1000000007;
}
return res;
}
vec... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N];
int way[N], d[N], deg[N], n, k;
bool used[N];
bool dfs(int v, int lvl, int p) {
if (lvl == 0) {
if (deg[v] < 3) return 1;
return 0;
} else if (deg[v] < 3)
return 0;
bool ret = 1;
for (auto u : adj[v]) {
if (... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int mod = (1e9) + 7;
const double eps = 1e-10;
const int siz = 1e5 + 5, siz2 = 18, siz3 = 5032108;
int n, k, deg[siz], del[siz];
vector<int> adj[siz], temp;
queue<int> cur;
bool vis[siz];
int main() {
scanf("%d%d", &n, &k);
for (int i = ... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
int n, k;
std::vector<std::vector<int> > g;
std::vector<int> par, lev;
void fail() {
std::cout << "No\n";
std::exit(0);
}
void dfs(int v) {
for (auto &ch : g[v]) {
if (par[v] == ch) continue;
par[ch] = v;
lev[ch] = lev[v] + 1;
dfs(ch);
}
}
void dfs2(int v, int p, int l) ... | ### Prompt
Please formulate a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
int n, k;
cin >> n >> k;
set<int> s[n + 1];
set<int> ss;
for (i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
s[x].insert(y);
s[y].insert(x);
}
for (i = 1; i <= n; i++) {
ss.insert(i);
}
int loop = 0;
while (ss.... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<vector<int> > g(n);
vector<int> degree(n);
for (int i = 0, u, v; i < n - 1; i++) {
... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, Mod = 1e9 + 7, MAXN = 1e5, Lg = 27, M = 1e7 + 10,
P = 727, Sq = 320;
const long long inf = 3e18 + 10;
int n, k, Root, Deg[N], Dis[N], Was[N];
set<pair<int, int> > second;
vector<int> Adj[N], V[N];
vector<pair<int, int> > T;
inline void Print... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
int GEIS(set<int> s) {
for (int i : s) {
return i;
}
}
int main() {
int N, M;
cin >> N >> M;
vector<set<int>> ss(N);
for (int i = 0; i < N - 1; i++) {
int u, v;
cin >> u >> v;
ss[u - 1].insert(v - 1);
ss[v - 1].insert(u - 1);
}
if (M > 11... | ### Prompt
Please formulate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int n, k;
vector<int> g[N];
vector<pair<int, int> > bfs(int src) {
vector<pair<int, int> > dist(n, {1e9, -1});
dist[src] = {0, -1};
queue<int> q;
q.push(src);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int y : g[x])
... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100001];
bool visit[100001];
int dist[100001];
int dig[100001];
int child[100001];
void dfs(int x) {
visit[x] = true;
for (int i = 0; i < v[x].size(); i++) {
if (!visit[v[x][i]]) {
dist[v[x][i]] = dist[x] + 1;
dfs(v[x][i]);
child[x] +... | ### Prompt
Please formulate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
if (y < x) x = y;
};
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
if (y > x) x = y;
};
const int N = 100005;
int n;
set<int> G[N];
int deg[N];
void die() {
cout << "No\n";
... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
vector<int> g[maxn];
set<int> g_dic[maxn];
int dep[maxn], k;
bool ok = true;
void dfs(int u, int fa) {
if (dep[u] == k) {
if (g[u].size() != 1) ok = false;
} else {
if (g[u].size() - (fa == -1 ? 0 : 1) < 3) ok = false;
}
for (int i =... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const long long N = (1e5) + 322;
const long long INF = (long long)(1e12);
const long long mod = 998244353;
const double eps = 1e-9;
int n, k, deg[N], dp[N], par[N];
vector<int> v[N];
queue<int> q;
void dfs(int x, int p = -1) {
int cnt = 0;
for (auto it : v[x]) {
if ... | ### Prompt
In cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
int n, k, root;
bool visited[1000003];
vector<int> vec[100003];
queue<int> q;
void dfs(int u, int jar) {
visited[u] = 0;
int cnt = 0;
for (int v : vec[u])
if (visited[v]) dfs(v, jar + 1), ++cnt;
if (jar == k) {
if (cnt) {
printf("No\n");
exit(0);... | ### Prompt
Construct a cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const long long INF = 1e16 + 17;
const int N = 1e5 + 7;
bool us[N];
vector<int> g[N], gv[N];
int cnt, is_ok[N];
void first(int v, int id) {
++is_ok[v];
if (us[v]) return;
int pr = 0;
for (int i = 0; i < (int)g[v].size(); ++i) {
int to ... | ### Prompt
Please create a solution in CPP to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
int p[100000];
int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }
void unite(int a, int b) {
if (a % 2 == 0) swap(a, b);
p[find(a)] = find(b);
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<set<int>... | ### Prompt
Please create a solution in cpp to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
int vis[maxn];
vector<int> g[maxn], now;
int flag, root, ok;
void addedge(int u, int v) { g[u].push_back(v); }
void dfs(int u, int fa) {
vis[u] = 1;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (v != fa) {
if (vis[v]... | ### Prompt
Develop a solution in CPP to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
stream << "]";
return stream;
}
long long fpow(long long x, long long p, long long m) {
long long r = 1;
f... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 2e9 + 5;
int lose() {
cout << "No\n";
return 0;
}
int win() {
cout << "Yes\n";
return 0;
}
int main() {
cin.tie(0), ci... | ### Prompt
In cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
vector<int> adj[maxn];
int deg[maxn], dep[maxn], cnt[maxn];
bool vis[maxn];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
adj[u].push_back(v);
deg[u]++;
adj[v]... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and d... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > Graph;
vector<int> Degree;
vector<int> Parent;
vector<int> Dist;
void Diameter(int node, int depth = 0, int parent = 0) {
if (Parent[node] != -1) return;
Dist[node] = depth;
Parent[node] = parent;
for (int i = 0; i < Graph[node].size(); i++) {
... | ### Prompt
Develop a solution in CPP to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 1e5;
vector<int> g[N];
int k, dp1[N], dp2[N];
void dfs1(int v, int p) {
if (g[v].size() > 1) {
dp1[v] = INF;
for (auto u : g[v])
if (u != p) {
dfs1(u, v);
dp1[v] = min(dp1[u] + 1, dp1[v]);
}
}
}
void... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | ### Prompt
Generate a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-8;
const int N = 1e5 + 10;
const int M = 2e2 + 10;
int n, k;
vector<int> g[N];
void NO() {
cout << "NO\n";
exit(0);
}
int center;
pair<int, int> dfs(int u, int d, int fa = -1) ... | ### Prompt
Please formulate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int n, k, a, b;
int depth[N], parent[N];
bool used[N];
vector<int> v[N];
void dfs(int curr, int prev, int d) {
depth[curr] = d;
parent[curr] = prev;
used[curr] = 1;
for (int i : v[curr]) {
if (!used[i]) {
dfs(i, curr, d + 1);
}
... | ### Prompt
In CPP, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k;
vector<int> g[N];
int from[N], lev[N];
vector<int> path;
void dfs(int u, int p) {
for (int v : g[u])
if (v != p) {
lev[v] = lev[u] + 1;
from[v] = u;
dfs(v, u);
}
}
int main() {
ios_base::sync_with_stdio(false);
... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
long long int ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
vector<long long int> v[100009];
bool check(long long int num) { return v... | ### Prompt
Develop a solution in cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
set<int> v[N], d1;
int d[N];
bool vis[N];
int main() {
int n, k, x, y;
cin >> n >> k;
int c2 = 0, c3 = 0;
for (int i = 1; i < n; i++) {
cin >> x >> y;
v[x].insert(y);
v[y].insert(x);
d[x]++;
d[y]++;
if (d[x] == 1) d1.ins... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
using Long = long long;
vector<vector<int>> G(100010);
int D[100010];
int dist[100010];
int P[100010];
int ep1 = -1, ep1lvl = -1, ep2 = -1, ep2lvl = -1;
void dfs(int u, int p, int lvl) {
if (lvl > ep1lvl) {
ep1lvl = lvl;
ep1 = u;
}
for (auto v : G[u]) {
if... | ### Prompt
Please formulate a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using ld = long double;
mt19937 rnd(time(nullptr));
const int inf = 1e9;
int n = 0, k = 0;
vector<vector<int>> data;
vector<int> leaves;
void DFS1(int v, int p) {
for (int u : data[v]) {
if (u != p) DFS1(u, v);
}
if (data[v].size() == 1) lea... | ### Prompt
Develop a solution in cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
long long int vis[N], sz[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
vector<long long int> G[n + 1];
for (long long int i = 0; i < n - 1; ++i) {
long ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename H, typename... T>
void debug_out(H h, T... t) {
cerr << " " << (h);
debug_out(t...);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> degree(n);
vector<... | ### Prompt
Create a solution in Cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
vector<int> FindCenter(vector<vector<int>>& G) {
int c = 1;
vector<int> P;
queue<int> q;
for (int j = 0; j < 2; j++) {
P.assign(G.size(), -1);
P[c] = c;
q.push(c);
while (!q.empty()) {
c = q.front();
q.pop();
for (auto& u : G[c])
... | ### Prompt
In Cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int h[N], e[N], ne[N], idx, v[N], d[N], res[N];
queue<int> q;
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int main() {
memset(h, -1, sizeof h);
int n, k;
cin >> n >> k;
for (int i = 1; i < n; i++) {
int a, b;
... | ### Prompt
Please formulate a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
vector<set<int> > gr;
vector<vector<int> > gr1;
int deg[300010];
queue<int> ls;
bool iskhg(int u, int k, int par) {
if (k < 0) {
return 0;
}
if (gr1[u].size() == 1) {
return k == 0;
}
bool res;
if (par == -1) {
res = deg[u] > 2;
} else
res = de... | ### Prompt
Develop a solution in Cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
long long n, k, u, v;
cin >> n >> k;
vector<set<long long>> graph(n);
for (long long i = 1; i < n; ++i) {
cin >> u >> v;
--u;
--v;
graph[u].insert(v);
graph[v].insert(u);
}
set<long long> ye... | ### Prompt
Create a solution in Cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 100005;
int i, n, k, x, y, lvl[N];
vector<int> g[N];
queue<int> q;
int main() {
ios_base::sync_with_stdio(0);
memset(lvl, -1, sizeof(lvl));
cin >>... | ### Prompt
Your task is to create a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and d... |
#include <bits/stdc++.h>
using namespace std;
int n, k, br[100005];
set<int> ms[100005], s[2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
ms[u].insert(v);
ms[v].insert(u);
}
for (int i = ... | ### Prompt
Create a solution in cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
vector<int> adj[N];
int rnk[N], par[N];
void dfs(int u, int p = -1) {
par[u] = p;
for (auto &x : adj[u]) {
if (x == p) continue;
rnk[x] = rnk[u] + 1;
dfs(x, u);
}
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int st[100005];
vector<int> g[100005];
bool dfs(int v, int pred, int d) {
if (d > k) return 0;
if (g[v].size() == 3 && pred != -1) return 0;
if (g[v].size() == 1 && d != k) return 0;
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (pre... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void println(const T &t) {
cout << t << '\n';
}
template <typename T, typename... Args>
void println(const T &t, const Args &...rest) {
cout << t << ' ';
println(rest...);
}
template <typename T>
void print(const T &t) {
cout << t << ' ';
}
tem... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 3;
int n, m, a, b, i, nivmax, jman[nmax], haida[nmax], fol[nmax];
vector<int> t2[nmax], t1[nmax], haicaca[nmax];
void usurelu(int nod, int niv);
string p1 = "Yes";
string p2 = "No";
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (i... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, k;
vector<int> g[100100];
int deg[200200];
int dep[200200];
int par[200200];
void dfs(int node, int p, int d) {
par[node] = p;
dep[node] = d;
for (auto v : g[node]) {
if (v == p) continue;
dfs(v, node, d + 1);
}
}
void solve() {
... | ### Prompt
Create a solution in cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
const int N = 1e5 + 5;
int n, K, Enum, H[N], nxt[N << 1], to[N << 1], dis[N], pre[N], dgr[N];
inline int read() {
int now = 0;
register char c = getchar();
for (; !isdigit(c); c = getchar())
;
for (; isdigit(c); now = now * 10 + c - '0', c = getchar())
;
return now;
}
inline v... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, deg[N], mn = 1e9, mx, dep[N];
vector<int> adj[N];
void dfs(int x, int p = -1) {
if (adj[x].size() == 1) mn = min(mn, dep[x]);
mx = max(mx, dep[x]);
for (auto& u : adj[x]) {
if (u == p) continue;
dep[u] = dep[x] + 1;
dfs(u, ... | ### Prompt
Create a solution in Cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int INF = INT_MAX;
const long long INFLL = (long long)1e18;
const double PI = acos(-1.0);
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gc... | ### Prompt
Create a solution in Cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename Args>
void kill(Args args) {
cout << args << "\n";
exit(0);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
const long lo... | ### Prompt
Construct a cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int eo[N], *ej[N], qu[N];
int d_, i_, cnt;
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *)realloc(ej[i], (o << 1) * sizeof *ej[i]);
ej[i][o] = j;
}
void dfs1(int p, int i, int d) {
if (d_ < d) d_... | ### Prompt
Generate a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const long long MAXN = (long long)1e5 + 10;
const long long MOD = (long long)998244353;
const long double EPS = (long double)1e-10;
long long power(long long x, long long n, long long mod = 1e9 + 7) {
if (n == 0) return 1ll;
if (n ... | ### Prompt
Generate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make... |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> sz;
vector<int> used;
int k, ind;
queue<int> q;
void dfs_x(int v, int p = -1) {
for (int to : g[v]) {
if (to == p) continue;
dfs_x(to, v);
}
if (g[v].size() == 1) {
used[v] = 0;
q.push(v);
}
}
void bfs_x() {
whil... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100010], path;
int n, k, dist[100010], from[100010];
void dfs(int s, int p) {
for (int v : G[s]) {
if (v != p) {
from[v] = s;
dist[v] = dist[s] + 1;
dfs(v, s);
}
}
}
int main() {
int i;
cin >> n >> k;
for (i = 0; i < n - 1; ... | ### Prompt
In cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
vector<int> arr[100005];
vector<bool> v;
int k;
bool dfs(int curr, int depth) {
if (depth > k) return false;
bool f = false;
for (int i = 0; i < arr[curr].size(); i++) {
int next = arr[curr][i];
if (!v[next]) {
v[next] = true;
if (!dfs(next, depth ... | ### Prompt
Create a solution in CPP for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, k, a, b, hMax = 0, K = 0, g;
cin >> n >> k;
int S[n], G[n], H[n];
vector<int> D[n], T;
for (int i = 0; i < n; i++) {
S[i] = 0;
G[i] = 1;
H[i] = -1;
}
for (int i = 0; i < n - 1; i++) {
cin >> a ... | ### Prompt
Please create a solution in CPP to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
int n, k;
basic_string<int> e[100005];
int d[100005], p[100005];
bool ok = true;
void bfs(int x) {
fill(d + 1, d + n + 1, 1123123123);
d[x] = 0;
p[x] = x;
queue<int> q;
q.push(x);
while (q.size()) {
int x = q.front();
q.pop();
for (int y : e[x]) {
... | ### Prompt
Please formulate a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
int n, k;
int sz[maxN], h[maxN];
bool flag = false;
vector<int> g[maxN];
void ReadInput() {
cin >> n >> k;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
}
int Get_root() {
que... | ### Prompt
Develop a solution in Cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int depth[100005];
int mx_depth[100005];
int lev[100005];
int node;
int k;
void dfs(int u, int par) {
for (auto v : adj[u]) {
if (v == par) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
mx_depth[u] = max(mx_depth[u], mx_depth[v]);
... | ### Prompt
Please create a solution in Cpp to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
bool u[N];
vector<int> g[N], st;
int deg[N], cnt[N];
inline bool check(int v, int k, int p = 0) {
if (k == 0) {
return g[v].size() == 1;
}
int wow = 0;
for (auto to : g[v]) {
if (to == p) continue;
if (check(to, k - 1, v)) {
... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and d... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int fa[maxn];
int head[maxn], nxt[maxn], to[maxn], cnt;
int d[maxn], son[maxn];
int n, k;
void init() {
cnt = 0;
fill(head, head + n + 1, -1);
fill(d, d + n + 1, 0);
}
void add(int u, int v) {
to[cnt] = v;
nxt[cnt] = head[u];
head[u] =... | ### Prompt
Construct a cpp code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
int MOD(int a, int b) {
if (a > b)
return a - b;
else
return b - a;
}
long long int max3(long long int a, long long int b, long long int c) {
return max(c, max(a, b));
}
long long int power(long long int x, long long int y, long long int p) {
long long int r... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 10;
int n, k;
vector<int> G[MAX_N];
bool mark[MAX_N];
int dis[MAX_N];
vector<int> best, path;
int maxx = -1;
void dfs(int u) {
path.push_back(u);
mark[u] = 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (mark[v]) {
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and d... |
#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(l... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
const int N1 = 200005;
const int inf = 0x3f3f3f3f;
struct Edge {
int to[N1], nxt[N1], head[N1], cte;
void ae(int u, int v) {
cte++;
to[cte] = v;
nxt[cte] = head[u];
head[u] = cte;
}
} e;
int n, K;
int deg[N1], b[N1], h[N1];
int vis[N1], que[N1], hd, tl... | ### Prompt
In cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
queue<int> q;
vector<int> g[100010];
int ind[100010], dep[100010], dd[100010];
int main() {
int n, K, x, y;
cin >> n >> K;
K++;
for (int i = (2); i <= (n); i++) {
scanf("%d%d", &x, &y);
... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring a... |
#include <bits/stdc++.h>
using namespace std;
int n, m, f = 1;
vector<vector<int> > g;
vector<int> deg, vis, par, dep;
void dfs(int node, int parent, int depth) {
vis[node] = 1;
par[node] = parent;
dep[node] = depth;
for (auto v : g[node]) {
if (v != parent) dfs(v, node, depth + 1);
}
}
int dfs2(int node,... | ### Prompt
Develop a solution in cpp to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<vector<int> > adjlist;
vector<bool> visited;
int dist[MAX], par[MAX];
void dfs(int node, int parent) {
visited[node] = 1;
if (parent != -1) dist[node] = dist[parent] + 1;
par[node] = parent;
for (int i = 0; i < adjlist[node].size(); +... | ### Prompt
In cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
inline void smax(int &x, int y) { x = max(x, y); }
inline void smin(int &x, int y) { x = min(x, y); }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
int n, k;
vector<vector<int> > gr;
vector<int> v... | ### Prompt
Construct a CPP code solution to the problem outlined:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void println(const T &t) {
cout << t << '\n';
}
template <typename T, typename... Args>
void println(const T &t, const Args &...rest) {
cout << t << ' ';
println(rest...);
}
template <typename T>
void print(const T &t) {
cout << t << ' ';
}
tem... | ### Prompt
In Cpp, your task is to solve the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to m... |
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, set<int>> g;
bool f(int k) {
if (k == 0) {
if (g.size() == 1) {
return true;
} else {
return false;
}
} else {
map<int, int> kek;
vector<int> fd;
for (const auto& e : g) {
if (e.second.size() == 0) {
retu... | ### Prompt
Develop a solution in CPP to the problem described below:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k, mx, cen, leaf = -1, mark[N], cnt[N];
bool ans = 1;
vector<int> adj[N];
queue<pair<int, int> > que;
void bfs(int v, int c) {
if (mark[v]) return;
mark[v] = c;
if (c > mx) {
mx = c;
cen = v;
}
for (int i : adj[v])
if (!m... | ### Prompt
Please create a solution in cpp to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100005];
long long dg[100005], sk[100005], n, k;
bool vis[100005];
int32_t main() {
scanf("%lld%lld", &n, &k);
for (long long i = 1; i < n; i++) {
long long x, y;
cin >> x >> y;
dg[x]++, dg[y]++;
adj[x].push_back(y);
adj[y].push... | ### Prompt
Please formulate a cpp solution to the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided... |
#include <bits/stdc++.h>
using namespace std;
int st[100001], col[100001], ss[100001];
bool use[100001];
vector<int> ed[100001];
int main() {
ios_base::sync_with_stdio(0);
queue<int> q;
int n, k, u, v;
cin >> n >> k;
for (int i = 0; i < n - 1; ++i) {
cin >> u >> v;
--u;
--v;
ed[u].push_back(v)... | ### Prompt
Create a solution in cpp for the following problem:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to ma... |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
long long n;
cin >> n;
long long m;
cin >> m;
vector<set<long long> > adj(n);
for (long long i = 0; i < n; ++i) adj[i].insert(i);
for (long long o = 0; o < m; o++) {
lon... | ### Prompt
Create a solution in cpp for the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparison... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_wit... | ### Prompt
In Cpp, your task is to solve the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the compariso... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
return __builtin_popcoun... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results o... |
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
set<int> q[100005];
int main() {
int n, m, g, h;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &g, &h);
if (g > h) {
int temp = g;
g = h;
h = temp;
}
q[g].insert(h);
}
for (int i = 1... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comp... |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> maps;
const int maxn = 1e5 + 5;
vector<int> G[maxn];
int a[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0, u, v; i < m; i++) {
scanf("%d%d", &u, &v);
maps[make_pair(u, v)] = 1;
maps[make_pair(v, u)] = 1;
}
... | ### Prompt
Create a solution in cpp for the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparison... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> V[maxn];
int n, m, ans1[maxn], ans2[maxn], cnt;
bool vis[maxn];
int main() {
cin >> n >> m;
int x, y;
for (int i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
V[x].push_back(y);
}
x = -1, y = -1... | ### Prompt
Your task is to create a CPP solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of th... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 2e9 + 9;
const long long INF1 = 1e18 + 9;
const long long MAXN = 4e5 + 7;
const long long MAXN1 = 1 << 11;
const long long MAXN2 = 4e6 + 9;
const long long MOD = 1e9 + 7;
const long long MOD1 = 1e9 + 9;
const long long ALPH = 50... | ### Prompt
Your task is to create a Cpp solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of th... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
x = 0;
short f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x *= f;
}
template <class T>
inlin... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results o... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
out << "[";
for (const T& x : v) {
out << v << ", ";
}
out << "]";
return out;
}
template <typename T, typename S>
ostream& operator<<(ostream& out, const pair<T, S>& p) {
out << "... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results o... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, k, u, v;
int a[N], b[N];
set<int> s[N];
int main() {
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> u >> v;
s[u].insert(v);
s[v].insert(u);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i != ... | ### Prompt
Create a solution in Cpp for the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparison... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
vector<vector<long long> > al(n, vector<long long>());
if (2 * m >= (n * (n - 1))) {
cout << "NO" << endl;
return 0;
}
vector<long long> deg(n, 0);
for (int i = 0;... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results o... |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[100005], b[100005];
set<int> s[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
while (m--) {
cin >> x >> y;
s[x].insert(y);
s[y].insert(x);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) ... | ### Prompt
Develop a solution in CPP to the problem described below:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comp... |
#include <bits/stdc++.h>
using namespace std;
void solve(int x, int y, int n) {
vector<int> ans(n + 1);
ans[x] = 1;
ans[y] = 2;
for (int i = 1, j = 3; i <= n; i++) {
if (ans[i] == 0) {
ans[i] = j++;
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
cout << '\n';
ans[y] = 1;... | ### Prompt
Create a solution in Cpp for the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparison... |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 1e5 + 5;
vector<... | ### Prompt
In cpp, your task is to solve the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the compariso... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<set<int>> a;
int main() {
cin >> n >> m;
a.resize(n);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
a[x - 1].insert(y - 1);
a[y - 1].insert(x - 1);
}
if (n == 1) {
cout << "NO" << endl;
return 0;
}
int minidx =... | ### Prompt
Construct a cpp code solution to the problem outlined:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the compari... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 998244353;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-7;
inline long long read() {
long long X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch ... | ### Prompt
Please create a solution in Cpp to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comp... |
#include <bits/stdc++.h>
using namespace std;
set<long long> adj[100003];
int a[100002];
int b[100002];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
adj[x].insert(y);
adj[y].inse... | ### Prompt
In cpp, your task is to solve the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the compariso... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
int n, k, x, y;
int a[maxn], b[maxn];
bool used[maxn];
vector<int> adj[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
if (n == 1 || n == 2) {
if (n == 2 && k == 0) {
cout << "YES\n1 2\n1 1\n";
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results o... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, t1, t2, a[100005], b[100005];
unordered_set<long long> g[100005];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (long long i = 1; i <= m; ++i) {
cin >> t1 >> t2;
g[t1].insert(t2);
g[t2].insert(t1);
}
for (lon... | ### Prompt
Your task is to create a cpp solution to the following problem:
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of th... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.