text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int n, u, v, z = 0, f[100001]; int main() { for (int i = 1; i <= 10000; i++) z++; for (int i = 1; i <= 100; i++) z--; cin >> n; for (int i = 1; i < n; i++) { cin >> u >> v; f[u]++; f[v]++; } for (int i = 1; i <= n; i++) if (f[i] != 1 && f[i] <= 2...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n, x, y; vector<int> g[100010]; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { scanf("%d%d", &x, &y); g[x].push_back(y); g[y].push_back(x); } for (int i = 1; i <= n; i++) { if (g[i].size() == 2) { pu...
#include <bits/stdc++.h> using namespace std; long long int n; vector<long long int> G[200020]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; G[x].push_back(y); G[y].push_back(x); } for (int i = 1; i <= n; i++) { if (G[i].siz...
#include <bits/stdc++.h> using namespace std; int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1}; long long bigmod(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % 998244353; x = (x * x) % 998244353; p >>= 1; } return res; } int32_t main() { ios_base::sync_wi...
#include <bits/stdc++.h> using namespace std; int g[100005]; int main() { int n; memset(g, 0, sizeof(g)); cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u]++; g[v]++; } for (int i = 1; i <= n; i++) { if (g[i] == 2) { cout << "NO"; return 0; } } cou...
#include <bits/stdc++.h> using namespace std; ; const double eps = 1e-8; const int mod = 1e9 + 7; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; struct EDGE { int v, nxt; } edge[maxn << 1]; int head[maxn], tot; void add_edge(int u, int v) { edge[tot].v = v, edge[to...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int BASE = 1e9 + 7; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const int N = 1e5 + 1; vector<int> a[N]; int pa[N], n; int F[N]; void DFS(int p, int u) { bool Check = true; for (__typeof(a[u].begin()) it = a[u].begin(...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } std::vector<long long> edge[100045]; int main() { ios_base::sync_with_...
#include <bits/stdc++.h> using namespace std; bool is_prime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } vector<long long> fact(long long n) { n = abs(n); vector<long long> ans; for (int i = 1; i * i <= n; i++) { if (n % i == 0)...
#include <bits/stdc++.h> using namespace std; int n, a, b; vector<int> adj[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = (int)1; i <= (int)n - 1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = (int)1; i <= (i...
#include <bits/stdc++.h> using namespace std; const long long inff = 0x3f3f3f3f3f3f3f3f; int n, x, y, du[100008]; int main() { cin.tie(0); cout.tie(0); cin >> n; for (int i(1); i <= (n - 1); ++i) { scanf("%d", &x), scanf("%d", &y); du[x]++, du[y]++; } for (int i(1); i <= (n); ++i) if (du[i] == 2...
#include <bits/stdc++.h> using namespace std; int main() { int n, f = 0; cin >> n; vector<int> V[100008]; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; V[u].push_back(v); V[v].push_back(u); } for (int i = 0; i <= n; i++) { if (V[i].size() == 2) { f = 1; break; ...
#include <bits/stdc++.h> using namespace std; int cnt[100005]; int main() { int n; scanf("%d", &n); if (n == 2) { printf("YES\n"); return 0; } if (n == 3) { printf("NO\n"); return 0; } for (int i = 0; i < n - 1; i++) { int u, v; scanf("%d%d", &u, &v); cnt[u]++; cnt[v]++; ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[101010]; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int a, b; scanf("%d %d", &a, &b); v[a].push_back(b); v[b].push_back(a); } for (int i = 1; i <= n; i++) if (v[i].size() == 2) return !printf("NO"); printf(...
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; int find(int v, int* parent) { if (parent[v] == v) { return v; } return find(parent[v], parent); } int vis[100005]; int dp[100005]; int dfs(int u) { vis[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (!vis[v]...
#include <bits/stdc++.h> int main() { long long in[100005]; long long n, i, j, m, t; memset(in, 0, sizeof(in)); scanf("%lld", &n); for (i = 1; i <= n - 1; i++) { long long u, v; scanf("%lld %lld", &u, &v); in[u]++; in[v]++; } long long num = 0; long long ans = 0; int flag = 1; for (i...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj; int main() { int n; cin >> n; adj = vector<vector<int>>(n + 1); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } string ans = "YES\n"; int flag = 1; for (int i = 1...
#include <bits/stdc++.h> using namespace std; int degree[100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; ++degree[u]; ++degree[v]; } for (int i = 1; i <= n; ++i) { if (degree[i] == 2) { cout <<...
#include <bits/stdc++.h> using namespace std; const long long max_n = 1e6 + 20; long long n, m, k, ans, sum; long long a[max_n]; long long mark[max_n]; vector<long long> v, adj[max_n], jda[max_n]; void dfs(long long v) { mark[v] = 1; if (adj[v].size() == 2) ans = -1; for (auto i : adj[v]) { if (!mark[i]) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n, u, v; int a[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; memset(a, 0, sizeof(a)); for (int i = 0; i < n - 1; i++) { cin >> u >> v; a[u]++; a[v]++; } long long cnt[3] = {0, 0, 0}; for (i...
#include <bits/stdc++.h> using namespace std; int n, cnt[100009]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> n; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; cnt[x]++, cnt[y]++; } for (int i = 1; i <= n; i++) if (cnt[i] == 2) return cout << "NO"...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 10; long long n, deg[maxn]; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ...
#include <bits/stdc++.h> using namespace std; vector<long long> tree[500500]; long long num[500500], fine = 0, n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i < n; i++) { long long u, v; cin >> u >> v; tree[u].push_back(v); tree[v].p...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; void solve() { int n, u, v; cin >> n; vector<int> Adj[n]; for (int i = 1; i < n; ++i) { cin >> u >> v; --u; --v; Adj[u].push_back(v); Adj[v].push_back(u); } for (int i = 0; i < n; ++i) { if (Adj[i].size()...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long a, long long b) { re...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> g(n); int f, t; for (int i = 0; i < n - 1; ++i) { cin >> f >> t; f--; t--; g[f].push_back(t); g[t].push_back(f); } for (int i = 0; i < n; ++i) { if (g[i].size() == 2) { cout << "NO...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); a[x]++; a[y]++; } for (int i = 1; i <= n; i++) if (a[i] == 2) { printf("NO\n"); return 0; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; long long n; vector<long long> add[N]; void nie() { cout << "NO"; exit(0); } void yie() { cout << "YES"; exit(0); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); vector<pair<long long, long long>> v; cin >> n; ...
#include <bits/stdc++.h> #pragma GCC optimize("-O2") using namespace std; const int LIM = 1e5 + 5, MOD = 1e9 + 7; const long double EPS = 1e-9; vector<vector<int> > g; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; g.resize(n); for (int i = 0; i < n - 1; ++i) { in...
#include <bits/stdc++.h> using namespace std; void func() { int n; cin >> n; vector<int> adj[n + 1]; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (adj[i].size() == 1) continue; if (adj[i].size...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e5 + 10; long long arr[MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; arr[u]++; arr[v]++; } for (int i = 1; i <= n; i++) if...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 3e5 + 5, M = 1e8 + 5, OO = 1000000; int T, n, m; int u, v; int deg[N]; int main() { scanf("%d", &n); for (int i = 1; i < n; ++i) { scanf("%d %d", &u, &v); ++deg[u], ++deg[v]; } for (int i = 1; i <= n; ++i) { if (d...
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int n, flag = 1; scanf("%d", &n); for (int i = 1, x, y; i < n; i++) { scanf("%d %d", &x, &y); a[x]++; a[y]++; } for (int i = 1; i <= n; i++) if (a[i] == 2) flag = 0; flag ? printf("YES") : printf("NO"); }
#include <bits/stdc++.h> using namespace std; int deg[100005]; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); deg[u]++; deg[v]++; } for (int i = 1; i <= n; i++) { if (deg[i] == 2) { printf("NO\n"); return 0; } } print...
#include <bits/stdc++.h> using ll = int64_t; using namespace std; const int N = 1e6 + 5; int n; int a[N]; basic_string<int> g[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1, u, v; i < n; i++) { cin >> u >> v; g[u] += v; g[v] += u; } for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n; int n1, n2; int grau[100010]; vector<pair<int, int> > edges; int main() { scanf("%d", &n); for (int g = 0; g < n - 1; g++) { scanf("%d %d", &n1, &n2); grau[n1]++; grau[n2]++; } for (int g = 1; g <= n; g++) { if (grau[g] == 2) { printf("N...
#include <bits/stdc++.h> using namespace std; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx4[] = {1, 0, -1, 0}; int dy4[] = {0, 1, 0, -1}; template <class A, class B> ostream& operator<<(ostream& out, const pair<A, B>& a) { return out << "(" << a.first << "," << a.second << ...
#include <bits/stdc++.h> using namespace std; int deg[200000]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; deg[u]++; deg[v]++; } for (int i = 1; i <= n; ++i) { if (deg[i] == 2) { cout << "NO\n"; return 0; } } cout << "YES\n";...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, n; cin >> n; vector<int> v[100010], barg; for (int i = 0; i < n - 1; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { if (v[i].size() == 2) { cout << "NO"; return 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1000, mod = 1e9 + 7; vector<int> vec[N]; long long bin_pow(int x, int y) { if (y == 0) return 1; if (y == 1) return x; if (y % 2 == 0) { long long z = bin_pow(x, y / 2); return (z * z) % mod; } return (bin_pow(x, y - 1) * x) % mod; } bo...
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > g; void endProg() { cout << "NO"; exit(0); } void dfs(long long v, long long p) { long long l = 0; for (auto i : g[v]) { if (i == p) continue; if (g[i].size() == 1) { l++; continue; } dfs(i, v); } if (v == 0...
#include <bits/stdc++.h> using namespace std; const long long inf = LONG_MAX; const long long arr = 1000000; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b.second; else return a.first < b.first; } vector<vector<long long> > g(arr); int mai...
#include <bits/stdc++.h> using namespace std; int n, x, y, mx, idx; int deg[100010]; vector<int> edge[100010]; bool vis[100010]; bool can = true; void dfs(int u) { vis[u] = true; int sz_u = (int)edge[u].size(); if (u != idx && sz_u == 2) { can = false; return; } for (int i = 0; i < sz_u && can; ++i) {...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse4") const long double EPS = 1e-9; const long long INF = 1e9; const long long mod = 1e9 + 7; using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long n, m, k; long long q; vector<vector<long ...
#include <bits/stdc++.h> using namespace std; int32_t main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<vector<long long>> graph(n + 1); if (n == 2) { cout << "YES" << "\n"; return 0; } for (long long i = 0; i < n - 1; i++) { long long...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 1; vector<long long> v[N]; int main() { long long n; cin >> n; for (int i = 0; i < n - 1; i++) { long long x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { if (v[i].size() == ...
#include <bits/stdc++.h> using namespace std; using ll = long long; long mmid(long a, long b, long c) { return a < b ? (b < c ? b : max(a, c)) : (b > c ? b : min(a, c)); } ll modinv(ll a) { ll b = 1000000007, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios::sync_with_stdio(0), cin.tie(0); long long int n; cin >> n; vector<long long int> v[n + 1]; for (long long int i = 0; i < n - 1; i++) { long long int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_bac...
#include <bits/stdc++.h> long long mod = 998244353; using namespace std; const long long N = 1e5 + 5; vector<long long> g[N]; long long n; void fail() { cout << "NO\n"; exit(0); } long long cnt = 1; void dfs(long long node, long long p = 0) { if (g[node].size() == 2) cnt = 0; for (long long nx : g[node]) { ...
#include <bits/stdc++.h> using namespace std; const long long inf = 998244353; bool cmp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) { if (a.first >= b.first) return false; return true; } int main() { long long n, i = 0, j, k, m, q, l, r = 0, w, x, y, z = 0; string t, s; cin >> n; vector<vector...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> d(n + 1); for (int i = 1; i <= n - 1; ++i) { int u, v; cin >> u >> v; d[u]++, d[v]++; } bool ok = 1; for (int i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } int main() { long long n; cin >> n; vector<long long> a[100001]; for (long long i = 0; i < n - 1; i++) { long long x, y; cin >> x >> y; a[x].push_back(y); a[y...
#include <bits/stdc++.h> using namespace std; void fast(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if ((int)name.size() > 0) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int N = 1e5; int deg[N]; int n; void solve() { cin >> ...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)) % md; } else { long long y = bigmod(b, p / 2, md); return (y * y) % md; } } int deg[100005]; int main() { int n;...
#include <bits/stdc++.h> using namespace std; const int N = 500010; int n, m, d[N]; inline int read() { int sym = 0, res = 0; char ch = 0; while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return sym ? -res : res; } void fil...
#include <bits/stdc++.h> using namespace std; long long ar[100005], n, flag; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { long long l, r; cin >> l >> r; ar[l]++; ar[r]++; } for (int i = 0; i < n + 1; i++) if (ar[i] == 2) flag = 1; if (!flag) cout << "YES"; else cout <...
#include <bits/stdc++.h> using namespace std; bool b2(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.first > p2.first.first; } bool b1(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.second < p2.first.second; } ...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18, M = 1e9 + 7; const long long int N = 1e5 + 5; vector<long long int> v[N]; void solve() { long long int n; cin >> n; long long int a, b; for (long long int i = 1; i < n; ++i) { cin >> a >> b; v[a].push_back(b); v[b].push_ba...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); int u, v; for (int i = 0; i < n - 1; i++) { cin >> u >> v; a[u]++; a[v]++; } bool check = false; for (int i = 1; i <= n; i++) if (a[i] == 2) check = true; if (check) cout << "NO"; el...
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; int main() { int t, q, n, m, x, y, i, j, k; scanf("%d", &n); for (i = 1; i < n; i++) { scanf("%d%d", &x, &y); v[x].push_back(y); v[y].push_back(x); } int f = 0; for (i = 1; i <= n; i++) { if (v[i].size() == 2) { f = 1...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; vector<vector<int>> A(n); for (int i = 0; i < (n - 1); i++) { cin >> a >> b; A[a - 1].push_back(b - 1); A[b - 1].push_back(a - 1); } if (n <= 2) { cout << "YES" << endl; return 0; } bool flag = fa...
#include <bits/stdc++.h> using namespace std; vector<int> N[100005]; void addE(int a, int b) { N[a].push_back(b); N[b].push_back(a); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b; cin >> n; for (int i = 1; i < n; i++) { cin >> a >> b; addE(a - 1, b - 1); ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); solve(); return 0; } long long max(long long a, long long b) { if (a > b) return a; return b; } long long min(long long a, long long b) { if (a < b) return a; re...
#include <bits/stdc++.h> using namespace std; vector<vector<long long int>> graph; int solve() { long long int n; cin >> n; graph.resize(n + 1); n--; while (n--) { long long int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } long long int flag = 0; for (auto adj : g...
#include <bits/stdc++.h> using namespace std; int n; vector<int> G[100005]; int main() { scanf("%d", &n); for (int i = 1; i <= n - 1; i++) { int u, v; scanf("%d %d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for (int i = 1; i <= n; i++) if (G[i].size() == 2) { printf("NO\n"); ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename S37, typename... Args> void err(istream_iterator<string> it, S37 a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const long long N = 200010, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998...
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const int N = 1e5 + 7; const int xinc[] = {0, 0, 1, -1}; const int yinc[...
#include <bits/stdc++.h> using namespace std; using namespace std; vector<int> conn[200100]; bool oka = true; void dfs(int u, int par) { if (par == -1 && conn[u].size() == 1) ; else { if (conn[u].size() == 1) return; if (conn[u].size() < 3 || oka == false) { oka = false; return; } } ...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; int n; vector<int> vs[N]; bool dfs(int node, int par) { if (par != -1 && vs[node].size() == 1) { return false; } int children = 0; bool bad = false; for (int v : vs[node]) if (v != par) { ++children; bad |= dfs(v, n...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long mod = 1000000007; const int MX = 0x3f3f3f; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, i, u, v; cin >> n; vector<int> adj[n]; for (i = 0; i <= n - 2; i++) { cin >> u >> v; adj[u - 1].empl...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int de[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; memset(de, 0, sizeof de); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; de[u]++; de[v]++; } bool flag = true; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int const maxn = 1e5 + 5; vector<int> p[maxn]; int main() { int n; scanf("%d", &n); int u, v; for (int i = 1; i < n; i++) { scanf("%d%d", &u, &v); p[u].push_back(v); p[v].push_back(u); } bool flag = 1; for (int i = 1; i <= n; i++) if (p[i].size...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, flag = 0, x, y; cin >> n; long long int a[200005]; for (i = 1; i <= n; i++) { a[i] = 0; } for (i = 1; i < n; i++) { cin >> x >> y; a[x]++; a[y]++; } for (i ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; int d[N]; int main() { int n; scanf("%d", &n); for (int i = 1, u, v; i < n; i++) { scanf("%d%d", &u, &v); d[u]++, d[v]++; } bool flag = true; for (int i = 1; i <= n; i++) { if (d[i] == 2) flag = false; } if (flag) ...
#include <bits/stdc++.h> using namespace std; const int limit = 1000000; int n; vector<int> g[limit]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int u = 1; u <= n; u++) { vector...
#include <bits/stdc++.h> const double eps = 1e-7; using namespace std; int n; int deg[100010]; int main() { while (~scanf("%d", &n)) { int a = 0, b = 0; memset(deg, 0, sizeof(deg)); for (int i = 0; i < n - 1; ++i) { scanf("%d%d", &a, &b); deg[a] += 1; deg[b] += 1; } bool isOk = 1...
#include <bits/stdc++.h> using namespace std; int a[100006]; int main(void) { int n, x, y; cin >> n; for (int i = 1; i < n; i++) cin >> x >> y, a[x]++, a[y]++; for (int i = 1; i <= n; i++) if (a[i] == 2) { cout << "NO"; return 0; } cout << "YES"; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unordered_map<int, int> m; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; m[a]++; m[b]++; } for (int i = 1; i <= n; i++) { if (m[i] == 2) { cout << "NO"; return 0; } } cout << "YES...
#include <bits/stdc++.h> using namespace std; const long long maxN = 2 * 100224; struct BIT { long long data[maxN] = {0}; void update(long long idx, long long val) { while (idx < maxN) { data[idx] += val; idx += idx & -idx; } } void update(long long l, long long r, long long val) { updat...
#include <bits/stdc++.h> using namespace std; int const maxn = 1e6 + 5; long long tree[4 * maxn], lazy[4 * maxn], a[maxn]; int kq[maxn]; int n; void down(int g) { if (lazy[g] != 0) { tree[g << 1] += lazy[g]; lazy[g << 1] += lazy[g]; tree[(g << 1) | 1] += lazy[g]; lazy[(g << 1) | 1] += lazy[g]; laz...
#include <bits/stdc++.h> using namespace std; long long n, a[500001], f[500001], ans[500001], mn; int lowbit(int x) { return x & (-x); } void ins(long long x, long long w) { long long i; for (i = x; i <= n; i += lowbit(i)) f[i] += w; } long long query(long long x) { long long xlh = 0, i; for (i = x; i; i -= low...
#include <bits/stdc++.h> using namespace std; long long int ar[4 * 200005]; void update(int a, int b, int l, int h, int p) { if (a < l || a > h) return; if (l == h) { ar[p] += b; return; } int m = (l + h) / 2; update(a, b, l, m, 2 * p); update(a, b, m + 1, h, 2 * p + 1); ar[p] += b; return; } in...
#include <bits/stdc++.h> using namespace std; const long long MAX = 200100; pair<long long, long long> tree[256 * 1024 * 2]; long long lazy[256 * 1024 * 2]; void updateRangeUtil(long long si, long long ss, long long se, long long us, long long ue, long long diff) { if (lazy[si] != 0) { tree[s...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxm = 4e6 + 10; const long long mod = 1e9 + 7; const int inf = 0x3ffffff; const double eps = 1e-5; long long n, s[maxn]; long long a[maxn], ans[maxn << 2], tag[maxn << 2], m; long long res[maxn]; inline void push_up(long long p) { ans[p...
#include <bits/stdc++.h> using namespace std; using ll = long long; ll P[200001]; ll sum[200001]; ll fen[200001]; int ans[200001]; void build() { for (int i = 1; i <= 200000; i++) { sum[i] = sum[i - 1] + ll(i - 1); fen[i] = sum[i] - sum[i - (i & -i)]; } } ll query(int l, int r) { if (l != 1LL) return quer...
#include <bits/stdc++.h> using namespace std; long long read() { char ch = getchar(); long long x = 0, ff = 1; while (ch < '0' || ch > '9') { if (ch == '-') ff = -ff; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * ff; } void write(long long aa) { ...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int p[M << 2], res[M]; long long V[M << 2], tag[M << 2]; void push_up(int o) { if (V[o << 1] < V[o << 1 | 1]) { V[o] = V[o << 1]; p[o] = p[o << 1]; } else { V[o] = V[o << 1 | 1]; p[o] = p[o << 1 | 1]; } } void push_down(int o) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int ans[maxn]; int n; long long a[maxn]; const int maxnode = maxn << 2; long long sum[maxnode], add[maxnode]; struct Node { int l, r; int mid() { return (l + r) >> 1; } } node[maxnode]; void Pushup(int rt) { sum[rt] = sum[rt << 1] + sum[rt << ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 10; const long long INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const long long MOD = 1e9 + 7; long long segtree[MAXN << 2]; long long lazy[MAXN << 2]; long long arr[MAXN]; long long ans[MAXN]; void pushup(long long rt) { seg...
#include <bits/stdc++.h> using namespace std; long long b[200005]; int n; long long sum(long long x) { if (x == 0) { return 0; } long long pas = 0; while (x > 0) { pas += b[x]; x = x & (x - 1); } return pas; } void update(long long x, long long i) { while (i <= n) { b[i] += x; i += (i ...
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, p[N]; long long a[N], tr[N << 2]; void build(int k, int l, int r) { if (l == r) { tr[k] = l; return; } int mid = l + r >> 1; build(k << 1, l, mid); build(k << 1 | 1, mid + 1, r); tr[k] = tr[k << 1] + tr[k << 1 | 1]; } void ad...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<int, int>; using ld = long double; using pii = pair<int, int>; using dbl = long double; using vll = vector<int>; #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") const ll mod = 1000000007; const ll N = 2e5 + 10; const ll...
#include <bits/stdc++.h> using namespace std; long long int fen[200005]; void upd(long long int x, long long int a) { for (long long int i = x; i < 200005; i += (i & (-i))) { fen[i] += a; } } long long int ret(long long int x) { long long int o = 0; for (long long int i = x; i > 0; i -= (i & (-i))) { o ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200100; const long long INF = 2000000100; const long long MOD = 998244353; long long N, S[MAXN], P[MAXN]; long long B[MAXN]; void update(int ind, long long v) { for (int i = ind; i <= N; i += (i & -i)) { B[i] += v; } } long long query(int ind)...
#include <bits/stdc++.h> using namespace std; struct node { int64_t data, lazy; int pos; }; node st[200001 * 4]; int64_t input[200001]; int anw[200001]; void output(int root, int L, int R) { if (L == R) { return; } int mid = (L + R) >> 1; output(root << 1, L, mid); output(root << 1 | 1, mid + 1, R); }...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10, Max = 101; const int MOD = 1000000007; const long long OO = 2e12 + 5000; const long long Sqrt = 710; const double PI = acos(-1); const double EPS = 1e-9; int n; long long a[N]; pair<long long, long long> seg[4 * N]; long long lazy[8 * N]; void ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; class { public: pair<long long, long long> T[200009 << 2]; long long lz[200009 << 2]; long long n, f[200009], ans[200009]; void solve() { cin >> n; for (int i = 1; i <= n; ++i) cin >> f[i]; build(1, 1, n); for (int i =...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const long long inf = 1000000000000; const int N = 200005; const long long LLMAX = 2e18; const long long MOD = 1000000009ll; const double eps = 1e-8; const int MAXN = 1e6 + 10; int gcd(int a, int b) { return b == 0 ? a :...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 2e9; const long long INFLL = 1e18; const int MAX_N = 1; int N; vector<long long> v; struct SEG { struct NODE { int l, r; long long data; }; vector<NODE> seg; int SZ; void add() { seg.push_back((NODE){-1, -1, (lon...