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
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 (...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 = ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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) ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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....
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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++) { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]) ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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] +...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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"; ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 =...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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);...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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>...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.util.*; public class CF1068E extends PrintWriter { CF1068E() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1068E o = new CF1068E(); o.main(); o.flush(); } void main() { int n = sc.nextInt(); int k = sc.nextInt(); in...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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++) { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashMap; import ...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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) ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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); } ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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); ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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<...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.util.*; public class E implements Runnable { public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();} public void run() { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); System.err.println(""); int n = fs.n...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]) ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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; ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.util.*; //find the center of the tree (delete leaves and keep doing that until there's one left) //dfs from center to determine if it is k-hedgehog public class multihedgehog { static int[] deg; static ArrayList<Integer>[] a; public static void main(String[] args) { Scanner scan=new Scanner(System.in...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 >>...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.util.*; public class Solution{ InputStream is; static PrintWriter out; String INPUT = ""; static long mod = (long)1e9+7L; int n, k; ArrayList<Integer>[] adj; int[] next; int centre = -1; public void solve(){ n = ni(); k = ni(); adj = new ArrayList[n+1]; for(int i = 0; i <...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 = ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
from __future__ import division from sys import stdin from collections import * from copy import copy class graph: # initialize graph def __init__(self, gdict=None): self.gdict, self.l = [[] for _ in range(n + 1)], [0] * (n + 1) # add edge def addEdge(self, node1, node2, w=None): self...
PYTHON
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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() { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.util.*; public class Solution{ InputStream is; static PrintWriter out; String INPUT = ""; static long mod = (long)1e9+7L; int n, k, k1; ArrayList<Integer>[] adj; int[] next; int centre = -1; public void solve(){ n = ni(); k = ni(); adj = new ArrayList[n+1]; for(int i = 0;...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
from collections import deque n,k = map(int,input().split()) d = {} for i in range(n): d[i+1] = set() for i in range(n-1): u,v = map(int,input().split()) d[u].add(v) d[v].add(u) dist = {} prev = {} dist[1] = 0 q = deque() q.append(1) while len(q) >0: cur = q.popleft() for x in d[cur]: i...
PYTHON3
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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, ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; public class E { public void solve(JS in, PrintWriter out) { int n = in.nextInt(); int k = in.nextIn...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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_...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.util.*; import java.io.*; public class E { static FastIO f; public static void main(String args[]) throws IOException { f = new FastIO(); int n = f.ni(), k = f.ni(), l[] = new int[n+1], c[] = new int[n+1], i; GraphNode g = new GraphNode(n); Node u, v = null; HashSet<Node> o = new HashSet<>(...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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; ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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 ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]) { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]); ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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)) { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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] =...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.stream.IntStream; import java.util.Arrays; import java.util.Iterator; import java.util.InputMismatchException; import java.io.IOException; import java.util.OptionalInt; import java.util.NoSu...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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]) { ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { private static final Scanner sc = new Scanner(System.in); public static void main(String[] args) throws IOException { ...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
from __future__ import division from sys import stdin from collections import * class graph: # initialize graph def __init__(self, gdict=None): self.gdict, self.l = [[] for _ in range(n + 1)], [0] * (n + 1) # add edge def addEdge(self, node1, node2, w=None): self.gdict[node1].append(n...
PYTHON
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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); ...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.*; import java.math.*; import java.util.*; public class E { static ArrayList<Integer> adj[], adjList[]; static int N, dp_down[][], dp_up[]; static boolean[] visited; // Part 1 static void dfs1(int u) { visited[u] = true; for (int i = 0; i < adjList[u].size(); ++i) { int v = adjList[u].get...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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,...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
// package CodeForces; //package ; import java.io.*; import java.util.*; public class Problem_1068E { static ArrayList<Integer> adjList[],adj[]; static boolean visited[]; @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { Scanner sc = new Scanner(); PrintWriter pw = ne...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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(); +...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.LinkedList; import java.util.StringTokenizer...
JAVA
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
#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)...
CPP
1068_E. Multihedgehog
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 himself k-multihedgehog. Let us define k-multihedgehog as fol...
2
11
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { void solve(){ int n=ni(),k=ni(); g=new ArrayList[n+1]; for(int i=1;i<=n;i++) g[i]=new ArrayList<>(); for(int i=1;i<n;i++){ int x=ni(),y=ni(); g[x].add(y); g[y].a...
JAVA
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Comparator.*; public class Main { FastScanner in; PrintWriter out; private void solve() throws IOException { /...
JAVA
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Comparator.*; public class Main { FastScanner in; PrintWriter out; private void solve() throws IOException { i...
JAVA
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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; } ...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
# SHRi GANESHA author: Kunal Verma # import os import sys from bisect import bisect_left, bisect_right from collections import Counter, defaultdict from functools import reduce from io import BytesIO, IOBase from itertools import combinations from math import gcd, inf, sqrt, ceil, floor #sys.setrecursionlimit(2*...
PYTHON3
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); String[] line = rd.readLine().split(" "); int n = Integer.parseInt(line[0]); int m = Integer...
JAVA
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP
1090_D. Similar Arrays
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 comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#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...
CPP