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
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int N, M, Q, CN; int a, b; int uf[100005]; int find(int x) { return x == uf[x] ? x : uf[x] = find(uf[x]); } int dep[100005]; int dad[100005]; int dis[100005]; int low[100005]; int cut[100005]; int com[100005]; int now; int A[100005]; int B[100005]; int top; vector<int> G[10...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> G[N]; int n, m, dfn[N], low[N], sta[N], top, dep[N], fa[N][21], scc_num, scc_id[N], w[N], dfs_clock; int q, num, odd[N]; bool vis[N]; void dfs(int u, int father) { vis[u] = 1; dep[u] = dep[father] + 1; fa[u][0] = father; for (i...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100111; const int MAXM = 100111; int N, M; int F[MAXN]; int Find(int a) { return F[a] == a ? a : F[a] = Find(F[a]); } struct Vert { int FE; int Dep; int Cnt; int Dps; int Dfn, Low; bool Vis; } V[MAXN]; struct Edge { int x, y, next, neg; bool...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> const int N = 1e5 + 50; int n, m, q, head[N], nxt[N << 1], ver[N << 1], f[N], cnt; int fa[N], dep[N], siz[N], son[N], top[N], d[N]; int tot, dfn[N], low[N]; std::pair<int, int> st[N]; int stop; bool vis[N]; inline int find(int x) { while (x != f[x]) x = f[x] = f[f[x]]; return x; } inline vo...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n, m; unordered_set<int> g[MAXN]; int color[MAXN]; int low[MAXN]; int depth[MAXN]; stack<pair<int, int> > edge_stack; vector<pair<int, int> > edges_to_remove; int COMP_ID; int comp_before[MAXN]; int comp_after[MAXN]; void remove_comp(int u, int ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; static char B[10000010]; char *e = B + 10000000, *p = e; char Getchar() { if (p == e) fread(B, 1, 10000000, stdin), p = B; return *(p++); } void read(int &ret) { ret = 0; char c; while (c = Getchar(), c < '0' || c > '9') ; do (ret *= 10) += c - '0'; while ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> int read() { char k = getchar(); int x = 0; while (k < '0' || k > '9') k = getchar(); while (k >= '0' && k <= '9') x = x * 10 + k - '0', k = getchar(); return x; } const int MX = 2e5 + 23; int n, m; int ORG[MX], CAC[MX], tot = 1; struct edge { int node, next, w; } h[MX * 6]; void ad...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; template <class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template <class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::differenc...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 200005, maxm = 400005; struct edge { int to, next; } e[maxm * 2]; int h[maxn], tot; int n, m, q; struct Edge { int u, v; bool operator<(const Edge &a) const { return u != a.u ? u < a.u : v < a.v; } }; stack<Edge> S; vector<Edge> bcc_e[maxn]; map<Edge,...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; inline char gc() { static char now[1 << 16], *S, *T; if (S == T) { T = (S = now) + fread(now, 1, 1 << 16, stdin); if (S == T) return EOF; } return *S++; } inline int read() { int x = 0, f = 1; char c = gc(); while (c < '0' || c > '9') { if (c == '-...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, Q, num = 0, top = 0, tot = 0, d[110010], h[110010], fa[110010][20], id[110010], cut[110010], dfn[110010], low[110010], vis[110010]; pair<int, int> q[110010 << 1]; struct edge { int x, y, next; } mp[110010 << 1]; inline char gc() { static char *S, ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; struct Edge { int next, v; Edge() {} Edge(int next, int v) : next(next), v(v) {} } e[maxn << 1]; struct Node { int val, pos; Node() {} Node(int val, int pos) : val(val), pos(pos) {} }; int n, m; int head[maxn], cnt; int dfn[maxn], ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 1e5 ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> e[N]; int dep[N], f[N], ok[N]; int cnt[N], fa[N][18]; int n, m; int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); } void dfs(int x) { dep[x] = dep[fa[x][0]] + 1; for (auto i : e[x]) if (!dep[i]) { fa[i][0] = x; d...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int maxn = 1e6 + 10, inf = 1e9 + 10, lg = 22; int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg], comp[maxn], c1; bool dp[maxn][lg]; vector<int> G[maxn]; bool mark[maxn]; void dfs(int a, in...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1000; vector<int> side[maxn]; int dfn[maxn], low[maxn], idx, f[maxn][23], stk[maxn], top, dep[maxn], bel[maxn]; bool odd[maxn], in[maxn]; int mark[maxn]; vector<int> edge[maxn]; void tarjan(int u, int fa) { bel[u] = bel[fa]; dfn[u] = low[u] = ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; namespace FGF { int n, m; const int N = 5e5 + 5; struct edg { int to, nxt, id; } e[N << 1]; int cnt = 1, head[N], s; int rt[N], dfn[N], low[N], st[N], bel[N], col[N], num, tp, dcc, siz[N], sum[N], dep[N], fa[N][20]; bool vis[N], is[N], fl; vector<int> V[N], E[N]; void...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxm = 100005; struct edge { int to, next; } e[maxm * 2]; int h[maxn], tot; int n, m, q; struct Edge { int u, v; bool operator<(const Edge &a) const { return u != a.u ? u < a.u : v < a.v; } }; stack<Edge> S; vector<Edge> bcc_e[maxn]; map<Edge,...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, x, y, q, cnt[100005], tot, vis[100005], dep[100005], dfn[100005], low[100005], d[100005], num, f[100005][20], s[100005], b[100005]; vector<int> v[100005]; inline int lca(int x, int y) { if (dep[x] < dep[y]) swap(x, y); for (int i = 18; i >= 0; i--) if ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int st[100010], aim[100010 << 1], nxt[100010 << 1], ln; void in_edge(int x, int y) { aim[ln] = y; nxt[ln] = st[x]; st[x] = ln++; } int father[100010]; int fp[100010][17]; int level[100010]; int belong[100010], tag[100010]; int n, m; int Find(int *father, int x) { re...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int read() { int kkk = 0, x = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') c = getchar(), x = -1; while (c >= '0' && c <= '9') kkk = kkk * 10 + (c - '0'), c = getchar(); return kkk * x; }...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; pair<int, int> edges[200105]; int C[200105], D[200105], temp[200105], sum[200105], num[200105], low[200105], disc[200105], vis[200105], cno, comp[200105], pa[19][200105], artic[200105], tim; stack<int> stk; set<int> s[200105]; vector<pair<int, int> > g[200105]; vect...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int dfn[100005], low[100005], N, Time, Stack[100005], zhan[100005], fa[19][100005], odd[100005], dep[100005], suf[100005], n, m, q, C, app[100005], root[100005]; vector<int> edge[100005]; void tarjan(int x) { dfn[x] = low[x] = ++Time; app[x] = C; Stack[++N] = ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100005, maxm = 100005; struct edge { int to, next; } e[maxm * 2]; int h[maxn], tot; int n, m, q; struct Edge { int u, v; bool operator<(const Edge &a) const { return u != a.u ? u < a.u : v < a.v; } }; stack<Edge> S; vector<Edge> bcc_e[maxn]; map<Edge,...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MN = 2e5 + 5, LG = 20; vector<pair<int, int> > Adj[MN]; int mh[MN], Cmp[MN], h[MN], es[MN], ee[MN], cmp, n, m; vector<int> st, C[MN], g[MN], adj[MN]; bool mk[MN], col[MN], is[MN], D[LG][MN]; int par[LG][MN]; int H[MN], V[MN], sz_v; void DFS(int s, int pr, int Comp...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct E { int ad, id, ne; } e[100010 * 4]; int n, m, q, u[100010], v[100010], w[100010], h1[100010], h2[100010], de[100010], fa[100010], f[100010], p0[100010], p1[100010]; bool o[100010]; void add(int* he, int x, int y, int d) { static int t = 0; ++t, e[t].ne = h...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; void read(int &x) { char c = getchar(); x = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); } const int maxn = 2e5 + 10; int n, m; namespace Tree { int tote = 1, FIR[maxn], TO[maxn], NEXT[maxn]; int fa[m...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; const int mod = (int)1e9 + 7; const int logN = 18; const int inf = 1e9; const int N = 2e5 + 5; int q, n, m, x, y, z, root[N], lca[logN + 1][N], depth[N], odd[N], f[N], up[N], sum[N]; vector<int> v[N]; int findset(int x) { return f[x] = (...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n, m, q, curcol, col[100010], depth[100010], val[100010], sum[100010], par[20][100010], parr[100010]; bool vis[100010]; vector<int> g[100010]; int FIND(int pos) { if (parr[pos] != pos) parr[pos] = FIND(parr[pos]); return parr[pos];...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int N, M, Q, u, v, id; vector<set<int>> G; vector<int> D, L, P, C1, C2; stack<pair<int, int>> S, O; bool dfs(int u, int p, int d, int c) { D[u] = L[u] = d; P[u] = c; bool ans = 0; for (int v : G[u]) if (v != p) { if (D[v] == -1) { S.emplace(u, v); ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, const T &b) { if (b > a) a = b; } const int maxn = 1e5 + 10; vector<pair<int, int> > g[maxn]; bool odd[maxn], in[maxn]; stack<int> stk; int col[...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> G[N]; int n, m, Q, dep[N], fa[N], ffa[N]; int hson[N], top[N], sz[N], sum[N]; int dfn[N], dfc = 0; bool vis[N], ans[N]; int qu[N], qv[N]; int idx[N]; int find(int x) { return ffa[x] == x ? x : ffa[x] = find(ffa[x]); } void dfs1(int u) { v...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXM = 100010; int n, m; struct edge { int ne, to, val; edge(int N = 0, int T = 0) : ne(N), to(T) {} } e[MAXM << 1]; int fir[MAXN], num = 1; inline void join(int a, int b) { e[++num] = edge(fir[a], b); fir[a] = num; } int dfn[MAXN]...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; template <bool Rank = true> struct DsuSec { map<int, int> r, sz; vector<pair<int, int> > edges; void clear() { r.clear(); sz.clear(); edges.clear(); } int root(int u) const { const auto it = r.find(u); if (it == r.end()) return u; return it...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q, len, en = 0, num = 0, top = 0, to[100100 << 1], r[100100 << 1], l[100100], st[100100], odd[100100], dfn[100100], low[100100], vis[100100], f[100100][18], d[100100], cnt[100100], con[100100]; void add(int x, ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const long long inf = 0x7f7f7f7f7f7f; long long mod; const long double eps = 1e-8; inline long long add(long long x) { return x >= mod ? x - mod : x; } inline long long sub(long long x) { return x < 0 ? x + mod : x; } inline void Add(long long &x, long long y) { if ((x +=...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 500005; int tot = 1; int ver[N << 1], nxt[N << 1], head[N << 1]; int dfn[N], low[N], f[N][19], rt[N]; int vis[N], st[N], top, v[N], sum[N], is[N]; vector<int> e[N], dcc[N]; int cnt, num, dep[N], bel[N], c[N], n, m, q; inline int read() { int x = 0, f = 1; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100111; const int MAXM = 100111; int N, M; int F[MAXN]; int Find(int a) { return F[a] == a ? a : F[a] = Find(F[a]); } struct Vert { int FE; int Dep; int Cnt; int Dps; int Dfn, Low; bool Vis; } V[MAXN]; struct Edge { int x, y, next, neg; bool...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> namespace IO { char buf[1000000], *p1, *p2; inline char getc() { if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin); return p1 == p2 ? EOF : *(p1++); } template <typename tp> inline void r(tp &n) { n = 0; char c = getc(); while (!isdigit(c)) c = getc(); while (isdigit(c))...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MXN = 100005; const int LOG = 17; struct DisjointSet { int fa[MXN]; void init(int n) { for (int i = (0); i <= (n); i++) fa[i] = i; } int f(int x) { return x == fa[x] ? x : fa[x] = f(fa[x]); } void uni(int x, int y) { fa[f(y)] = f(x); } } djs, con; in...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> namespace IO { char ibuf[(1 << 21) + 1], *iS, *iT; char Get() { return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, (1 << 21) + 1, stdin), (iS == iT ? EOF : *iS++)) : *iS++); } int read() { int x = 0, c = Get(); while (!isdigit(c)) c = Get(); w...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; pair<int, int> edges[200105]; int C[200105], D[200105], temp[200105], sum[200105], num[200105], low[200105], disc[200105], vis[200105], cno, comp[200105], pa[19][200105], artic[200105], tim; stack<int> stk; unordered_set<int> s[200105]; vector<pair<int, int> > g[200...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, p = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') p = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x *= p; } template <typename T> inline bool chkmin(T &a, T b) { re...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct Edge { int v; Edge *link; } edge[400010 * 2], *adj[200010], *tree[200010 * 2]; int totE, con, root, currT, top, top1; int totCut, totBi; int dep[200010], deps[200010], num[200010], dfn[200010], lowlink[200010], cut[200010], bi[200010], color[200010]; int temp...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; namespace zyt { template <typename T> inline void read(T &x) { char c; bool f = false; x = 0; do c = getchar(); while (c != '-' && !isdigit(c)); if (c == '-') f = true, c = getchar(); do x = x * 10 + c - '0', c = getchar(); while (isdigit(c)); if (f) x = -...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long read() { long long s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int read() { char ch = '!'; int res = 0, f = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = 1; } while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); return f ? -res : res; } const int N = 2e5 + 100; int n, m, Q, cnt, fa[N], col[N...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; int f(1); char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T, typename... Args> inline void read(T...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0LLU >> 1; int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); } const int maxn = 100010; const int maxq = 100010; int p[maxn], q[maxn], fa[maxn], dep[maxn], odd[maxn], sum[maxn]; int lca[maxq]; vector<i...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct DJS { int p[101010]; void init(int n) { for (int i = 0; i <= n; i++) p[i] = i; } int find_p(int x) { return x == p[x] ? x : p[x] = find_p(p[x]); } void uni(int x, int y) { p[find_p(x)] = find_p(y); } } djs, cc; int n, m; vector<int> g[101010], s[101010]...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7, M = 2e6 + 7; struct graph { int cnt, v[M], nxt[M], w[M], hd[N]; void add(int x, int y, int z) { v[++cnt] = y; w[cnt] = z; nxt[cnt] = hd[x]; hd[x] = cnt; } } G, H; int n, m, q, a[M][2], dep[N], lca[N], p0[N], p1[N], fa[N], tot[N];...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> const int N = 1e5 + 5; int n, m, q, tot, ff[N], t[4 * N], dfn[N]; int fa[N], sz[N], son[N], top[N], dep[N]; int to[N + N], nx[N + N], hd[N], sze; inline void add(int u, int v) { to[++sze] = v, nx[sze] = hd[u], hd[u] = sze; } inline int find(int x) { return x == ff[x] ? x : ff[x] = find(ff[x]); ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, q, fa[N], f[N][17], dep[N], s[N], a[N]; vector<int> e[N]; int get(int u) { return u == fa[u] ? u : fa[u] = get(fa[u]); } void dfs1(int u) { dep[u] = dep[f[u][0]] + 1; for (auto v : e[u]) { if (!dep[v]) { f[v][0] = u; dfs1(...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> u[100005]; vector<int> v[100005]; int cid[100005], _CID, col[100005], d[100005], par[100005], SPEC[100005], spec[100005]; int P[18][100005], Q[18][100005]; set<int> mergeto; int l[100005]; int gl(int a) { return l[a] = a == l[a] ? a : gl(l[a]); } v...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct Edge { int u, v; } sta[200010]; int n, m, q, k, t, p, top, vis[200010], tag[200010]; int head[200010], to[200010], nexts[200010]; int dfn[200010], low[200010], res[200010], cnt[200010], dep[200010], fa[200010][18]; void add(int u, int v) { to[++k] = v; next...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; struct DSU { int fa[maxn]; inline void init(int n) { for (int i = 1; i <= n; i++) fa[i] = i; } int findset(int x) { return fa[x] == x ? x : fa[x] = findset(fa[x]); } } dsu; vector<int> G[maxn]; int dep[maxn], anc[maxn][20], odd[maxn]; v...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100000; vector<int> s[N + 5]; int fa[N + 5], pa[N + 5][20], dis[N + 5], odd[N + 5], sum[N + 5]; int Find(int k) { if (fa[k] == k) return k; return fa[k] = Find(fa[k]); } void dfs1(int u, int add) { dis[u] = add; for (int i = 0; i < s[u].size(); i++) { ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX = 200010; vector<int> L[MAX]; struct data { int a, b, ans, done; } Q[MAX]; int ara[MAX]; namespace BCT { vector<int> ed[MAX]; bool cut[MAX]; int tot, Time, low[MAX], st[MAX]; vector<int> bcc[MAX]; stack<int> S; void popBCC(int s, int x) { cut[s] = 1; bcc...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5, L = 18; int n, m, q; vector<int> e[N + 1]; int rt[N + 1], fa[N + 1][L + 1], dep[N + 1]; bool vis[N + 1]; int cnt, bel[N + 1]; bool oddRing[N + 1]; int val[N + 1], sum[N + 1]; int read() { int ret = 0; char c = getchar(); while (!isdigit(c)) { c ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; namespace IO { const int __S = (1 << 20) + 5; char __buf[__S], *__H, *__T; inline char getc() { if (__H == __T) __T = (__H = __buf) + fread(__buf, 1, __S, stdin); if (__H == __T) return -1; return *__H++; } template <class __I> inline void read(__I &__x) { __x = 0; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; struct UnionFind { vector<int> p, rank; void assign(int N) { rank.assign(N, 0); p.resize(N); for (int i = 0; i < N; ++i) p[i] = i; } UnionFind(int N) { rank.assign(N, 0); p.resize(N); for (int i = 0; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[200010]; int n, m, q, cnt, father[100010], fa[100010][30], a[100010], dis[100010], deep[100010], head[100010]; inline void add(int u, int v) { cnt++; e[cnt].to = v; e[cnt].next = head[u]; head[u] = cnt; } inline int find(int x) ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; vector<int> G[N]; int n, m, Q, dep[N], fa[N], ffa[N]; int hson[N], top[N], sz[N], sum[N]; int dfn[N], dfc = 0; bool vis[N], ans[N]; int qu[N], qv[N]; int idx[N]; int find(int x) { return ffa[x] == x ? x : ffa[x] = find(ffa[x]); } void dfs1(int u) { v...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q; int to[200010], nxt[200010], fst[100010], tot = 1; void add(int u, int v) { to[++tot] = v; nxt[tot] = fst[u]; fst[u] = tot; } int d[100010], bl[100010], cnt; int stk[200010], no[100010], top, bccno; int anc[100010][17], dfn[100010], clk; int dfs(int u) { ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m; int k; bool debug = false; int f[100005], cid[100005], cc, deep[100005], par[100005], lca[18][100005], D[100005]; bool mark[100005], col[100005], spec[100005], S[100005]; int ff(int x) { return x == f[x] ? x : f[x] = ff(f[x]); } vector<int> mp[100005]; void df...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct Edge { int next, v; Edge() {} Edge(int next, int v) : next(next), v(v) {} } e[maxn << 1]; struct Node { int val, pos; Node() {} Node(int val, int pos) : val(val), pos(pos) {} }; int n, m; int head[maxn], cnt; int dfn[maxn], l...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int nex[maxn], to[maxn], head[maxn], s[maxn]; int e = 1; void add(int x, int y) { nex[++e] = head[x]; head[x] = e; to[e] = y; } int dfn[maxn], low[maxn], st[maxn], dep[maxn]; int p[maxn][27]; bool root[maxn]; int dfs_clock; int top, color; bo...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 200005; char buf[1 << 20], *p1, *p2; inline int _R() { int d = 0; bool ty = 1; char t; while (t = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? 0 : *p1++), (...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q, cnt, vis[100010], used[100010], dep[100010], val[100010], sum[100010], p[100010], par[21][100010]; vector<int> v[100010], g[100010]; vector<pair<int, int> > e; inline int find_set(int x) { return p[x] == x ? x : p[x] = find_set(p[x]); } inline void dfs(int ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const long long inf = 0x7f7f7f7f7f7f; long long mod; const long double eps = 1e-8; inline long long add(long long x) { return x >= mod ? x - mod : x; } inline long long sub(long long x) { return x < 0 ? x + mod : x; } inline void Add(long long &x, long long y) { if ((x +=...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, q, dfn[N], low[N], dfs_clock, sta1[N * 2], top1, scc_num, scc_id[N * 2], edgenum; int fa[N][21], vet[N * 2], head[N], Next[N * 2], dep[N], beg[N * 2], sta2[N * 4], top2, w[N][21]; bool flag[N * 2], vis[N]; bool used[N]; void addedge(...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int oo = ~0u >> 2, mo = (int)1e9 + 7; const int mn = 110000, mm = 110000 * 2, ml = 18; struct Edge { int y, l; } E[mm]; int g[mn], d[mn], s[mn], blg[mn]; int fa[mn][ml], f[mn]; bool o[mn]; int n, m, tt(1); void add(int x, int y) { E[++tt]...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int fr[100010], sa[200010], ne[200010], v[200010], bs = 0; void addb(int a, int b) { sa[bs] = a; v[bs] = b; ne[bs] = fr[a]; fr[a] = bs++; } bool bk[100010], jh[100010]; int sd[100010], fa[100010], son[100010], top[100010], ro[100010], jl[100010]; vector<int> ve[1000...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int head[1000009], to[1000009], nex[1000009], cnt; inline void add(int u, int v) { nex[++cnt] = head[u]; head[u] = cnt; to[cnt] = v; } int f[1000009][30], dep[1000009], root[1000009], num, ins[1000009], s[1000009]; int c[1000009], odd[1000009], st[1000009], top, color...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100000; vector<int> s[N + 5]; int fa[N + 5], pa[N + 5][20], dis[N + 5], odd[N + 5], sum[N + 5]; int Find(int k) { if (fa[k] == k) return k; return fa[k] = Find(fa[k]); } void dfs1(int u, int add) { dis[u] = add; for (int i = 0; i < s[u].size(); i++) { ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; vector<int> from[200010], g[200010]; int id[200010], low[200010], TOT, ALL; vector<int> S; int col[200010], vis[200010], TOTOT = 233; int val[200010]; int fa[200010][18], dep[200010]; bool check(int x, int c = 1) { col[x] = c; for (int i = 0; i < from[x].size(); i++) { ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> namespace IO { char buf[1000000], *p1, *p2; inline char getc() { if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin); return p1 == p2 ? EOF : *(p1++); } template <typename tp> inline void r(tp &n) { n = 0; char c = getc(); while (!isdigit(c)) c = getc(); while (isdigit(c))...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int p[200010], n1[200010], h[100010], ee = 0, anc[17][100010], F[100010], d[100010], odd[100010], sum[100010], n, m; void ae(int x, int y) { p[ee] = y; n1[ee] = h[x]; h[x] = ee++; } int gf(int x) { return (F[x] == x) ? x : F[x] = ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; inline long long rd() { long long x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 5; const long long mod = 1000 * 1000 * 1000 + 7; const int maxL = 20; vector<int> a[maxN]; int mark[maxN], dad[maxN], par[maxN]; int c[maxN], cid, bad[maxN], B[maxN]; int h[maxN], bl[maxN]; int get_par(int v) { return (par[v] == v ? v : par[v] ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } const int N = 100010; const int...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> g[100005]; int dep[100005], fa[100005][17], odd[100005], ufa[100005], ccnt, ic[100005]; int find(int x) { if (ufa[x] == x) return x; return ufa[x] = find(ufa[x]); } void dfs(int x, int p, int cd) { fa[x][0] = p; dep[x] = cd; ic[x] = ccnt; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n, m, q; vector<int> e[N + 1]; int rt[N + 1], fa[N + 1], dep[N + 1], siz[N + 1]; int read() { int ret = 0; char c = getchar(); while (!isdigit(c)) { c = getchar(); } while (isdigit(c)) { ret = ret * 10 + c - '0'; c = getchar(); ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int f[1000005][20]; int dfn[1000005], low[1000005], zhan[1000005 * 2], head[1000005], bcc[1000005]; int pdltk[1000005], num, dep[1000005]; int root[1000005]; int n, m; bitset<1000005> vis1, vis2; int cnt, tot; int sum[1000005]; vector<int> e[1000005]; struct dian { int x,...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; long long n, m, q, fa[100010], fa2[100010], dep[100010], f[100010][25], par[100010], sum[100010]; bool vis[100010], odd[100010]; vector<long long> vt[100010]; long long getf(long long x) { if (x == fa[x]) { return x; } return fa[x] = getf(fa[x]); } long long g...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 100111; const int MAXM = 100111; int N, M; int F[MAXN]; int Find(int a) { if (F[a] != F[F[a]]) F[a] = Find(F[a]); return F[a]; } struct Vert { int FE; int Dep; int Cnt; int Dps; int Dfn, Low; bool Vis; } V[MAXN]; struct Edge { int x, y, ne...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m; int head[N], nxt[N * 2], to[N * 2], tot; int vis[N], stp[N]; int dp[N][20]; int dfn[N], low[N], dep = 0; int stk[N * 5], top = 0; int belong[N], block = 0; int odd[N], col[N]; void init() { memset(head, -1, sizeof(head)); tot = 0; } void ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int nodes, edges, counter, counter2; vector<int> adj[100001]; set<int> adjset[100001]; int seen[100001]; int low[100001]; int depth[100001]; bool iscut[100001]; set<int> group[100001]; int dfn[100001]; stack<pair<int, int> > s; set<pair<int, int> > ins; bool isOld[100001]; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; struct DJS { int p[101010]; void init(int n) { for (int i = 0; i <= n; i++) p[i] = i; } int find_p(int x) { return x == p[x] ? x : p[x] = find_p(p[x]); } void uni(int x, int y) { p[find_p(x)] = find_p(y); } } djs, cc; int n, m; vector<int> g[101010], s[101010]...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; } template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <typename T> void read(T &first) { int f = 1; char ch; for (ch = getchar(); !isdigit(ch); ch...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int read() { int a = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { a = a * 10 + c - 48; c = getchar(); } return a; } const int _ = 2e5 + 7; struct Edge { int end, upEd; }; int N, M; namespace tree { Edge Ed[_ << 1]; int...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> v[100100]; int dept[100100]; int par[100100][22]; int dsu_par[100100]; bool tag[100100]; int root[100100]; int get_par(int now) { return dsu_par[now] = (dsu_par[now] == now) ? now : get_par(dsu_par[now]); } void dfs1(int now) { for (int i = 0; i...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { register T sum = 0; register char cc = getchar(); int sym = 1; while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar(); if (cc == '-') sym = -1, cc = getchar(); sum = sum * 10 + cc - '0'; cc = getchar(); while (cc >...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q, dsu[100100], dis[100100]; int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); } void merge(int x, int y) { x = find(x), y = find(y); if (x != y) dsu[y] = x; } namespace Tree { int head[200100], cnt; struct Edge { int to, next; } edge[400100]...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, Q, fa[N], f[N][18]; int dep[N], S[N], fl[N]; vector<int> e[N]; int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); } void dfs1(int x) { dep[x] = dep[f[x][0]] + 1; for (auto i : e[x]) if (!dep[i]) { f[i][0] = x; df...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> G[1000006]; int dfn[1000006], low[1000006], g[1000006][19], clo, stk[1000006], top, ins[1000006], dep[1000006], odd[1000006]; int od[1000006], bel[1000006]; void tarjan(int u, int f) { bel[u] = bel[f]; dfn[u] = low[u] = ++clo, ins[u] = 1; ...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; namespace zzc { inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } const int maxn = 2e5 + 5; i...
CPP
97_E. Leaders
After a revolution in Berland the new dictator faced an unexpected challenge: the country has to be somehow ruled. The dictator is a very efficient manager, yet he can't personally give orders to each and every citizen. That's why he decided to pick some set of leaders he would control. Those leaders will directly orde...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, maxm = maxn << 1; int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 0; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f ? x :...
CPP
99_E. Help Greg the Dwarf
A very unusual citizen lives in a far away kingdom β€” Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg β€” he's been living for over 200 years; besides, he lives in a crypt on an abandoned cemetery an...
2
11
#include <bits/stdc++.h> using namespace std; template <typename T, typename TT> ostream& operator<<(ostream& s, pair<T, TT> t) { return s << "(" << t.first << "," << t.second << ")"; } template <typename T> ostream& operator<<(ostream& s, vector<T> t) { for (int i = 0; i < t.size(); i++) s << t[i] << " "; return...
CPP
99_E. Help Greg the Dwarf
A very unusual citizen lives in a far away kingdom β€” Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg β€” he's been living for over 200 years; besides, he lives in a crypt on an abandoned cemetery an...
2
11
#include <bits/stdc++.h> using namespace std; int a, b, l; double f(double x) { return a * cos(x) + b * sin(x) - l * sin(x) * cos(x); } int main() { scanf("%d%d%d", &a, &b, &l); if (a > b) swap(a, b); if (l <= b) { printf("%.7f", (double)min(a, l)); return 0; } double L = 0, R = acos(0); for (int _ ...
CPP