solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = v * 10 + c - '0';
while (isdigit(c = getchar())) v = v * 10 + c - '0';
x = v * f;
}
inline void read(long lon... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200009], h[200009], q[200009], d[200009], s[200009], sg[200009],
bo[200009];
vector<int> e[200009];
bool vis[200009];
int read() {
int x = 0;
char ch = getchar();
bool flag = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') flag = 1;
ch = get... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A& a, B b) {
if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
if (a < b) a = b;
}... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int h[200200];
struct data {
int to, nxt;
} mp[200200];
int head[200200], cnt;
void link(int x, int y) {
mp[++cnt].to = y;
mp[cnt].nxt = head[x];
head[x] = cnt;
}
int d[200200];
queue<int> q;
vector<int> nx[200200];
int id[200200];
int val[200200];
void To... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0;
bool flg = false;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') flg = true;
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
return flg ? -x : x;
}
int n, m, h[200010], g[200010];
vec... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, maxm = 2e5 + 5;
int head[maxn], nume;
struct edge {
int v, w, c, next;
} e[maxm];
inline void init_edge() {
memset(head, -1, sizeof head);
nume = 0;
}
inline void add_edge(int u, int v, int w = 0, int c = 0) {
e[nume].v = v;
e[nume].w = w... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
register T f = 1;
register char ch = getchar();
t = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
t ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> G[maxn];
int topo[maxn];
int sg[maxn], deg[maxn], mem[maxn];
int Xor[maxn];
long long h[maxn];
int main(void) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) scanf("%lld", &h[i]);
for (int i = 1; i <= m; ++i) {
int ... | 11 | CPP |
#include <bits/stdc++.h>
std::vector<std::vector<int>> ad;
std::vector<int> fm;
std::vector<bool> tmp;
int f(int x) {
if (fm[x] >= 0) return fm[x];
for (int y : ad[x]) f(y);
for (int y : ad[x]) tmp[fm[y]] = true;
fm[x] = int(std::find(begin(tmp), end(tmp), false) - begin(tmp));
for (int y : ad[x]) {
tmp[f... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200500;
vector<int> side[maxn];
int n, m, val[maxn];
long long h[maxn], x[maxn], mx;
void dfs(int u) {
if (val[u] != -1) return;
bool vis[705] = {0};
for (int i = 0; i < side[u].size(); i++) {
int v = side[u][i];
dfs(v);
vis[val[v]] = 1;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + (c & 15);
c = getchar();
}
f ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
if (x < y) x = y;
}
tem... | 11 | CPP |
#include <bits/stdc++.h>
const int N = 200054, M = N;
int V, E;
int w[N], W[N], deg[N];
int to[M], first[N], next[M];
int topo[N], mark[N], sg[N];
inline void up(int &x, const int y) { x < y ? x = y : 0; }
inline void addedge(int u, int v, int id) {
to[id] = v, next[id] = first[u], first[u] = id, ++deg[v];
}
int main... | 11 | CPP |
#include <bits/stdc++.h>
inline 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;
}
int h[200010], SG[200010], sum[200010];
int fir[200010], nxt[200010], dis[200010], ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch - '0' < 0 || ch - '0' > 9) {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch - '0' >= 0 && ch - '0' <= 9) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
in... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename _tp>
inline void read(_tp& x) {
char ch = getchar(), ob = 0;
x = 0;
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') ob = 1, ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
if (ob) x = -x;
}
const int... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const long long INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long b) {
long long s = 1;
wh... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int h[212345];
vector<vector<int> > graph;
vector<int> mex;
vector<int> xors;
int get_mex(int v) {
if (mex[v] != -1) return mex[v];
vector<bool> seen(graph[v].size(), false);
for (auto u : graph[v]) {
int val = get_mex(u);
if (val < seen.size()) seen[val] = tr... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
constexpr int inf32 = 0x3f3f3f3f;
constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<long long> a(n);
for (int u = 0; u < (n); ++u) cin >> a[u];
vector<vector<int> ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)998244353;
const int MAXN = (int)2e5 + 3;
const int infint = (int)1e9 + 3;
const long long inf = (long long)1e18;
int n, m, M[MAXN], visited[MAXN], h[MAXN], t[MAXN];
vector<int> G[MAXN], topol;
void dfs(int u) {
visited[u] = 1;
for (auto v : G[u])
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAXN = 200010;
vector<int> x[MAXN], y[MAXN];
int v[MAXN], out[MAXN], sg[MAXN];
int xr[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> v[i];
for (int i = 0; i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename tp>
inline void read(tp &x) {
x = 0;
char c = getchar();
int f = 0;
for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
;
if (f) x = -x;
}
const int ... | 11 | CPP |
#include <bits/stdc++.h>
const int MAXN = 200010;
int head[MAXN], nxt[MAXN], to[MAXN], ind[MAXN], tot;
void adde(int b, int e) {
nxt[++tot] = head[b];
to[head[b] = tot] = e;
++ind[e];
}
int A[MAXN], mx[MAXN];
std::set<int> S;
int n, m;
std::queue<int> q;
int bfn[MAXN], idx;
int B[MAXN];
int main() {
std::ios_ba... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> E;
vector<int> G;
vector<int> h;
void dfs(int cur) {
if (G[cur] != -1) return;
set<int> S;
for (int i = 0; i < (E[cur].size()); ++i) {
int to = E[cur][i];
dfs(to);
S.insert(G[to]);
}
for (int i = 0; i < (1000000001); ++i) {
if (... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class n, class second>
ostream &operator<<(ostream &p, pair<n, second> x) {
return p << "<" << x.first << ", " << x.second << ">";
}
template <class n>
auto operator<<(ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value,
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a[200005];
struct edge {
int to, nxt;
} e[200005];
int hed[200005], cnt;
inline void add(int u, int v) {
e[++cnt] = (edge){v, hed[u]};
hed[u] = cnt;
}
int num[200005], ru[200005];
int sg[200005], tag[200005], dep[200005];
inline void topo() {
q... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int t, next;
} a[200010], a1[200010];
vector<int> v[200010];
queue<int> q;
int head[200010], head1[200010], num[200010], out[200010], f[200010],
sum[200010], n, m, tot, tot1;
bool vis[200010];
inline int rd() {
int x = 0;
char ch = getchar();
for (... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int read() {
char c = getchar();
int x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x;
}
int n, m;
const int _ = 2e5 + 7;
int val[_], v[_];
vector<int> E[_];
int deg[_];
int st[_], top;
int ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int x = 0, w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') w = 0, ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return w ? x : -x;
}
const ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long h[200005], s[200005];
int n, m, a, b, ru[200006], mex[200005], fu[200005], ma;
vector<int> x[200005];
int dfs(int now) {
if (mex[now]) return mex[now];
for (int i = 0; i < x[now].size(); i++) dfs(x[now][i]);
for (int i = 0; i < x[now].size(); i++) fu[mex[x[n... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005, maxm = 200005;
int n, m, e, stp;
int h[maxn], SG[maxn], start[maxn], to[maxm], then[maxm], xorsum[maxn],
deg[maxn], vis[maxn];
vector<int> v[maxn], revg[maxn], g[maxn];
queue<int> q;
inline void add(int x, int y) {
g[x].push_back(y), deg[x]++;... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int sum(int a, int b) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
int dif(int a, int b) {
int c = a - b;
if (c < 0) {
c += mod;
}
return c;
}
int mlt(int a, int b) {
long long c = a * 1LL * b;
return c % mod;
}
i... | 11 | CPP |
#include <bits/stdc++.h>
const int N = 200005;
int n, m, sg[N];
bool r[N];
long long a[N], sum[N];
std::vector<int> g[N];
bool vis[N];
int dfs(int x) {
if (~sg[x]) return sg[x];
for (int p : g[x]) dfs(p);
for (int p : g[x]) vis[dfs(p)] = 1;
for (int i = 0;; ++i)
if (!vis[i]) {
sg[x] = i;
break;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
long long ver[N << 1], nxt[N << 1], head[N], deg[N], tot;
long long h[N], st[N], vis[N << 1], id[N], t[N << 1], Max, top, n, m;
queue<long long> q;
inline long long read() {
long long x = 0, ff = 1;
char ch = getchar();
while (ch < '0' || c... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int sum(int a, int b) {
int c = a + b;
if (c >= mod) {
c -= mod;
}
return c;
}
int dif(int a, int b) {
int c = a - b;
if (c < 0) {
c += mod;
}
return c;
}
int mlt(int a, int b) {
long long c = a * 1LL * b;
return c % mod;
}
i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct edge {
int to, nxt;
} e[N];
vector<int> G[N];
int deg[N], n, head[N], cnt, m, h[N], mex[N], X[N];
bool vis[N];
queue<int> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", h + i);
while (m--) {
int u, v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-') f = -1;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + ch - 48;
}
return x * f;
}
const int mxN = 2e5;
struct Edge {
int v, nxt;
} ... | 11 | CPP |
#include <bits/stdc++.h>
const int N = 200005;
int n, m, t = -1, he, ta, sg[N], d[N], s[N], q[N];
bool vis[N];
long long h[N];
struct ed {
ed* nxt;
int to;
} pool[N], *p = pool, *lnk[N];
void ae(int u, int v) { *++p = (ed){lnk[u], v}, ++d[v], lnk[u] = p; }
void dfs(int u) {}
int main() {
scanf("%d%d", &n, &m);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
int n, m, i, j, k, h[N], head[N], adj[N], nxt[N], sg[N], q[N], bg, ed, d[N],
s[N];
bool v[N];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= n; ++i) scanf("%d", h + i);
for (i = 1; i <= m; ++i) {
scanf("%d%d", &j, &k);
adj[i] = ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
inline int gi() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return sum;
}
int n, m, val[maxn], Id[maxn], sum[maxn], vis[maxn];
vector<in... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int head[200005], ver[200005], nxt[200005], cnt;
void add(int a, int b) { ver[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt; }
vector<int> e[200005], has[200005];
int n, m, cd[200005];
long long a[200005], sg[200005];
int pos[200005], mex[200005], mx;
bool vis[200005];
queu... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> E[N];
int n, m, h[N], deg[N], vis[N], sg[N], sum[N], sq[N], tt = 0;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> h[i];
for (int i = 1, u, v; i <= m; i++) cin >> u >> v, ++deg[v], E[u].push_back(v);
queue<int> q;... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, m, h[N], q[N], d[N], s[N], vis[N], sg[N];
vector<int> G[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
for (int i = 1, x, y; i <= m; i++)
scanf("%d%d", &x, &y), G[x].push_back(y), d[y]++;
in... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
int n, m, h[N], f[N];
vector<int> G[N];
int d[N], S[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
for (int i = 1, u, v; i <= m; i++)
scanf("%d%d", &u, &v), ++d[v], G[u].push_back(v);
static int q[N];
i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
vector<int> dp;
vector<vector<int> > adj;
int f(int u) {
if (dp[u] != -1) return dp[u];
vector<int> ch;
for (int j = 0; j < (int)adj[u].size(); j++) {
int v = adj[u][j];
ch.push_back(f(v));... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> G[maxn];
int sg[maxn], deg[maxn], Xor[maxn], topo[maxn], mem[maxn], cnt;
long long h[maxn], XOR[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%lld", &h[i]);
for (int i = 0; i < m; ++i) ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(200001);
int c[200001], mex[200001], h[200001], b[200001];
void DFS(int i) {
if (mex[i] >= 0) {
return;
}
for (int j : adj[i]) {
DFS(j);
}
for (int j : adj[i]) {
c[mex[j]] = i;
}
int &k = mex[i];
for (k = 0; c[k] == i; ++... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m, num[200100], sy[200100], ds[200100], bj[200100], sum[200100];
vector<long long> to[200100], pre[200100];
queue<long long> que;
int main() {
long long i, j, t, p, q;
cin >> n >> m;
for (i = 1; i <= n; i++) scanf("%lld", &num[i]);
for (i = 1; i <= m; i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> V[maxn], H[maxn];
int n, m;
long long a[maxn];
int SG[maxn];
int h[maxn];
int maxx = 0;
int dfs(int u) {
if (SG[u] != -1) return SG[u];
vector<int> tmp;
for (auto v : V[u]) {
tmp.push_back(dfs(v));
}
sort(tmp.begin(), tmp.... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, h[200205];
int info[200205], Prev[200205], to[200205], cnt_e;
void Node(int u, int v) {
Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v;
}
int in[200205], Q[200205], L, R, SG[200205], S[200205];
int vis[200205], tim, Mx;
int main() {
scanf("%d%d", &n, ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int h[200000];
vector<int> adjList[200000];
int nim[200000];
int doDFS(int u) {
if (nim[u] != -1) return 0;
int i, j = 0;
vector<int> s;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
doDFS(v), s.push_back(nim[v]);
}
sort(s.begin(), s.e... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2.1e5;
int N, M;
uint64_t H[MAXN];
int outDeg[MAXN];
vector<int> outEdges[MAXN];
vector<int> inEdges[MAXN];
int omegaPow[MAXN];
uint64_t totalNimber[MAXN];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> M;
for (int i =... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 2e5 + 5;
int n, m;
long long h[N];
long long ans[N];
struct Edge {
int num;
int next;
} edge[M];
int tot, last[N];
int du[N];
int sg[N];
queue<int> L;
int node[N], cnt;
int mem[N];
void Add(int i, int j) {
tot++;
edge[tot].num = ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
using ll = long long;
int n, m, top;
vector<int> v[N];
ll a[N], val[N];
int deg[N], p[N], vis[N], id[N], mx;
queue<int> q;
void toposort() {
for (int i = 1; i <= n; i++)
if (!deg[i]) q.push(i);
while (!q.empty()) {
int nd = q.front();
q... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m, h[maxn], u, v, d[maxn], sg[maxn], vis[maxn], chc[maxn], hed[maxn], ed,
s[maxn], cnt;
struct edge {
int to, nex;
edge(int _ = 0, int __ = 0) : to(_), nex(__) {}
} e[maxn];
inline void add(int u, int v) {
e[++ed] = edge(v, hed[u]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200002;
int mex(vector<int>& cands) {
static bool flags[maxN];
for (int i = 0; i <= cands.size(); ++i) {
flags[i] = false;
}
for (int x : cands) {
flags[x] = true;
}
int res = 0;
while (flags[res]) {
++res;
}
return res;
}
stat... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m;
int h[maxn], in[maxn], q[maxn], sg[maxn], sum[maxn], vis[maxn];
vector<int> G[maxn];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d%d",... | 11 | CPP |
#include <bits/stdc++.h>
#pragma optimize("unroll-loops,no-stack-protector")
using namespace std;
namespace io {
struct eof {
eof() {}
};
const int L = (1 << 21) | 5;
char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55];
int f, qr;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = o... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
int n, m, u, v, a[MX], b[MX], ex[MX], x[MX];
vector<int> adj[MX], in[MX];
void dfs(int u) {
if (b[u] != -1) return;
for (int v : adj[u]) dfs(v);
for (int v : adj[u]) ex[b[v]] = u;
b[u] = 0;
while (ex[b[u]] == u) b[u]++;
in[b[u]].push_back(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(200001);
int c[200001], mex[200001], h[200001], b[200001];
void DFS(int i) {
for (int j : adj[i]) {
if (mex[j] >= 0) {
continue;
}
DFS(j);
}
for (int j : adj[i]) {
c[mex[j]] = i;
}
int &k = mex[i];
for (k = 0; c[k] ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct ahowwogaw {
int v, next;
} _[1000005];
int head[1000005], tot = 1, zyl[200005], yihuo[1000005], a[1000005];
bool qwer[1000005];
int fyr(int iakioi) {
if (zyl[iakioi] >= 0) {
return zyl[iakioi];
}
int i, ykb = 0, t;
for (i = head[iakioi]; i; i = _[i].nex... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 200010;
int n, m;
int e, to[M], nxt[M], hd[N], deg[N];
int tag[N], sg[N], val[N], sum[N];
vector<int> vec[N];
void add(int x, int y) {
to[++e] = y;
nxt[e] = hd[x];
hd[x] = e;
}
void topo() {
queue<int> q;
for (int i = 1; i <= n; i++)
... | 11 | CPP |
#include <bits/stdc++.h>
using ll = long long;
int const nmax = 200000;
int v[1 + nmax];
std::vector<int> g[1 + nmax];
int mex(std::vector<int> aux) {
std::sort(aux.begin(), aux.end());
aux.erase(std::unique(aux.begin(), aux.end()), aux.end());
for (int i = 0; i < aux.size(); i++)
if (aux[i] != i) return i;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)2e5 + 5;
int n, m;
vector<int> v[MAX];
int h[MAX];
set<int> s[MAX];
set<int> t[MAX];
int dep[MAX];
int xors[MAX];
vector<pair<int, int> > mxx[MAX];
int bio[MAX];
int p[1000];
void dfs(int cx) {
if (bio[cx]) return;
bio[cx] = 1;
for (int i = (0), _... | 11 | CPP |
#include <bits/stdc++.h>
const int N = 200005;
using namespace std;
long long n, m, num[N], sy[N], ds[N], bj[N], sum[N];
vector<long long> to[N], pre[N];
queue<long long> que;
int main() {
long long i, j, t, p, q;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) scanf("%lld", &num[i]);
for (i = 1; i <= m; i++) {... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
const int N = 2e5 + 5;
long long h[N], s[N];
int w[N];
vector<int> g[N];
bool used[N];
void dfs(int node) {
if (used[node]) return;
used[node] = 1;
vector<int> t;
for (int to : g[node]) {
dfs(to);
t.push_back(w[to]);
}
sor... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m, h[N], nxt[N], adj[N], rd[N], u, v, t, id[N], mx, q[N], top1, top2;
long long a[N], val[N];
bool vs[N];
inline void add() { nxt[++t] = h[u], h[u] = t, adj[t] = v; }
int main() {
scanf("%d%d", &n, &m);
register int i;
for (i = 1; i <= n;... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200200;
vector<int> g[N];
int ord[N];
int ordSz;
bool used[N];
int n, m;
int a[N];
int b[N];
int c[N];
bool mex[N];
void dfs(int v) {
used[v] = 1;
for (int u : g[v]) {
if (used[u]) co... | 11 | CPP |
#include <bits/stdc++.h>
struct city {
int estart;
long long int tax;
bool visited;
int mex;
} v[200003];
struct edge {
int enext, to;
} e[200003];
int n, m;
void dfs(int i) {
v[i].visited = true;
std::vector<int> temp;
for (int j = v[i].estart; j != -1; j = e[j].enext) {
int to = e[j].to;
if (!... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int to, nxt;
} edge[200100];
int val[200100], maxn, cnt, head[200100], n, m;
long long h[200100], X[710];
void addedge(int x, int y) {
edge[++cnt].to = y;
edge[cnt].nxt = head[x];
head[x] = cnt;
}
void dfs(int x) {
if (val[x] != -1) return;
bool vi... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
int n, m;
const int NN = 200011;
int h[NN];
VI adj[NN];
map<int, int> g;
int tot[NN];
inline int get(int u) {
if (g.count(u)) return g[u];
map<int, int> vst;
for (int v : adj[u]) {
vst[get(v)] = 1;
}
for (int i = 0;; i++)
if (vst.co... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn];
bool mark[maxn];
vector<int> v[maxn], vec;
vector<int> vv[maxn];
int p[maxn], xr[maxn], C;
void dfs(int u) {
mark[u] = 1;
for (int y : v[u]) {
if (!mark[y]) dfs(y);
}
vec.push_bac... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long double eps = 0.00000000001;
int n, m;
vector<int> E[300000];
int tab[300000];
int vis[300000];
int levelId[300000];
int levelXor[300000];
void dfs(int a) {
vis[a] = true;
vector<int> L;
for (int v : E[a]) {
if (!vis[v]) {
dfs(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m;
vector<int> edges[N];
bool vis[N];
int mex[N];
int getMex(int u) {
if (~mex[u]) return mex[u];
vector<bool> vis(edges[u].size() + 1, false);
for (int v : edges[u]) {
vis[min(getMex(v), (int)edges[u].size())] = true;
}
mex[u] = 0... | 11 | CPP |
#include <bits/stdc++.h>
const long long INF = 1e18;
const int inf = 1e9;
const int MAXN = 3e5 + 200;
const long double eps = 1e-16;
const long double pi = acos(-1.0);
using namespace std;
int dx[] = {0, 1, 1, 1, -1, -1, -1};
int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
int n, m;
long long a[MAXN], H[MAXN];
int M[MAXN];
vec... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, h[200012], cnt = 0, a[200012], f[200012], b[200012], c[200012];
bool vis[200012];
struct Edge {
int to, next;
} e[200012];
inline void AddEdge(int x, int y) {
e[++cnt] = (Edge){y, h[x]};
h[x] = cnt;
}
void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int gi() {
int x = 0, o = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') o = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * o;
}
vec... | 11 | CPP |
#include <bits/stdc++.h>
int h[200010], SG[200010], sum[200010];
int fir[200010], nxt[200010], dis[200010], id;
void link(int a, int b) { nxt[++id] = fir[a], fir[a] = id, dis[id] = b; }
int que[200010], hd = 1, tl = 1, in[200010];
int c[200010];
int main() {
int n, m, a, b;
scanf("%d%d", &n, &m);
for (int i = 1; ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, nxxt;
} e[200005 << 1];
queue<int> q;
vector<int> v[200005];
bool vis[200005];
int head[200005], cnt = 1, n, m, a[200005], id[200005], b[200005], tot,
rd[200005], tb[200005], xr[200005], mx;
inline void ins(int u, int v) {
e[cnt] ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int c = 200002;
queue<int> q;
vector<int> sz[c], s[c], f[c];
long long n, m, be[c], me[c], t[c], xo[c], maxi;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> t[i], f[i].push_back(c);
for (int i = 1; i <= m; i++... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int NN = 200011;
vector<int> adj[NN];
int n, m;
int h[NN];
int xo[NN];
int g[NN];
int ans[NN];
int vst[NN];
int runs = 1;
int calc(int u) {
if (~g[u]) return g[u];
for (int v : adj[u]) calc(v);
runs++;
for (int v : adj[u]) vst[g[v]] = runs;
for (int i = 0;; ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, SG[200005], Mx, h[200005], sum[200005];
bool vis[200005];
int fir[200005], nxt[200005], to[200005], tot;
inline void line(int x, int y) {
nxt[++tot] = fir[x];
fir[x] = tot;
to[tot] = y;
}
void dfs(int u) {
for (int i = fir[u]; i; i = nxt[i])
if (!SG[to... | 11 | CPP |
#include <bits/stdc++.h>
using std::cerr;
using std::endl;
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 - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 200005;
int ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
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)... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int c = 200002;
queue<int> q;
vector<int> sz[c], s[c], f[c];
long long n, m, be[c], me[c], t[c], xo[c], maxi;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> t[i], f[i].push_back(c);
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;... | 11 | CPP |
m = int(input())
l = [0 for _ in range(m + 1)]
for _ in range(m - 1):
a,b = map(int, input().split())
l[a] += 1
l[b] += 1
if 2 in l:
print("NO")
else:
print("YES")
| 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void pr_init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
vector<vector<long long> > tree;
vector<long long> deg;
void solve() {
long long n;
cin >> n;
tree.assign(n + 1, vector<long long>());
deg.assign(n + 1, 0);
for (long long i = 0; i < n... | 10 | CPP |
# @author
import sys
class D1AddOnATree:
def dfs(self, start):
self.done[start] = 1
for x in self.adj[start]:
if self.done[x]:
continue
self.par[x] = start
self.dfs(x)
def solve(self):
from collections import defaultdict
impo... | 10 | PYTHON3 |
n=int(input())
deg=[0]*n
for i in range(n-1):
u,v=map(int,input().split())
u-=1
v-=1
deg[u]+=1
deg[v]+=1
for d in deg:
if d==2:
print("NO")
exit(0)
print("YES") | 10 | PYTHON3 |
from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())
def solve():
n = int(input())
cnt = defaultdict(int)
for _ in range(n-1):
x,y = ri()
cnt[x] += 1
cnt[y] += 1
valid = True
for x in cnt... | 10 | PYTHON3 |
n = int(input())
tree_nums = [0 for i in range(n)]
for i in range(n - 1):
a1, a2 = map(int, input().split())
tree_nums[a1 - 1] += 1
tree_nums[a2 - 1] += 1
if n == 2:
print('YES')
elif n == 3:
print('NO')
else:
ans_is_no = False
for i in range(n):
if tree_nums[i] == 2:
ans... | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ind[n];
memset(ind, 0, sizeof(ind));
int u, v;
for (int i = 0; i < n - 1; i++) {
cin >> u >> v;
u--;
v--;
ind[u]++;
ind[v]++;
}
bool f = 1;
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++) {
if (in... | 10 | CPP |
n = int(input())
gr = {i: 0 for i in range(1, n + 1)}
for i in range(n - 1):
a, b = map(int, input().split())
gr[a] += 1
gr[b] += 1
for i in gr:
if gr[i] == 2:
print('NO')
exit(0)
print('YES') | 10 | PYTHON3 |
n = int(input())
arr = [0] * (n+1)
for _ in range(n-1):
a,b = map(int,input().split())
arr[a] += 1
arr[b] += 1
for i in range(1,n+1):
if arr[i] == 2:
print("NO")
break
else:
print("YES")
| 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int power(long long int x, long long int y) {
long long int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
bool prime_check(long long int n) {
long long int i, j;
if (n == 1) {
... | 10 | CPP |
n = int(input())
g = [[] for i in range(n+1)]
d = [0]*100001
for i in range(n-1):
u, v = [int(i) for i in input().split()]
g[u].append(v)
g[v].append(u)
d[u] += 1
d[v] += 1
for i in d:
if i == 2:
print("NO")
break
else:
print("YES")
| 10 | PYTHON3 |
n = int(input())
edges = [0] * (n)
for i in range(n-1):
a, b = list(map(int, input().split()))
edges[a-1] +=1
edges[b-1] +=1
if 2 in edges:
print("NO")
else:
print("YES") | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, p, q;
vector<int> G[100005];
int main() {
cin >> n;
for (i = 0; i < n - 1; i++) {
cin >> p >> q;
G[p - 1].push_back(q - 1);
G[q - 1].push_back(p - 1);
}
bool flag = false;
for (i = 0; i < n; i++) {
if (G[i].size() == 2) {
flag... | 10 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.