solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; const int N = 3005; struct edge { int to, next; } e[N * 2]; int head[N], tot; int vis[N], q[N], V; int deg[N], n, sz; double ans; void add(int x, int y) { e[++tot] = (edge){y, head[x]}; head[x] = tot; } void dfs(int x, int A, int B) { deg[x] == 2 ? B++ : A++; vis[...
10
CPP
#include <bits/stdc++.h> char ch; inline void read(int &x) { x = 0; ch = getchar(); while (ch <= 32) ch = getchar(); while (ch > 32) { x = x * 10 + ch - 48; ch = getchar(); }; }; int n; struct edge { edge *next; int y; }; edge *se[3005], e[3005 * 2], *etot = e; inline void addedge(int x, int y) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; int n, inR[MAXN], dep[MAXN], jmp[13][MAXN]; int top, stk[MAXN], ins[MAXN], bl[MAXN], rt, ringo[MAXN]; vector<int> T[MAXN], Ring; void dfs(int x, int fa) { ins[stk[++top] = x] = 1; for (int v : T[x]) if (v != fa) { if (ins[v]) throw v; ...
10
CPP
#include <bits/stdc++.h> const int MAXN = 3000; struct edge { int to; edge *nxt; } edges[2 * MAXN + 5], *adj[MAXN + 5], *ecnt = edges; void addedge(int u, int v) { edge *p = (++ecnt); p->to = v, p->nxt = adj[u], adj[u] = p; p = (++ecnt); p->to = u, p->nxt = adj[v], adj[v] = p; } bool vis[MAXN + 5], tag[MAXN...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 100005; inline int read() { int res, ok = 1; char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') ok = -1; res = ch - '0'; for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar()...
10
CPP
#include <bits/stdc++.h> const int maxn = 3005; const int maxm = 6005; const int inf = 999999999; struct edge { int to, next; }; int n; edge e[maxm]; int head[maxn], tot; int stn[maxn], stk[maxn], top = 1; int cir[maxn], circ; int cirr[maxn]; bool vis[maxn]; int dis[maxn][maxn]; bool vis2[maxn][maxn]; void dfs2(int u...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3010; vector<int> e[N]; double ans = 0; int n, h, t, rt, tot, d[N], vis[N], q[N]; void dfs(int u, int a, int b) { if (d[u] == 2) ++b; else ++a; vis[u] = rt; if (b == tot) ans += 1.0 / (a + 2); else if (b <= 2) ans += 1.0 / (a + b); ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005, mod = 1e9 + 7; inline int read() { int s = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return s; } inline long long qpow(long long a, long long b) { long long res = 1...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; int To[MAXN * 2], Next[MAXN * 2], Final[MAXN], tot; int Circle[MAXN], Deep[MAXN], Fa[MAXN][MAXN], Lst[MAXN], Top[MAXN], P[MAXN], N, Up, Down; void Link(int u, int v) { To[++tot] = v, Next[tot] = Final[u], Final[u] = tot; } int Get(int a) { return ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MX = 3500; int N; struct Edge { int y, nx; } E[MX << 1]; int H[MX], ec; void Add(int x, int y) { E[++ec].y = y, E[ec].nx = H[x], H[x] = ec; } int B[MX], dfn[MX], low[MX], dc; int Cr[MX], Ic[MX], cc, stk[MX], tp; void Tarjan(int x, int f) { B[x] = 1, dfn[x] = l...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; struct _two { int a, b; } edge[N + N], p[N]; double ans; int n, tot, num, pos, tnum; int st[N], flag[N], stack[N], qu[N], tqu[N]; void Init() { scanf("%d", &n); int x, y; tot = 1; for (int i = 1; i <= n; i++) { scanf("%d%d", &x, &y); x+...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int 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'; ch = getchar(); } return x * f; } double ans; int n, cnt,...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3333; int n; vector<int> g[N]; int inside[N]; int deg[N]; vector<int> dist0[N], dist1[N]; void dfs(int v, int d0, int d1) { if (inside[v]) { return; } dist0[v].push_back(d0); dist1[v].push_back(d1); inside[v] = 1; for (int j = 0; j < (int)g[v]....
10
CPP
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); template <typename _Tp> _Tp gcd(const _Tp &a, const _Tp &b) { return (!b) ? a : gcd(b, a % b);...
10
CPP
#include <bits/stdc++.h> using namespace std; namespace Fread { const int MAXN = 1 << 20; char buffer[MAXN], *S, *T; inline char getchar() { if (S == T) { T = (S = buffer) + fread(buffer, 1, MAXN, stdin); if (S == T) return EOF; } return *S++; } } // namespace Fread inline int read() { int f = 1, x = 0...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> G[3005]; int stk[3005], tp, instk[3005]; vector<int> cyc; int incyc[3005]; bool flag; inline void findCycle(int u, int pa) { stk[++tp] = u; instk[u] = 1; for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if (v == pa) continue; if ...
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const bool db = false; vector<int> gr[3010]; double res; int mark[3010], color; int ds[3010], ds2[3010]; int deg[3010], n, m; int Len; void dfs(int v) { mark[v] = 1; for (int i = 0, sz = gr[v].size(); i < sz; ++i) { int t...
10
CPP
#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; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 3010; vector<int> e[N], dis[N]; int q[N], n, u, ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int M = 3005; vector<int> eg[M]; int n; int fa[M], cnt[M], sz[M]; int getfa(int x) { if (fa[x] == x) return x; return fa[x] = getfa(fa[x]); } double ans; int pl[M], psz; int mark[M], TIM; void dfs_jih_pre(int x) { pl[psz++] = x; mark[x] = TIM; for (int i = 0...
10
CPP
#include <bits/stdc++.h> using namespace std; struct node_ { int v, next; } node[6005]; int head[3005], e, fa[3005][14], gf[3005]; int bj[3005], bjj = 0; bool b[3005]; void addnode(int u, int v) { e++; node[e].v = v; node[e].next = head[u]; head[u] = e; } int flag = 0; int n; int dep[3005]; void dfs(int t, in...
10
CPP
#include <bits/stdc++.h> using namespace std; int c[3050 * 2][2], ss = 1, h[3050][2], fi[3050], n, m, len; bool b[3050], flag = false; double ans; inline int Read() { int x = 0; char y; do y = getchar(); while (y < '0' || y > '9'); do x = x * 10 + y - '0', y = getchar(); while (y >= '0' && y <= '9'); retu...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-11; const long double pi = acos(-1); const int oo = 1 << 30; const long lon...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
10
CPP
#include <bits/stdc++.h> using namespace std; struct bian { int next, point; } b[7000]; int p[4000], n, len, pd[4000], x[4000], s[4000], head, bo[4000], d[4000], u[4000]; long double ans; void ade(int k1, int k2) { b[++len] = (bian){p[k1], k2}; p[k1] = len; } void add(int k1, int k2) { ade(k1, k2); ade(k2...
10
CPP
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } if (flag) x = -x; } using name...
10
CPP
#include <bits/stdc++.h> using namespace std; int lca[3005][3005]; int last[3005]; int cir[3005]; int lab[3005]; int par[3005]; int pre[6005]; int dep[3005]; int e[6005]; int f[3005]; int h[3005]; int n, m, cnt; int find_cir(int x, int par, int cirst) { int i; h[x] = 1; for (i = last[x]; i != 0; i = pre[i]) i...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005, M = N << 1; int n, tot, len, du[N], now[N], prep[M], son[M]; double ans; void read(int &x) { x = 0; int f = 1; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10...
10
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int NN = 3011; inline int read() { int t = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') f = (ch == '-') ? -1 : 1, ch = getchar(); while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar(); return t * f; } double...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; int n, ai, bi; vector<int> G[MAXN]; int deg[MAXN]; vector<pair<int, int> > C[MAXN]; int nxt(int i, int p) { for (int j : G[i]) if (deg[j] == 2) { if (j == p) continue; return j; } return -1; } double prob(int d) { return 2.0 / ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MXN = 100005; int N, loid[MXN], islolo[MXN]; int bln[MXN], dep[MXN]; vector<int> E[MXN]; vector<int> lolo; int ins[MXN]; vector<int> stk; long double ans; bool DFS1(int u, int f) { ins[u] = 1; stk.push_back(u); for (auto v : E[u]) { if (v == f) continue;...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, m, dep[5000], id[5000], cnt, sum, acc[5000], lca[3020][3020], f[5000]; int dfn[5000], low[5000], ist[5000], belong[5000], tot[5000], maxid; double Ans; stack<int> a; vector<int> v[5000]; inline void tarjan(int x, int fa) { dfn[x] = low[x] = ++cnt; a.push(x); is...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxlog = 13; const int maxn = 3003; int n; vector<int> g[maxn]; bool vis[maxn], mark[maxn]; int pos[maxn], cnt; int dis[maxn], r[maxn], d[maxn][maxlog]; long double ans; void go(int v, int u) { if (mark[v]) return; for (int i = 0; v != d[u][0]; i++) { mark...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3000 + 3; struct Edge { int to, nxt; } e[N << 1]; int n, cnt; int hd[N], top, q[N], tail, cur[N], c[N], pos[N], belong[N], fa[N][13], dep[N]; bool vis[N], used[N]; long double ans; inline void addedge(int x, int y) { e[++top].to = y; e[top].nxt = hd[x]; ...
10
CPP
#include <bits/stdc++.h> using namespace std; stack<int> st; int head[333000], cnt, ins[333000], is[333000], c[333000], id[333000], le, vis[333000], ntt[333000], s1[333000], s2[333000], s3[333000], s4[333000], s5[333000], sth[2220000 * 5], lb[333000], len[333000], rev[333000], n, m, a, b, ds[333000], mx1, v...
10
CPP
#include <bits/stdc++.h> using namespace std; int head[5010]; int from[5010]; int to[100010]; int nex[100010]; int dep[5010]; int q[5010]; int cnt; int vis[5010]; int bel[5010]; int num[100010]; double ans; int tot; int x, y, n, m; int f[5010][17]; void add(int x, int y, int z) { nex[++tot] = head[x]; head[x] = tot...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, fa[N], dfn[N], ord, mark[N], len, vis[N]; vector<int> G[N]; void dfs(int u) { dfn[u] = ++ord; for (auto& v : G[u]) if (v ^ fa[u]) { if (!dfn[v]) { fa[v] = u; dfs(v); } else if (dfn[v] < dfn[u]) { for (in...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> using vec = vector<T>; template <typename Iter> ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = "", const string se = "") { o << ss; for (auto it = b; it != e; it++) o << (it == b ? "" : ", ") << *it; return...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000 + 10; namespace opt { int N; const int alp = 999, MOD = 1004535809; static int a[MAXN], b[MAXN], w[MAXN], tmp[MAXN]; int Pow(int a, int b) { int d = 1; for (; b; d = (b & 1) ? (long long)d * a % MOD : d, a = (long long)a * a % MOD, b /=...
10
CPP
#include <bits/stdc++.h> const int MAXN = 3005, MAXLOG = 15; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s - '0'), s = getchar(); } ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; const int MAXE = MAXN << 1; int N; int e[MAXE], enxt[MAXE], head[MAXN], ec; void regi(int u, int v) { e[++ec] = v; enxt[ec] = head[u]; head[u] = ec; } int visId[MAXN]; vector<int> Loop, stk; bool FindLoop(int ths, int prev) { if (visId[ths] !=...
10
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long Inf = 1e10; const int N = 100005; const int P = 1000000007; int IN() { int x = 0; int f = 0, ch = 0; for ((ch = getchar()); ch < 48 || ch > 57; (ch = getchar())) f = (ch == '-'); for (; ch >= 48 && ch <= 57; (ch = getchar())) ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; struct E { int to, next; } mem[N << 1]; int n, x, y, num, h, t, c; double ans; int head[N], d1[N], d2[N], q[N]; bool vis[N]; void add(int x, int y) { num++; mem[num].to = y; mem[num].next = head[x]; head[x] = num; } void init() { int k, u; ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> using vec = vector<T>; template <typename Iter> ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = "", const string se = "") { o << ss; for (auto it = b; it != e; it++) o << (it == b ? "" : ", ") << *it; return...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 4011; namespace RikukiIX { int n; int xi, yi; struct sumireko { int to, ne; } e[N << 1]; int he[N], ecnt; void addline(int f, int t) { e[++ecnt].to = t; e[ecnt].ne = he[f]; he[f] = ecnt; } int sta[N], stp; int vis[N]; int sp; int onr[N], rnd[N], ra; in...
10
CPP
#include <bits/stdc++.h> const int sz = 3010; int vi[sz], low[sz], t; int sta[sz], top = 0; int con[sz], cir[sz]; std::vector<int> edge[sz], ed[sz]; void dfs(int x, int p) { vi[x] = low[x] = ++t; sta[top++] = x; for (int k = 0; k < edge[x].size(); k++) { int y = edge[x][k]; if (!vi[y]) dfs(y, x); if (...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> E[3005]; int deg[3005], V[3005]; int sz; double ans; void dfs(int r, int i, int A, int B) { deg[i] == 2 ? ++B : ++A; V[i] = r; if (B == sz) ans += 1.0 / (A + 2); else if (B <= 2) ans += 1.0 / (A + B); else ans += 1.0 / (A + B) + 1.0 / (A + ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, m, flag, sum, tot, dis[3001][3001], e[100001], nt[100001], hd[100001], pa[100001], v[3001], d[3001], f[3001], sz[3001]; double ans; void build(int x, int y) { tot++; e[tot] = y; nt[tot] = hd[x]; hd[x] = tot; } void dfs(int x, int fa) { int i, y; if (v...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; int q[N]; int fa[N], dep[N]; int n, co[N], dis[N]; vector<int> e[N]; double ans; void dfs(int x) { for (auto i : e[x]) if (i != fa[x]) { if (!dep[i]) { fa[i] = x; dep[i] = dep[x] + 1; dfs(i); } else if (dep[i] < ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; inline void read(int &x) { x = 0; int 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'; ch = getchar(); } x *= f;...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; int N, C, cnt, d[maxn], q[maxn], head[maxn], d1[maxn], d2[maxn]; double ans; struct Data { int next, to; } data[maxn << 1]; bool vis[maxn]; void add(int x, int y) { data[++cnt] = (Data){head[x], y}; head[x] = cnt; } void dfs(int x) { vis[x] = ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> inline void write(F x, char...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> v[3005]; bool vis[3005], cir[3005]; int q, s, n; int Find_Cir(int x, int y) { vis[x] = 1; for (int i = 0; i < v[x].size(); i++) if (!vis[v[x][i]]) { int t = Find_Cir(v[x][i], x); if (t) { if (t > 0) { cir[x] = 1; s...
10
CPP
#include <bits/stdc++.h> using namespace std; int hed[3005], to[3005 << 1], nxt[3005 << 1], q[3005], cnt, tot; bool in[3005], used[3005]; int n, deg[3005], C; double ans; void ins(int x, int y) { nxt[++tot] = hed[x]; to[tot] = y; hed[x] = tot; } void dfs(int x, int len, int lcn) { used[x] = 1; if (lcn <= 1) ...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int 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 << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * f; } const int...
10
CPP
#include <bits/stdc++.h> std::set<std::pair<int, int> > set; int head[3010], nxt[6010], b[6010], k, n, u, v, fa[3010], cnt, rt; bool vis[3010]; long double ans; void push(int s, int t) { nxt[++k] = head[s]; head[s] = k; b[k] = t; } void getloop(int x, int f) { if (vis[x]) { u = x, v = f; return; } v...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; vector<int> g[N]; int n, cirLen, stk[N], top, vis[N], findCir, onCir[N]; double ans; void dfs(int v, int p) { stk[++top] = v; vis[v] = 1; for (int d : g[v]) if (d != p) { if (!vis[d]) { dfs(d, v); if (findCir) return; ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> void ckmax(T& a, T b) { if (b > a) a = b; } template <typename T> void ckmin(T& a, T b) { if (b < a) a = b; } struct _in { const _in operator,(int& a) const { a = 0; char k = getchar(); int f = 1; for (; !isdigit(k); k = getchar()...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MX = 3500; int N; struct Edge { int y, nx; } E[MX << 1]; int H[MX], ec; void Add(int x, int y) { E[++ec].y = y, E[ec].nx = H[x], H[x] = ec; } int B[MX], dfn[MX], low[MX], dc; int Cr[MX], Ic[MX], cc, stk[MX], tp; void Tarjan(int x, int f) { B[x] = 1, dfn[x] = l...
10
CPP
#include <bits/stdc++.h> using namespace std; int head[5010]; int from[5010]; int to[100010]; int nex[100010]; int dep[5010]; int q[5010]; int cnt; int vis[5010]; int bel[5010]; int num[100010]; double ans; int tot; int x, y, n, m; int f[5010][17]; void add(int x, int y, int z) { nex[++tot] = head[x]; head[x] = tot...
10
CPP
#include <bits/stdc++.h> using namespace std; queue<int> q; int head[5009], tot, du[5009], n, cnt; double ans; int vis[5009]; inline int rd() { int x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3333; int n, m, a[N], b[N], c[N], d[N], f[N]; vector<int> v[N], h; double ans, w[N]; int fnd(int x) { if (f[x] == x) return x; return f[x] = fnd(f[x]); } void dfs0(int u, int o) { if (b[u]) return; if (!b[o]) h.push_back(u); b[u] = 1; for (int i = ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3000 + 10; struct Graph { int id, next; } g[MAXN * 2]; int st[MAXN], dep[MAXN], fa[MAXN], bel[MAXN], n, lca[MAXN][MAXN], num[MAXN]; bool vis[MAXN]; vector<int> L; void Add(int tot, int x, int y) { g[tot].id = y, g[tot].next = st[x], st[x] = tot; } int f...
10
CPP
#include <bits/stdc++.h> struct Vertex { bool vis; int head, top, dist; Vertex() : vis(false), head(0), top(0), dist(0) {} } vertex[3005]; struct Edge { int to, next; Edge(int __to = 0, int __next = 0) : to(__to), next(__next) {} } edge[6005]; int n, ptr, dist[3005][3005]; std::vector<int> circle; void addEdg...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { char ch; x = 0; bool fl = false; while (!isdigit(ch = getchar())) (ch == '-') && (fl = true); for (x = (ch ^ '0'); isdigit(ch = getchar()); x = x * 10 + (ch ^ '0')) ; (fl == true) && (x = -x); } template <class T> in...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x; } int tot = 1; int fir[3010], nex[3010 << 1], got[3010 << 1]; inline void AddEdge(int x, int y) { nex[++...
10
CPP
#include <bits/stdc++.h> using namespace std; int g() { char ch; bool f = 0; while (!((ch = getchar() - 48) >= 0)) if (ch == -3) f = 1; int v = ch; while (((ch = getchar() - 48) >= 0)) v = v * 10 + ch; return f ? -v : v; } const int Maxn = 3005; vector<int> p[Maxn]; long double ans; int n, R; bool mark[...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, tot, fst[N], to[2 * N], nxt[2 * N], cir[N], pos[N], len, dep[N], fa[N], subt[N], st[N], top, dis[N]; bool vis[N]; void addedge(int u, int v) { nxt[++tot] = fst[u]; fst[u] = tot; to[tot] = v; nxt[++tot] = fst[v]; fst[v] = tot; to[to...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n; double ans; double inv[N]; struct Edge { int ce; int hd[N], nxt[N * 2], v[N * 2]; void ade(int x, int y) { ce++; nxt[ce] = hd[x]; v[ce] = y; hd[x] = ce; } }; Edge T; int lenc, tp; int fa[N], dep[N], cir[N], lc[N], rc[N]; vo...
10
CPP
#include <bits/stdc++.h> using namespace std; pair<int, int> it; int n, f[3010], x, y, fa[3010], dep[3010], tot, L[3010], t, tmp[3010], num[3010], belong[3010]; vector<int> E[3010]; int dis[3010][3010]; bool vis[3010]; queue<int> h; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != '-' && (c...
10
CPP
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-10; inline int read() { static char ch; bool sgn = false; while (ch = getchar(), ch < '0' || ch > '9') if (ch == '-') sgn = true; int res = ch - 48; while (ch = getchar(), ch >= '0' && ch <= '9') res = res * ...
10
CPP
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[6005]; int n, m, head[3005], d[3005], d2[3005], num, c; bool ok[3005]; queue<int> q; double ans; inline void insert(int u, int v) { e[++num].to = v; e[num].next = head[u]; head[u] = num; e[++num].to = u; e[num].next = head[v]; h...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, stk[N], top, num[N], cyc[N], idx; bool vis[N], instk[N], fl; vector<int> v[N]; void dfs(int pos, int fa) { stk[++top] = pos; instk[pos] = 1; for (auto &i : v[pos]) { if (i == fa) continue; if (!instk[i]) return dfs(i, pos); if (f...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; template <typename T> T _abs(T a) { return (a < 0) ? (-a) : (a); } int n, m; vector<int> cir; vector<int> G[N]; stack<int> S; bool vis[N], onc[N]; void dfs(int p, int fa) { if (vis[p]) { int cur; do { cur = S.top(); S.pop(); ...
10
CPP
#include <bits/stdc++.h> using namespace std; int N, lk[6005], nx[6005], head[3005], s[3005], d[3005], dfn[3005], tot, L, p[3005], q[3005], fa[3005], f[3005][3005]; bool b[3005]; void init() { scanf("%d", &N); auto add = [&](int u, int v, int t) { lk[t] = v, nx[t] = head[u], head[u] = t; }; for (int i =...
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; const double inf = 1e121; const double eps = 1e-10; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long randint(long long l, long long r) { long long out = rng() % (r - l + ...
10
CPP
#include <bits/stdc++.h> using namespace std; int read() { char c = getchar(); long long x = 1, s = 0; while (c < '0' || c > '9') { if (c == '-') x = -1; c = getchar(); } while (c >= '0' && c <= '9') { s = s * 10 + c - '0'; c = getchar(); } return s * x; } const int N = 4000; int n, x, y, ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> v[3030]; void init() { scanf("%d", &n); for (int i = 0; i < n; i++) { int ai, bi; scanf("%d%d", &ai, &bi); v[ai].push_back(bi); v[bi].push_back(ai); } } bool oncyc[3030], instk[3030]; int vst[3030], p[3030][14], dep[3030], stk[3030];...
10
CPP
#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 _ = 3001; struct Edge { int end, upEd; } Ed[_ << 1]; int head[_], cntEd, N; void addEd(int a...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; int read() { int x = 0, f = 1; char ch; while (!isdigit(ch = getchar())) (ch == '-') && (f = -f); for (x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48)) ; return x * f; } template <class T> T Abs(T a) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> edge[3100]; int cir[3100], vi[3100], cirlen; int _lca[3100][3100], fa[3100], dep[3100]; void dfs2(int x) { dep[x] = dep[fa[x]] + 1; vi[x] = 1; for (typeof((edge[x]).begin()) y = (edge[x]).begin(); y != (edge[x]).end(); y++) if (*y != fa[x...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int Get() { int res = 0, q = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') q = -1, ch = getchar(); while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return res * q; } const doubl...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 3005; int n, dep[maxn], point[maxn << 1], nextp[maxn << 1], head[maxn], cir[maxn], len, ecnt; void ins(int u, int v) { point[++ecnt] = v; nextp[ecnt] = head[u]; head[u] = ecnt; } int dfs(int x, int f) { dep[x] = dep[f] + 1; int i, to, tmp, res...
10
CPP
#include <bits/stdc++.h> using namespace std; struct edge { int v, next; } e[6005]; int etot = 0; int g[3005]; void ae(int u, int v) { e[etot].v = v; e[etot].next = g[u]; g[u] = etot++; } int n; double ans = 0.0; int pre[3005], vis[3005]; int cyc[3005], len = 0; int oncy[3005] = {0}; int dfs(int u) { vis[u] =...
10
CPP
#include <bits/stdc++.h> using namespace std; int head[5010]; int from[5010]; int to[100010]; int nex[100010]; int dep[5010]; int q[5010]; int cnt; int vis[5010]; int bel[5010]; int num[100010]; double ans; int tot; int x, y, n, m; int f[5010][17]; void add(int x, int y, int z) { nex[++tot] = head[x]; head[x] = tot...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, mark[((int)3030)], pos[((int)3030)], dp[((int)12)][((int)3030)], dis[((int)3030)]; long double ans; vector<int> e[((int)3030)], now, cycle; bool dead[((int)3030)]; void dfs_cycle(int x, int par = 0) { mark[x] = 1; now.push_back(x); for (auto u : e[x]) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3000 + 5; int n; int hd[N], to[N * 2], nxt[N * 2]; inline void add_se(int idx, int a, int b) { nxt[idx] = hd[a]; hd[a] = idx; to[idx] = b; } int sz_circ, circ[N], at_circ[N], stk[N], stkfr[N], b_stk; ; bool vis[N], incirc[N], e_incirc[N]; bool dfs_circ(i...
10
CPP
#include <bits/stdc++.h> namespace ringo { template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } template <class T> inline void print(T x) { if (x < 0) pu...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> adj[3000]; bool visited[3000]; bool incycle[3000]; int find_cycle(int u, int p) { if (visited[u]) return u; visited[u] = true; for (int c : adj[u]) if (c != p) { int x = find_cycle(c, u); if (x != -1) { incycle[u] = true; re...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& num) { num = 0; bool f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { num = num * 10 + ch - '0'; ch = getchar(); } num =...
10
CPP
#include <bits/stdc++.h> using namespace std; struct graph { int nxt, to; } e[3005 << 1]; int g[3005], t[3005], d1[3005], d2[3005], n, cnt; bool ins[3005]; double ans; queue<int> q; inline int read() { int ret = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { ret = (ret << 1...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; int n; int deg[MAXN]; vector<int> edges[MAXN]; double ans = 0; int vis[MAXN]; int dist[MAXN], dist2[MAXN]; int cirsiz = 0; void dfs(int x) { vis[x] = 1; for (auto nex : edges[x]) if (!vis[nex]) { dist2[nex] = dist2[x] + 1; if (!dis...
10
CPP
#include <bits/stdc++.h> long long gi() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f ^= ch == '-', ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? x : -x; } std::mt19937 rnd(time(NULL)); template <class T> void cxk(T& a, T b) { a = a > b ? a : b...
10
CPP
#include <bits/stdc++.h> const int maxn = 3010; const int maxm = 6010; using namespace std; int ter[maxm], nxt[maxm], lnk[maxn], d[maxn]; int n, m, e, tot, opt[maxn], pos[maxn], dis[maxn], bel[maxn], fa[maxn][20]; bool cir[maxn], vis[maxn]; void add(int x, int y) { ter[++e] = y, nxt[e] = lnk[x], lnk[x] = e; ter[++e...
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29, N = 5e5 + 50, M = 1e6 + 5; inline int read() { int f = 1, x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getc...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 100010, M = 1000010, P = 1e9 + 7; const int inf = 0x3f3f3f3f; const int INF = 0xcfcfcfcf; const double eps = 1e-9, pi = asin(1) * 2; inline long long read(); inline int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; } inline int MINUS(int a, int b)...
10
CPP
#include <bits/stdc++.h> using namespace std; int vis[3010]; vector<int> ne[3010]; int n, siz; int du[3010]; queue<int> q; double ans; void dfs(int u, int siza, int sizb, int top) { if (du[u] == 2) sizb++; else siza++; vis[u] = top; if (sizb == siz) ans += 1.0 / (siza + 2); else if (sizb <= 2) ...
10
CPP
#include <bits/stdc++.h> using namespace std; void file(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } template <typename Tp> void read(Tp &x) { int fh = 1; char c = getchar(); x = 0; while (c > '9' || c < '0') { if (c == '-') { fh = -1; } ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T1> void debug(T1 e) { cout << e << endl; } template <class T1, class T2> void debug(T1 e1, T2 e2) { cout << e1 << "\t" << e2 << endl; } template <class T1, class T2, class T3> void debug(T1 e1, T2 e2, T3 e3) { cout << e1 << "\t" << e2 << "\t" << e3 <<...
10
CPP
#include <bits/stdc++.h> using namespace std; struct road { int x, next; } r[3005 * 2]; int N, M; double ans; int fa[3005], flag; int st[3005], w, vis[3005], pr[3005]; int deep[3005], lca[3005][3005], rt[3005]; int loop[3005], num[3005], cnt; int stk[3005], top; int find(int x) { if (fa[x] == x) return x; return ...
10
CPP