Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class template { public static void main(String[] args) throws Exception { new template().run(); } public void run() throws Exception { FastScanner f = new FastScanner(); PrintWriter out = new...
JAVA
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
import java.io.*; import java.util.*; public class Solution { int bound = 100000; private void solve() throws Exception { powers = new HashSet<Integer>(); int pow = 1; while(pow-1 <= bound) { powers.add(pow-1); pow = pow*2; } int n = nextIn...
JAVA
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, K, ans[100004]; int lowb(int x) { return x & -x; } int main() { scanf("%d%d", &n, &K); if (n % 2 == 0) return puts("NO"), 0; if (max(0, (n - 3) / 2) < K) return puts("NO"), 0; if (n == 9 && K == 2) return puts("NO"), 0; if (lowb(n + 1) == n + 1 && K == 1) r...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int ans[200010]; int main() { int a, b; cin >> a >> b; if (a % 2 == 0) { printf("NO"); return 0; } if (b == 0) { int k = a + 1; while (k % 2 == 0) k /= 2; if (k == 1) { printf("YES\n"); for (int i = 1; i <= a; i++) printf("%d ", i /...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int ncnt; int anc[N], lg2[N]; bool Check(int n, int m) { if (n == 1 && m == 0) return true; if (m < 0 || n < 0) return false; if (n == 9 && m == 2) return false; if (((n + 1) & (-(n + 1))) == n + 1 && m == 1) return false; if (m == 0 && ((n...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, lim, m, fa[110000]; bool check(int n) { n++; return n == (n & -n); } int main() { scanf("%d%d", &n, &k); lim = max((n - 3) / 2, 0); if (!(n & 1) || (k > lim) || (k == check(n)) || (n == 9 && k == 2)) { puts("NO"); return 0; } puts("YES"); m...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, fa[100005]; int f(int n) { n++; return (n ^ (n & -n)) > 0; } int g(int n) { return (n == 1) ? 0 : (n - 3) / 2; } void cover(int x, int p, int n) { fa[x] = p; if (n == 1) return; for (int k = 1; k <= n; k = k << 1 | 1) if ((k << 1 | 1) > (n -...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int nmax = 1e5 + 42; void wrong() { printf("NO\n"); exit(0); } bool off_one(int n) { return (n & (n + 1)) == 0; } int parent[nmax]; int low(int SZ, int LHS) { int RHS = SZ - 1 - LHS; int ret = 0; if (LHS >= 2 * RHS || RHS >= 2 * LHS) ret++; if (off_one(LHS...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; int fa[100005]; bool is_bal(int n) { int x = __builtin_popcount(n); return (n == ((1 << x) - 1)); } bool check(int n, int k) { if (n % 2 == 0) return false; if (n == 1 && k == 0) return true; if (k > (n - 3) / 2) return false; if (k == 0 && !is_bal(n))...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int SMALL = 100; vector<vector<int>> dp; bool check(int n, int k) { if (n % 2 == 0 || k < 0) return false; if (n < SMALL) { if (find(dp[n].begin(), dp[n].end(), k) == dp[n].end()) return false; } else if (n & (n + 1)) { if (k == 0 || k >= n / 2) return f...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long inf = 1LL << 50; const int N = 100000; int cnt = 1; int children[N]; int pwrs[17]; void build(int curr, int k, int n) { if (n == 1) { return; } int lg = log2(n); if (pwrs[lg] * 2 - 1 == n && k == 0) { children[cnt++] = c...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, p[200001]; int low(int x) { return x & -x; } int check() { if (n % 2 == 0) return 0; if (n == 9 && k == 2) return 0; if (k > (n - 3) / 2) return 0; if (low(n + 1) == n + 1 && k == 1) return 0; if (low(n + 1) != n + 1 && k == 0) return 0; return 1; } in...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> ans; const int mod = 1e9 + 7; bool hasSoln(int n, int k) { if ((n & 1) == 0) return false; if (k == 0 && (n & (n + 1)) != 0) return false; if (k == 1 && (n & (n + 1)) == 0) return false; if (n == 1 && k != 0) return false; if (n == 1 && k == 0) return ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 10; int pr[sz], nu = 2; void f(int n, int k, int rt) { if (n > 1) { if (k == 0) { pr[nu] = rt, f(n / 2, k, nu++); pr[nu] = rt, f(n / 2, k, nu++); } else if (k == 1) { for (int x = 1;; x = x * 2 + 1) { int y = n - 1 - ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; using namespace std; const int maxn = 100000 + 10; const int inf = 2000000000; int n, k; int vis[1 << 19]; inline int gao(int n, int k) { if (k < 0) return 0; if (k == 1) { return !vis[n]; } if (k == 0) { return vis[n]; } if (n == 9 && k == 2) return 0; ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &num) { T x = 0, f = 1; char ch = getchar(); for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1; for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0'); num = x * f; } in...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; bool Right(int n, int k) { if (n % 2 == 0) return false; if (n == 1) return k == 0; bool pw2 = ((n + 1) & n) == 0; if (pw2 && k == 1) return false; if (!pw2 && k == 0) return false; if (k > (n - 3) / 2) return false; if (n == 9 && k == 2) return false; retur...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; bool isp2(int n) { while (n % 2 == 0) n /= 2; return n == 1; } int maxk(int n) { return (n - 3) / 2; } bool ok(int n, int k) { if (n < 0 || k < 0 || n % 2 == 0) return false; if (k == 0) { return isp2(n + 1); } if (k == 1) { return !isp2(n + 1); } re...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, k; void end() { puts("NO"); exit(0); } inline bool check(int x) { return x == (x & (-x)); } int fa[N]; int main() { scanf("%d%d", &n, &k); int lim = max(0, (n - 3) / 2); if (n % 2 == 0) end(); if (k > lim) end(); if (check(n + 1) &...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, ans[100050]; inline int qr() { char a = 0; int w = 1, np = 0; while (a < '0' || a > '9') { if (a == '-') w = -1; a = getchar(); } while (a <= '9' && a >= '0') { np = (np << 3) + (np << 1) + (a ^ 48); a = getchar(); } return np * w; } ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int mod = 1000000007; int lowbit(int x) { return x & (-x); } int fast_power(int a, int b) { int x; for (x = 1; b; b >>= 1) { if (b & 1) x = 1ll * x * a % mod; a = 1ll * a * a % mod; } return x % mod; } int n, m; int ans[100005]...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, k, f[100010]...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 10; int par[maxN]; int n, k; bool isPower(int n) { int dd = (n + 1); return ((dd & (dd - 1)) == 0); } bool can[105][105]; bool ok(int n, int k) { if (n < 100) { if (!can[n][k]) { return false; } } else { if (k == 0) { i...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> #pragma GCC Optimize(2) using namespace std; int n, k, id; inline int lowbit(int x) { return x & (-x); } inline bool isfull(int x) { return (x + 1) == lowbit(x + 1); } inline int lowerX(int x) { while (x != lowbit(x)) x -= lowbit(x); return x - 1; } inline int upperX(int x) { while (!isfu...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rnd(seed); const int MOD = 998244353; void dp(vector<int> &res, int k, int s, int e, int p) { if (s > e) return; int num = e - s + 1; res[s] = p; if (num == 1) return; i...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int MAXN = 100005; using namespace std; int pa[MAXN], is_bal[MAXN]; vector<int> bal; int exist(int n, int k) { if (n % 2 == 0) return 0; if (n == 9 && k == 2) return 0; if (n == 1) return k == 0; if (k >= n / 2) return 0; if (is_bal[n]) return k != 1; return k != 0; } void bui...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; inline bool check(int n, int k) { if (n % 2 == 0) return false; if (k == 0) return !(n & (n + 1)); if (k == 1) return n & (n + 1); if (n == 9 && k == 2) return false; return k > 0 && k <= max(0, (n - 3) / 2); } int cnt; void dfs(int n, int k, int fa) { ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; bool Right(int n, int k) { if (n % 2 == 0) return false; if (n == 1) return k == 0; bool pw2 = ((n + 1) & n) == 0; if (pw2 && k == 1) return false; if (!pw2 && k == 0) return false; if (k > (n - 3) / 2) return false; if (n == 9 && k == 2) return false; retur...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18; long long t, a[maxn]; bool isp[maxn]; bool ok(long long x, long long y) { if (x == 1 && y == 0) return 1; if (x % 2 == 0) return 0; if (y > (x - 3) / 2) return 0; if (x == 9...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; bool pt(int n) { return !(n & (n - 1)); } bool check(int n, int k) { if (n <= 0 or n % 2 == 0 or k < 0) return false; if (n <= 3) return k == 0; if (n == 5) return k == 1; if (n == 7) return k == 0 or k == 2; if (n == 9) return k == 1 or k == 3; return k <= (n -...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int MAXN = 1e5; int n, K, fa[MAXN + 5]; int main() { scanf("%d %d", &n, &K); if (!(n & 1)) return puts("NO"), 0; if (!K) { if (n & (n + 1)) return puts("NO"), 0; puts("YES"); for (int i = 1; i <= n; ++i) printf("%d%c", i >> 1, i ^ n ? ' ' : '\n'); return 0; } if ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, mod = 998244353; template <class o> inline void qr(o &x) { x = 0; char c = getchar(); int f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + (c ^ 48); c = ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int chtholly = 0; const int N = 30; bool v[N][N]; int n; using pii = pair<int, int>; void construct(int n, int tar, int par, int val) { int j, k, l; bool pass = false; pii tar_1, tar_2; cout << par << " "; if (n == 1) { return; } else if (n <= N) { ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; mt19937_64 rng( (unsigned)chrono::system_clock::now().time_since_epoch().count()); const long double PI = acosl(-1); const int nmax = 1e5 + 10; inline bool isTwo(int x) { return x == (x & -x); } int parent[nmax]; int nodecnt = 0; void build(int n, int imbalance, int par...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, w; void v(int a) { cout << a << " "; } void t(int a, int b) { for (int i = a + 1; i <= b; i++) v(a + (i - a - 1) / 2); } void solve(int db, int p, int f) { v(f); if (db < 2) t(p, n); else { if (db == 3 && n - p == 10) t(p, p + 6), t(p + 6, p ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5, M = 50 + 5; const long long INF = 1e18 + 5; inline long long read() { long long sum = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fh = -1; c = getchar(); } while (c >= '0' && c <= '9') { sum = sum * ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; int s[100005], si[100005]; int main() { scanf("%d%d", &n, &k); if (n % 2 == 0) { puts("NO"); return 0; } if (n == 1 && k == 0) { puts("YES"); puts("0"); return 0; } int tmp = (n - 3) / 2; if (tmp < k) { puts("NO"); return ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; bool mark[N]; int full_binary[N]; bool small[10][4]; int ans[N], cnt; bool valid(int n, int k) { if (k < 0) return false; if (n % 2 == 0) return false; if (n == 1 && k == 0) return true; if (k > (n - 3) / 2) { return false; } if (n <= 9...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int lowbit(int x) { return x & -x; } int n, k, fa[100010]; int main() { scanf("%d%d", &n, &k); if (!(n & 1) || k > max(0, (n - 3) / 2) || (n == 9 && k == 2)) puts("NO"), exit(0); if (n + 1 == lowbit(n + 1)) { if (k == 1) puts("NO"), exit(0); } else if (k == ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <class T> int chkmax(T& a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int chkmin(T& a, T b) { if (b < a) { a = b; return 1; } return 0; } template <class iterator> void output(iterator begin, iterator end, ostr...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100003; template <typename T> void read(T &x) { int ch = getchar(); x = 0; bool f = false; for (; ch < '0' || ch > '9'; ch = getchar()) f |= ch == '-'; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } int n, k,...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; __inline__ __attribute__((always_inline)) unsigned int rnd() { static unsigned int seed = 416; return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; } template <typename _Tp> _Tp gcd(const _T...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { char c = getchar(); int x = 0; bool f = 0; for (; !isdigit(c); c = getchar()) if (c == '-') f = 1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); if (f) x = -x; return x; } int n, k, fa[100...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int ans[maxn]; int lowbit(int x) { return x & -x; } bool is_two(int x) { return x == lowbit(x); } int main() { int n, k; scanf("%d%d", &n, &k); int lim = max(0, (n - 3) / 2); if (n % 2 == 0 || k > lim || (n == 9 && k == 2) || (!is_two...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, k; bool works(int n, int k) { if (!(n & 1) || k < 0) return 0; if (k < 2) return k ^ !(n & (n + 1)); if (n == 9 && k == 2) return 0; return k && 2 * k + 3 <= n; } void sol(int n, int k, int p) { int x = ++m; cout << p << (x > ::n ? '\n' : ' '); for (...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
from heapq import * import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)]...
PYTHON3
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, las; int main() { scanf("%d%d", &n, &k); if (n % 2 == 0 || (k > (n - 3) / 2 && n != 1) || (n == 9 && k == 2) || (((int)(pow(2, (int)log2(n + 1)) + 1e-8)) != n + 1 && k == 0) || (((int)(pow(2, (int)log2(n + 1)) + 1e-8)) == n + 1 && k == 1) || ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, cnt; bool check(int cntNode, int cntCritical) { if (cntNode % 2 == 0) return 0; if (!cntCritical) return !(cntNode & (cntNode + 1)); if (cntCritical == 1) return cntNode & (cntNode + 1); if (cntNode == 9 && cntCritical == 2) return 0; return cntCritical ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int now = 0; int p[100005]; int buildbinary(int dep) { now++; if (dep == 1) return now; int node = now; p[buildbinary(dep...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target("avx2") using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; bool f[100005]; void out() { cout << "NO"; exit(0); } int fa[100005]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; f[1] = 1; for (int i = 2; i <= n + 1; i++) { if (!(i & 1) && f[i / 2]) f[i] ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int fa[maxn]; int chk(int x) { return x - (x & -x); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; int lim = max((n - 3) / 2, 0); if ((k > lim) || (n % 2 == 0) || (n == 9 && k == 2) || (c...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int s[maxn] = {}; void create2(int i, int n) { s[i + 1] = i; s[i + 2] = i; if (n - 2 > 0) create2(i + 2, n - 2); } bool create(int i, int n, int k) { if (n < 2 * k + 2) { return false; } if (n == 0) return true; if (n == 2 * k + 2)...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int first = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { first = first * 10 + ch - 48; } return first * f; } const int mxN = 1e6; int fa[mxN + 3...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int MAXN = 1e5 + 5, MAXLOG = 50; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s - '0'), s = getchar(); ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, i, fa[100002]; bool check(int x) { while (x != 1) { if (x % 2 != 0) return 0; x /= 2; } return 1; } int main() { scanf("%d%d", &n, &k); if ((n == 9 && k == 2) || n % 2 == 0) puts("NO"); else if (k == 0) { if (!check(n + 1)) puts("...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, k, f[N], b; void no() { puts("NO"); exit(0); } int ok(int x) { return x == (x & (-x)); } int main() { scanf("%d%d", &n, &k); if (n % 2 == 0) no(); if (k > max((n - 3) / 2, 0)) no(); if (n == 9 && k == 2) no(); if (ok(n + 1) && k ==...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> inline int Bitcount(int x) { int ret = 0; while (x) ret += x & 1, x >>= 1; return ret; } int n, k; int main() { scanf("%d %d", &n, &k); if (n == 1 && k == 0) { printf("YES\n0\n"); return 0; } if (!(n & 1) || n - 2 * k < 3) { puts("NO"); return 0; } if (n == 9 &...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5; const int oo = 1e9; int ans[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; if (n == 1 && k == 0) { cout << "yes 0\n"; return 0; } int nini = n; if (n % 2 == 0 || k >= ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int na, ka; int lowbit(int x) { return x & (-x); } bool chk(int n, int k) { if (k < 0) return 0; if (!(n % 2)) return 0; if (k && k * 2 + 3 > n) return 0; if (lowbit(n + 1) == n + 1 && k == 1) return 0; if (lowbit(n + 1) != n + 1 && k == 0) return 0; if (n == 9 ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, fa[100005]; bool check(int x) { return x - (x & -x) == 0; } int main() { scanf("%d%d", &n, &k); int mx = max((n - 3) / 2, 0); if (k > mx || (n % 2 == 0) || (n == 9 && k == 2) || (check(n + 1) && k == 1) || (!check(n + 1) && k == 0)) { printf("NO");...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int N, K, cnt; bool can(int n, int k) { if (!(n & 1)) return false; if (k == 0) return (n & (n + 1)) ? false : true; if (k == 1) return (n & (n + 1)) ? true : false; if (n == 9 && k == 2) return false; return k > 0 && k * 2 + 3 <= n; } void solve(int n, int k, int...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; int s[100005]; int main() { cin >> n >> k; if (n == 1 && k == 0) return puts("YES\n0"), 0; if (n % 2 == 0 || n - 3 < k * 2) return puts("NO"), 0; if (n == 9 && k == 2) return puts("NO"), 0; if (k == 1 && ((n + 1) & (-(n + 1))) == n + 1) return puts("NO")...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
from heapq import * import sys def ng(): print("NO") exit() n, k = map(int,input().split()) if (n,k)==(1,0): print("YES") print(0) exit() ans = [0] * n popcnt = lambda x: bin(x).count("1") if n & 1 == 0 or n < 2 * k + 3 or (popcnt(n + 1) > 1 and k == 0): ng() u = 0 if popcnt(n + 1 - 2 * (k - 1)...
PYTHON3
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int p[100010]; int cnt; int solve0(int n) { if (n == 1) return ++cnt; int l = solve0(n / 2), r = solve0(n / 2); p[l] = p[r] = cnt + 1; return ++cnt; } int solve1(int n) { int base = 1 << (31 - __builtin_clz(n)), l, r; if (n + 1 == base * 3 / 2) l = solve0(ba...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <typename __T> inline void read(__T &x) { x = 0; int f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } x *= f; } pair<int, int> mp(int ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> inline void write(F x, char...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const long long D = 30; long long deg[D] = {1}; vector<long long> ans; long long check() { vector<long long> sz(ans.size() + 1); vector<pair<long long, long long> > son(ans.size() + 1); long long ret = 0; for (long long i = ans.size() - 1; i >= 0; --i) { ++sz[i ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 200050; int n, k, fa[N]; queue<int> q; inline bool check(int x) { x++; int w = 1; while (w < x) w <<= 1; return (w == x); } inline void get(int rt, int l, int r) { fa[l] = rt; q.push(l); for (int i = l + 1; i <= r; i += 2) { int now = q.front...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 5...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 1e5; int n, m, t, a[maxn], b[maxn], ans; bool can(int num, int k) { if (num % 2 == 0 or k < 0) return 0; if (k <= 1) return k ^ (!(num & (num + 1))); if (num == 9 && k == 2) return 0; return 2 * k + 3 <= num; } void did(int num, int k, int fro...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; char buf[1048576], *p0, *p1; inline int read() { int r = 0; char c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1) ? EOF : *p0++); while (c < 48 || c > 57) c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 104...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100000; int n, wantimbal; int par[MAXN]; int nxtnode; int calcmn(int n) { ++n; while ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int par[N]; int ID; int two(int x) { return __builtin_popcount(x + 1) == 1; } int solve(int n, int K) { if (K > 3) { int p = ++ID, u = ++ID; par[u] = p; int v = solve(n - 2, K - 1); par[v] = p; return p; } if (K == 3) { ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int M = 1e6 + 5; int read() { int x = 0, y = 1; char ch = getchar(); while (ch < '0' || ch > '9') y = (ch == '-') ? -1 : 1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * y; } int lowbit(int x) { return x & (...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int K, N; int ans[MAXN]; bool check(int n, int k) { if (n == 1 && k == 0) return true; if (k * 2 + 3 > n) return false; if (n % 2 == 0) return false; if (n == 9 && k == 2) return false; if (__builtin_popcount(n + 1) == 1) { if (k == 1...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k, cnt; bool check(int x, int y) { if (x % 2 == 0) return 0; if (y == 0) { if (x & (x + 1)) return 0; else return 1; } if (y == 1) { if (x & (x + 1)) return 1; else return 0; } if (x == 9 && y == 2) return 0; retu...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int fa[100010]; int n, k; inline int read() { int ans = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); return ans; } inline bool check(int x) { retur...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; int ans[100000 + 10]; int p2 = 2 << 20; void pt(int start, int num) { for (int i = 0; i < num; i++) { ans[start + i] = i / 2 + start; } return; } int main() { scanf("%d%d", &n, &k); if (n == 1 && k == 0) { printf("YES\n0\n"); return 0; } ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int mod = 1000000007; int lowbit(int x) { return x & (-x); } int fast_power(int a, int b) { int x; for (x = 1; b; b >>= 1) { if (b & 1) x = 1ll * x * a % mod; a = 1ll * a * a % mod; } return x % mod; } int n, m; int ans[100005]...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; bool isbalanced(int x, int y) { return (2 * x > y && 2 * y > x); } bool ispow(int x) { return (__builtin_popcount(x + 1) == 1); } int getdep(int x) { return __builtin_ctz(x + 1); } int n, k, cnt; int ans[MAXN]; void build(int fa, int dep) { if (d...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <class T> inline void cmin(T &a, T b) { ((a > b) && (a = b)); } template <class T> inline void cmax(T &a, T b) { ((a < b) && (a = b)); } char IO; template <class T = int> T rd() { T s = 0; int f = 0; while (!isdigit(IO = getchar())) f |= IO == '-'; do s...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 110000, maxm = 550000; int n, k, lim = 0, ans[maxn]; bool tag = 1; int lowbit(int x) { return x & (-x); } int main() { scanf("%d%d", &n, &k), lim = max((n - 3) / 2, 0); if (k > lim || !(n & 1)) tag = 0; if (n == 9 && k == 2) tag = 0; if (n + 1 - low...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int memo[105][6]; pair<int, int> next1[105][6]; pair<int, int> next2[105][6]; bool boleh(int n, int k); int dp(int n, int k) { if (n % 2 == 0) { return false; } if (k < 0) { return false; } if (n == 1) { return k == 0; } if (memo[n][k] != -1) { ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; const int M = 20; vector<int> soln[M][M]; int compute(vector<int> sha) { vector<int> sz(sha.size(), 1); vector<int> out[sha.size()]; for (int i = sha.size() - 1; i > 0; i--) { sz[sha[i]] += sz[i]; out[sha[i]].push_back(i); } in...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int ha = 998244353; int ok(int n, int k) { if (n == 9 && k == 2) return 0; if (~n & 1 || k < 0) return 0; if (n > 1 && (n - 3) / 2 < k) return 0; if (k == 0) return !(n & (n + 1)); if (k == 1) return n & (n + 1); return 1; } int cnt ...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> namespace ztd { using namespace std; template <typename T> inline T read(T& t) { t = 0; short f = 1; char ch = getchar(); double d = 0.1; while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getc...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; bool isbalanced(int x, int y) { return (2 * x > y && 2 * y > x); } bool ispow(int x) { return (__builtin_popcount(x + 1) == 1); } int getdep(int x) { return __builtin_ctz(x + 1); } int n, k, cnt; int ans[MAXN]; void build(int fa, int dep) { if (d...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#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...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, k; int par[100005]; void solve(int n1, int k1, int idx) { if (n1 == 1) return; if (n1 == 11 && k1 == 3 || __builtin_popcount(n1 - 1) == 1 && k1 == 2) { par[idx + 1] = idx; par[idx + 2] = par[idx + 3] = idx + 1; par[idx + 4] = idx; solve(n1 - 4, k1...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; long long N, K, cnt; long long can(long long n, long long k) { if (n % 2 == 0) { return 0; } if (k == 0) { if (n & (n + 1)) { return 0; } else { return 1; } } if (k == 1) { if (n & (n + 1)) { return 1; } else { retur...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int N = 1e5 + 5; using namespace std; int n, m, k, cnt, num[105], fa[N], stk[N], top; template <typename T> inline T read() { T x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 +...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> const int MAX_N = 100000; int son[1 + MAX_N]; bool canDo[4][1 + MAX_N]; int root(int N, int K, int firstNode) { if (N % 2 == 0) return -1; if (K >= 3 && N < 2 * K + 3) return -1; else if (K >= 4) { int a = root(1, 0, firstNode); int b = root(N - 2, K - 1, firstNode + 1); s...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, fa[100005]; int f(int n) { n++; return (n ^ (n & -n)) > 0; } int g(int n) { return (n == 1) ? 0 : (n - 3) / 2; } void cover(int x, int p, int n) { fa[x] = p; if (n == 1) return; for (int k = 1; k <= n; k = k << 1 | 1) if ((k << 1 | 1) > (n -...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; char buf[1048576], *p0, *p1; inline int read() { int r = 0; char c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 1048576, stdin), p0 == p1) ? EOF : *p0++); while (c < 48 || c > 57) c = (p0 == p1 && (p1 = (p0 = buf) + fread(buf, 1, 104...
CPP
1379_E. Inverse Genealogy
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& in, vector<T>& a) { for (auto& i : a) in >> i; return in; } template <typename T> ostream& operator<<(ostream& out, const vector<T>& a) { for (auto& i : a) { out << i << " "; } return out; } template <typename...
CPP