QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386616 | #8551. DFS Order 5 | ucup-team087# | AC ✓ | 148ms | 18672kb | C++20 | 24.1kb | 2024-04-11 18:39:33 | 2024-04-11 18:39:33 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name( \
a, vector<vector<vector<type>>>( \
b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) \
for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
(check(x) ? ok : ng) = x;
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids),
[&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/graph/tree.hpp"
#line 2 "library/graph/base.hpp"
template <typename T>
struct Edge {
int frm, to;
T cost;
int id;
};
template <typename T = int, bool directed = false>
struct Graph {
static constexpr bool is_directed = directed;
int N, M;
using cost_type = T;
using edge_type = Edge<T>;
vector<edge_type> edges;
vector<int> indptr;
vector<edge_type> csr_edges;
vc<int> vc_deg, vc_indeg, vc_outdeg;
bool prepared;
class OutgoingEdges {
public:
OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}
const edge_type* begin() const {
if (l == r) { return 0; }
return &G->csr_edges[l];
}
const edge_type* end() const {
if (l == r) { return 0; }
return &G->csr_edges[r];
}
private:
const Graph* G;
int l, r;
};
bool is_prepared() { return prepared; }
Graph() : N(0), M(0), prepared(0) {}
Graph(int N) : N(N), M(0), prepared(0) {}
void build(int n) {
N = n, M = 0;
prepared = 0;
edges.clear();
indptr.clear();
csr_edges.clear();
vc_deg.clear();
vc_indeg.clear();
vc_outdeg.clear();
}
void add(int frm, int to, T cost = 1, int i = -1) {
assert(!prepared);
assert(0 <= frm && 0 <= to && to < N);
if (i == -1) i = M;
auto e = edge_type({frm, to, cost, i});
edges.eb(e);
++M;
}
#ifdef FASTIO
// wt, off
void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }
void read_graph(int M, bool wt = false, int off = 1) {
for (int m = 0; m < M; ++m) {
INT(a, b);
a -= off, b -= off;
if (!wt) {
add(a, b);
} else {
T c;
read(c);
add(a, b, c);
}
}
build();
}
#endif
void build() {
assert(!prepared);
prepared = true;
indptr.assign(N + 1, 0);
for (auto&& e: edges) {
indptr[e.frm + 1]++;
if (!directed) indptr[e.to + 1]++;
}
for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
auto counter = indptr;
csr_edges.resize(indptr.back() + 1);
for (auto&& e: edges) {
csr_edges[counter[e.frm]++] = e;
if (!directed)
csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
}
}
OutgoingEdges operator[](int v) const {
assert(prepared);
return {this, indptr[v], indptr[v + 1]};
}
vc<int> deg_array() {
if (vc_deg.empty()) calc_deg();
return vc_deg;
}
pair<vc<int>, vc<int>> deg_array_inout() {
if (vc_indeg.empty()) calc_deg_inout();
return {vc_indeg, vc_outdeg};
}
int deg(int v) {
if (vc_deg.empty()) calc_deg();
return vc_deg[v];
}
int in_deg(int v) {
if (vc_indeg.empty()) calc_deg_inout();
return vc_indeg[v];
}
int out_deg(int v) {
if (vc_outdeg.empty()) calc_deg_inout();
return vc_outdeg[v];
}
#ifdef FASTIO
void debug() {
print("Graph");
if (!prepared) {
print("frm to cost id");
for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
} else {
print("indptr", indptr);
print("frm to cost id");
FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
}
}
#endif
vc<int> new_idx;
vc<bool> used_e;
// G における頂点 V[i] が、新しいグラフで i になるようにする
// {G, es}
Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
if (len(new_idx) != N) new_idx.assign(N, -1);
if (len(used_e) != M) used_e.assign(M, 0);
int n = len(V);
FOR(i, n) new_idx[V[i]] = i;
Graph<T, directed> G(n);
vc<int> history;
FOR(i, n) {
for (auto&& e: (*this)[V[i]]) {
if (used_e[e.id]) continue;
int a = e.frm, b = e.to;
if (new_idx[a] != -1 && new_idx[b] != -1) {
history.eb(e.id);
used_e[e.id] = 1;
int eid = (keep_eid ? e.id : -1);
G.add(new_idx[a], new_idx[b], e.cost, eid);
}
}
}
FOR(i, n) new_idx[V[i]] = -1;
for (auto&& eid: history) used_e[eid] = 0;
G.build();
return G;
}
private:
void calc_deg() {
assert(vc_deg.empty());
vc_deg.resize(N);
for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
}
void calc_deg_inout() {
assert(vc_indeg.empty());
vc_indeg.resize(N);
vc_outdeg.resize(N);
for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
}
};
#line 4 "library/graph/tree.hpp"
// HLD euler tour をとっていろいろ。
template <typename GT>
struct Tree {
using Graph_type = GT;
GT &G;
using WT = typename GT::cost_type;
int N;
vector<int> LID, RID, head, V, parent, VtoE;
vc<int> depth;
vc<WT> depth_weighted;
Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }
void build(int r = 0, bool hld = 1) {
if (r == -1) return; // build を遅延したいとき
N = G.N;
LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
depth.assign(N, -1), depth_weighted.assign(N, 0);
assert(G.is_prepared());
int t1 = 0;
dfs_sz(r, -1, hld);
dfs_hld(r, t1);
}
void dfs_sz(int v, int p, bool hld) {
auto &sz = RID;
parent[v] = p;
depth[v] = (p == -1 ? 0 : depth[p] + 1);
sz[v] = 1;
int l = G.indptr[v], r = G.indptr[v + 1];
auto &csr = G.csr_edges;
// 使う辺があれば先頭にする
for (int i = r - 2; i >= l; --i) {
if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
}
int hld_sz = 0;
for (int i = l; i < r; ++i) {
auto e = csr[i];
if (depth[e.to] != -1) continue;
depth_weighted[e.to] = depth_weighted[v] + e.cost;
VtoE[e.to] = e.id;
dfs_sz(e.to, v, hld);
sz[v] += sz[e.to];
if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
}
}
void dfs_hld(int v, int ×) {
LID[v] = times++;
RID[v] += LID[v];
V[LID[v]] = v;
bool heavy = true;
for (auto &&e: G[v]) {
if (depth[e.to] <= depth[v]) continue;
head[e.to] = (heavy ? head[v] : e.to);
heavy = false;
dfs_hld(e.to, times);
}
}
vc<int> heavy_path_at(int v) {
vc<int> P = {v};
while (1) {
int a = P.back();
for (auto &&e: G[a]) {
if (e.to != parent[a] && head[e.to] == v) {
P.eb(e.to);
break;
}
}
if (P.back() == a) break;
}
return P;
}
int heavy_child(int v) {
int k = LID[v] + 1;
if (k == N) return -1;
int w = V[k];
return (parent[w] == v ? w : -1);
}
int e_to_v(int eid) {
auto e = G.edges[eid];
return (parent[e.frm] == e.to ? e.frm : e.to);
}
int v_to_e(int v) { return VtoE[v]; }
int ELID(int v) { return 2 * LID[v] - depth[v]; }
int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }
// 目標地点へ進む個数が k
int LA(int v, int k) {
assert(k <= depth[v]);
while (1) {
int u = head[v];
if (LID[v] - k >= LID[u]) return V[LID[v] - k];
k -= LID[v] - LID[u] + 1;
v = parent[u];
}
}
int la(int u, int v) { return LA(u, v); }
int LCA(int u, int v) {
for (;; v = parent[head[v]]) {
if (LID[u] > LID[v]) swap(u, v);
if (head[u] == head[v]) return u;
}
}
// root を根とした場合の lca
int LCA_root(int u, int v, int root) {
return LCA(u, v) ^ LCA(u, root) ^ LCA(v, root);
}
int lca(int u, int v) { return LCA(u, v); }
int lca_root(int u, int v, int root) { return LCA_root(u, v, root); }
int subtree_size(int v, int root = -1) {
if (root == -1) return RID[v] - LID[v];
if (v == root) return N;
int x = jump(v, root, 1);
if (in_subtree(v, x)) return RID[v] - LID[v];
return N - RID[x] + LID[x];
}
int dist(int a, int b) {
int c = LCA(a, b);
return depth[a] + depth[b] - 2 * depth[c];
}
WT dist_weighted(int a, int b) {
int c = LCA(a, b);
return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
}
// a is in b
bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }
int jump(int a, int b, ll k) {
if (k == 1) {
if (a == b) return -1;
return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
}
int c = LCA(a, b);
int d_ac = depth[a] - depth[c];
int d_bc = depth[b] - depth[c];
if (k > d_ac + d_bc) return -1;
if (k <= d_ac) return LA(a, k);
return LA(b, d_ac + d_bc - k);
}
vc<int> collect_child(int v) {
vc<int> res;
for (auto &&e: G[v])
if (e.to != parent[v]) res.eb(e.to);
return res;
}
vc<int> collect_light(int v) {
vc<int> res;
bool skip = true;
for (auto &&e: G[v])
if (e.to != parent[v]) {
if (!skip) res.eb(e.to);
skip = false;
}
return res;
}
vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
// [始点, 終点] の"閉"区間列。
vc<pair<int, int>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
down.eb(LID[head[v]], LID[v]);
v = parent[head[v]];
} else {
up.eb(LID[u], LID[head[u]]);
u = parent[head[u]];
}
}
if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
reverse(all(down));
up.insert(up.end(), all(down));
return up;
}
vc<int> restore_path(int u, int v) {
vc<int> P;
for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
if (a <= b) {
FOR(i, a, b + 1) P.eb(V[i]);
} else {
FOR_R(i, b, a + 1) P.eb(V[i]);
}
}
return P;
}
};
#line 4 "main.cpp"
void solve() {
LL(N, Q);
Graph<int, 0> G(N);
G.read_tree();
Tree<decltype(G)> tree(G);
auto dfs = [&](auto& dfs, vc<int>& A, int v, int L, int R, bool is_prefix,
bool is_suffix) -> bool {
assert(0 <= L && L < R && R <= len(A));
if (is_prefix && A[L] != v) return 0;
int lca = tree.lca(A[L], A[R - 1]);
if (is_prefix && lca != v) { return 0; }
if (!tree.in_subtree(lca, v)) return 0;
v = lca;
if (A[L] == v) is_prefix = 1;
if (R == L + 1) {
int w = A[L];
if (!tree.in_subtree(w, v)) return 0;
if (is_prefix && w != v) return 0;
if (is_suffix && tree.subtree_size(w) > 1) return 0;
return 1;
}
// 同じ部分木方向の区間を列挙する
vc<tuple<int, int, int>> dat;
int L1 = (is_prefix ? L + 1 : L);
while (L1 < R) {
if (A[L1] == v) return 0;
int d = tree.jump(v, A[L1], 1);
if (!tree.in_subtree(d, v)) return 0;
int R1 = binary_search(
[&](int k) -> bool { return tree.in_subtree(A[k], d); }, L1, R);
++R1;
dat.eb(L1, R1, d);
L1 = R1;
}
// 方向は distinct であることが必要
set<int> S;
for (auto& [l, r, d]: dat) {
if (S.count(d)) return 0;
S.insert(d);
}
int n = len(dat);
FOR(k, n) {
auto [l, r, d] = dat[k];
bool is_p = (k > 0 ? true : is_prefix);
bool is_s = (k < n - 1 ? true : is_suffix);
bool ok = dfs(dfs, A, d, l, r, is_p, is_s);
if (!ok) return 0;
}
// prefix かつ suffix の場合:すべての部分木方向に進んだか?
if (is_prefix && is_suffix) {
int n = tree.subtree_size(v);
if (R - L != n) return 0;
}
return 1;
};
FOR(Q) {
LL(n);
VEC(int, A, n);
for (auto& x: A) --x;
Yes(dfs(dfs, A, 0, 0, n, 0, 0));
}
}
signed main() {
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
input:
6 7 1 2 1 3 2 4 3 5 2 6 2 4 1 2 4 2 2 4 3 2 4 4 2 4 5 2 4 6 6 1 2 6 4 3 5
output:
No No Yes No No Yes Yes
result:
ok 7 tokens
Test #2:
score: 0
Accepted
time: 17ms
memory: 4268kb
input:
10 100000 7 2 1 7 7 10 8 6 8 7 1 3 4 5 9 5 5 8 8 8 9 7 2 8 1 6 1 4 8 3 5 2 6 7 10 3 9 9 1 1 1 8 10 3 2 9 3 8 7 3 7 5 6 2 8 5 9 1 6 3 4 6 2 1 3 5 8 9 2 4 9 1 3 2 1 5 5 8 5 1 7 9 10 5 2 9 2 6 4 10 6 3 8 3 4 5 8 2 8 4 9 4 10 1 2 4 3 3 6 3 1 3 6 1 1 6 8 3 1 3 7 3 2 3 9 1 5 4 3 7 8 10 9 4 2 3 10 2 5 4 3 ...
output:
No No No Yes No No No No Yes No No No No No No Yes No No No No No No No No No No No No No No No Yes No No No No No No Yes No No No No No Yes Yes No No No No No No No No No No No No No No No No No No No No No No No No Yes No No Yes Yes No No No No Yes No No No No No No No No No No No No No No No No N...
result:
ok 100000 tokens
Test #3:
score: 0
Accepted
time: 30ms
memory: 3872kb
input:
20 95326 19 7 11 14 15 14 6 12 14 13 2 9 1 15 4 7 16 14 13 10 13 17 13 20 10 5 16 18 7 6 9 11 3 2 12 16 2 8 17 11 3 20 16 6 1 6 11 3 14 6 6 17 4 20 10 2 14 19 8 6 12 8 8 12 20 1 5 3 18 12 13 13 16 3 8 12 13 6 19 18 5 8 14 19 15 3 8 11 16 9 18 19 2 19 2 17 16 7 10 3 18 11 13 1 12 19 10 5 20 4 6 17 18...
output:
No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No Yes No No No No No No No No No No No No No Yes Yes No No No No No Yes Yes No No No No No No No No No...
result:
ok 95326 tokens
Test #4:
score: 0
Accepted
time: 20ms
memory: 4240kb
input:
30 64393 17 20 17 6 29 13 26 9 11 13 17 5 12 27 5 1 25 28 3 20 28 13 19 29 22 14 21 13 18 10 3 4 30 27 15 21 21 23 8 10 21 24 27 14 9 7 28 16 7 3 2 7 7 27 3 18 29 27 15 14 2 24 21 24 24 22 6 5 12 12 4 20 26 28 22 22 14 7 30 19 13 16 29 9 18 14 14 14 4 8 14 25 11 6 25 22 11 28 10 10 7 1 22 7 6 14 12 ...
output:
No No No No No Yes No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
ok 64393 tokens
Test #5:
score: 0
Accepted
time: 20ms
memory: 4012kb
input:
40 48628 34 2 10 30 26 16 3 9 29 13 12 25 38 34 22 7 16 5 22 13 8 27 23 30 39 6 24 15 20 13 4 17 15 14 2 19 25 32 5 10 17 1 18 11 9 28 31 36 31 20 11 8 40 16 5 24 1 20 30 39 37 31 10 20 14 34 12 8 16 12 17 21 33 30 24 35 10 3 38 14 31 3 33 14 21 38 3 16 32 4 6 32 1 36 6 7 20 40 16 8 28 39 9 36 13 33...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No Yes No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 48628 tokens
Test #6:
score: 0
Accepted
time: 15ms
memory: 4028kb
input:
50 39193 24 17 12 8 47 31 12 2 23 37 29 41 38 20 19 23 27 40 42 48 1 26 24 41 39 35 32 24 6 4 41 11 9 13 13 26 37 8 41 50 24 5 27 4 34 14 7 42 16 4 45 41 21 28 49 13 26 46 10 3 18 23 24 39 48 8 33 8 14 13 25 42 36 21 4 22 43 38 44 9 4 47 38 29 37 45 11 10 48 21 38 26 47 13 27 15 30 36 36 26 13 6 34 ...
output:
No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
ok 39193 tokens
Test #7:
score: 0
Accepted
time: 17ms
memory: 4200kb
input:
10 100000 7 2 1 7 7 10 8 6 8 7 1 3 4 5 9 5 5 8 8 9 1 5 2 10 7 6 4 4 7 3 4 2 6 1 6 8 3 4 2 1 4 8 2 7 6 4 5 3 1 9 7 5 2 4 1 6 9 8 6 1 8 6 2 3 10 5 2 7 3 8 9 1 7 2 3 8 5 1 6 5 7 8 10 1 7 2 10 5 9 8 3 4 6 3 6 4 5 2 9 1 9 3 6 4 10 5 2 7 8 1 1 7 6 1 7 5 2 10 6 3 6 7 8 3 3 2 5 4 5 1 8 4 9 4 10 8 9 1 2 7 3 ...
output:
No No No Yes No No No No Yes No No No No No No Yes No No No No No No No No No No No No No No No No No No No No Yes No Yes No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes Yes No No No No Yes No No No No No No No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #8:
score: 0
Accepted
time: 20ms
memory: 4200kb
input:
10 100000 8 2 10 4 8 1 2 7 5 7 9 10 10 1 1 6 3 4 6 9 7 8 3 1 5 8 1 9 2 3 10 5 4 7 3 5 8 1 9 7 1 4 10 9 6 2 5 8 2 10 4 6 7 2 1 10 9 4 3 8 9 4 5 3 9 5 6 4 6 2 5 9 8 7 1 8 6 7 1 2 9 4 10 5 8 3 5 8 9 4 2 10 1 8 10 1 7 2 8 9 6 4 4 6 9 4 2 5 10 3 9 8 2 8 9 10 8 6 7 5 2 4 8 5 8 7 6 3 4 9 1 1 3 1 4 5 8 6 3 ...
output:
No No No No Yes No No No No No No No No No No No Yes Yes No No No No No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No No No No No No Yes No No No No No No No No Yes No No No No No Yes No No No No No No No No No No No No Yes No No No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #9:
score: 0
Accepted
time: 16ms
memory: 3864kb
input:
10 100000 6 8 1 5 4 2 7 5 3 4 10 1 9 7 3 7 6 5 6 10 8 1 7 3 5 9 4 6 5 1 7 8 2 9 3 3 8 4 9 1 4 3 7 10 4 6 1 8 9 3 6 2 6 6 7 3 4 1 5 3 9 5 7 6 4 7 2 9 3 10 6 2 9 3 4 1 10 8 9 4 1 7 2 6 5 10 8 10 7 8 2 3 9 6 1 4 10 1 2 7 6 1 7 9 5 2 4 3 3 7 1 7 5 10 1 8 6 2 9 3 6 9 1 6 10 5 7 9 6 1 3 6 1 7 9 6 10 4 7 9...
output:
No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No Yes No Yes Yes No No No No No No No No No No No No No No Yes No No No No Yes No No No No No No No No No No No No Yes No No No No No No Yes No No No Yes No No Yes No No Yes No No Yes No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #10:
score: 0
Accepted
time: 11ms
memory: 4036kb
input:
10 100000 5 9 7 2 3 4 5 2 6 3 5 3 8 5 10 9 9 1 5 3 6 10 4 9 3 8 1 10 6 8 9 6 4 5 1 8 2 9 7 5 6 4 10 8 1 10 9 9 2 7 10 4 5 8 1 6 2 10 6 1 7 1 6 9 1 6 10 7 3 4 5 2 9 8 6 4 5 7 3 1 9 2 1 7 4 1 4 8 7 5 2 8 3 5 9 6 8 4 1 5 7 10 4 4 3 2 7 8 4 2 9 5 10 3 8 6 4 1 5 4 7 5 8 5 9 2 1 2 9 2 10 4 9 7 3 6 5 2 8 1...
output:
No No No No Yes No No Yes Yes No No Yes No No No No No No No No No No No Yes No No No No No No No No No No No No Yes Yes No No No Yes No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No Yes No Yes No No No No No No No No No No No No No No Yes No No No ...
result:
ok 100000 tokens
Test #11:
score: 0
Accepted
time: 15ms
memory: 3920kb
input:
10 100000 4 6 10 8 7 2 4 7 6 5 1 7 3 2 5 10 9 1 9 6 7 5 10 9 4 8 1 3 3 2 7 6 6 7 4 3 5 1 6 4 9 8 6 3 10 9 10 6 8 2 1 5 3 7 4 8 3 2 5 7 8 4 1 10 5 2 6 3 10 5 3 3 1 2 10 10 3 4 8 9 6 2 7 5 1 1 10 9 2 9 6 7 8 1 3 4 5 9 1 7 6 5 2 9 4 8 3 6 2 10 9 4 6 3 7 7 4 5 3 10 8 9 1 4 1 6 4 5 4 7 2 4 2 1 9 7 3 7 3 ...
output:
No No No No No No No No No Yes No No No No Yes Yes No No No No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No...
result:
ok 100000 tokens
Test #12:
score: 0
Accepted
time: 30ms
memory: 3984kb
input:
20 95326 19 7 11 14 15 14 6 12 14 13 2 9 1 15 4 7 16 14 13 10 13 17 13 20 10 5 16 18 7 6 9 11 3 2 12 16 2 8 17 13 10 14 12 2 19 9 8 17 15 3 6 16 18 11 7 20 14 2 19 14 20 13 3 6 5 1 12 17 11 7 16 13 6 11 2 19 15 5 13 12 16 4 17 1 7 3 15 10 6 9 14 7 17 8 19 13 2 12 1 3 10 13 9 1 19 19 11 16 1 4 3 20 1...
output:
No No No No No No Yes No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No Yes No No No No No No No No No No No No No Yes Yes No No No No No Yes Yes No No No No No No No No N...
result:
ok 95326 tokens
Test #13:
score: 0
Accepted
time: 16ms
memory: 4040kb
input:
30 64393 17 20 17 6 29 13 26 9 11 13 17 5 12 27 5 1 25 28 3 20 28 13 19 29 22 14 21 13 18 10 3 4 30 27 15 21 21 23 8 10 21 24 27 14 9 7 28 16 7 3 2 7 7 27 3 18 29 27 15 5 15 26 12 3 4 13 27 7 9 16 14 22 25 11 22 25 24 15 17 14 23 16 26 7 1 13 29 27 20 28 10 2 19 21 4 11 22 28 3 16 20 9 29 21 2 19 17...
output:
No No No No No Yes No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
ok 64393 tokens
Test #14:
score: 0
Accepted
time: 20ms
memory: 4208kb
input:
40 48628 34 2 10 30 26 16 3 9 29 13 12 25 38 34 22 7 16 5 22 13 8 27 23 30 39 6 24 15 20 13 4 17 15 14 2 19 25 32 5 10 17 1 18 11 9 28 31 36 31 20 11 8 40 16 5 24 1 20 30 39 37 31 10 20 14 34 12 8 16 12 17 21 33 30 24 35 10 3 38 32 5 30 12 1 25 35 26 37 19 13 40 14 6 17 29 3 8 2 18 38 24 36 31 34 22...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No Yes No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 48628 tokens
Test #15:
score: 0
Accepted
time: 18ms
memory: 4040kb
input:
50 39193 24 17 12 8 47 31 12 2 23 37 29 41 38 20 19 23 27 40 42 48 1 26 24 41 39 35 32 24 6 4 41 11 9 13 13 26 37 8 41 50 24 5 27 4 34 14 7 42 16 4 45 41 21 28 49 13 26 46 10 3 18 23 24 39 48 8 33 8 14 13 25 42 36 21 4 22 43 38 44 9 4 47 38 29 37 45 11 10 48 21 38 26 47 13 27 15 30 36 36 44 47 14 48...
output:
No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
ok 39193 tokens
Test #16:
score: 0
Accepted
time: 11ms
memory: 4240kb
input:
10 100000 4 1 3 6 7 4 2 6 5 7 8 6 4 9 4 6 10 7 4 8 2 1 9 3 2 4 7 3 3 2 8 3 10 1 2 1 3 5 2 8 4 1 9 3 5 1 9 7 4 9 1 7 5 10 8 1 2 3 4 9 6 9 9 4 6 3 2 8 7 5 10 4 6 4 1 7 3 6 8 2 1 1 2 6 3 4 9 7 10 5 6 9 6 3 2 8 7 5 7 10 5 9 6 2 5 4 1 4 2 9 1 2 2 3 1 3 5 9 1 6 2 8 5 6 4 7 5 10 3 9 1 6 7 7 5 10 6 8 3 2 2 ...
output:
No No Yes No Yes No No No Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes No Yes Yes No No No Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No No Yes Yes No Yes Yes Yes No No No Yes No Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes No No Yes Yes No Yes No Yes Yes No Yes Yes Yes Yes No No Yes Yes Yes Yes...
result:
ok 100000 tokens
Test #17:
score: 0
Accepted
time: 14ms
memory: 3984kb
input:
10 100000 10 6 1 9 5 6 3 7 3 9 1 8 4 6 3 2 6 9 2 3 7 2 5 6 2 1 8 2 10 4 4 9 6 5 4 6 5 10 9 1 8 3 1 5 6 4 9 1 8 3 2 1 5 3 3 2 7 4 7 2 1 8 1 7 3 5 4 9 1 2 1 9 3 4 10 5 5 5 10 4 3 2 1 3 1 5 3 10 5 4 4 5 10 1 8 5 4 9 1 8 3 7 8 1 9 6 5 4 10 6 6 9 3 7 2 1 6 6 4 5 10 3 2 8 3 9 1 8 6 4 5 10 4 6 5 10 9 1 4 6...
output:
Yes No Yes Yes Yes No Yes No Yes Yes No Yes No Yes Yes Yes Yes Yes Yes Yes No No No No Yes No No Yes No Yes Yes Yes Yes No No Yes Yes No No Yes No No Yes Yes Yes Yes Yes Yes No Yes Yes No No Yes Yes No Yes Yes No No Yes No Yes Yes Yes Yes Yes No Yes Yes No No No Yes Yes Yes No No Yes Yes No No Yes Y...
result:
ok 100000 tokens
Test #18:
score: 0
Accepted
time: 15ms
memory: 4032kb
input:
10 100000 10 6 9 4 6 3 1 6 2 7 8 6 7 5 9 6 7 6 1 10 3 8 10 2 1 9 3 1 3 7 4 10 9 4 3 6 6 8 3 9 4 7 2 9 4 2 1 9 1 4 1 6 10 7 5 2 6 9 4 8 10 3 1 2 3 10 3 1 9 4 3 8 9 4 1 4 1 7 1 3 3 9 6 7 2 8 7 1 3 7 7 6 10 1 9 4 3 9 9 4 6 10 7 2 5 3 8 4 4 6 10 7 1 5 4 4 10 8 3 2 2 7 1 7 1 3 4 1 8 3 10 7 6 10 3 7 5 2 1...
output:
Yes No Yes No Yes Yes Yes No Yes Yes No Yes No Yes Yes Yes Yes No Yes Yes No No No Yes Yes No Yes Yes No No Yes No No Yes No No Yes Yes No No Yes Yes Yes Yes No No Yes Yes Yes Yes No No No Yes No No Yes Yes No Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes Yes Yes No Yes Yes No Yes No Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #19:
score: 0
Accepted
time: 18ms
memory: 4036kb
input:
10 100000 3 1 4 3 6 1 3 10 7 9 7 1 2 7 2 8 5 1 3 8 5 6 4 5 1 6 3 1 2 1 2 1 10 5 7 9 1 5 3 3 8 9 1 2 8 6 2 9 6 2 10 6 4 1 6 5 3 1 9 2 10 4 8 4 1 5 6 7 9 2 8 3 7 2 8 3 8 2 7 5 6 7 2 8 9 3 8 1 5 1 8 5 7 9 2 8 4 3 7 2 8 5 3 10 4 6 9 2 10 4 1 4 3 2 8 9 6 6 1 7 2 8 9 4 2 8 1 6 2 2 7 4 9 1 6 5 4 9 2 8 1 9 ...
output:
Yes No Yes Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes No Yes No Yes No Yes No Yes Yes Yes No No No No No No No Yes No No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No No No Yes Yes Yes No Yes No No Yes Yes Yes Yes No No No Yes Yes Yes Yes Yes No Yes Yes Y...
result:
ok 100000 tokens
Test #20:
score: 0
Accepted
time: 15ms
memory: 3980kb
input:
10 100000 7 5 3 2 7 6 7 4 8 7 7 2 7 1 10 8 7 9 5 7 8 10 6 1 2 7 5 8 8 7 4 9 1 2 3 5 3 6 8 10 1 4 7 1 2 3 6 8 10 9 3 1 7 9 1 5 4 10 9 6 1 2 9 8 2 2 3 4 5 1 2 3 2 1 4 4 1 7 5 9 6 8 10 9 2 3 6 2 4 5 6 5 2 3 1 4 9 3 5 9 4 1 1 1 6 10 4 7 8 10 2 3 9 6 1 5 2 5 4 4 1 4 2 3 1 2 4 6 4 9 8 2 4 1 3 6 8 10 4 10 ...
output:
No Yes No Yes Yes No Yes Yes No Yes Yes No No Yes Yes Yes No Yes Yes Yes No Yes No Yes Yes No Yes No No Yes Yes Yes Yes No Yes Yes No Yes No Yes Yes No No Yes Yes Yes Yes No No Yes Yes No Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes Yes Yes Yes No Yes Yes Yes No No No Yes No No Yes Yes Yes No Ye...
result:
ok 100000 tokens
Test #21:
score: 0
Accepted
time: 27ms
memory: 3980kb
input:
20 100000 2 12 3 20 1 8 8 11 9 1 5 4 16 11 5 10 3 13 11 10 6 15 6 20 18 20 12 7 15 19 5 20 17 20 14 17 12 20 7 12 2 7 3 13 5 10 8 5 10 11 8 1 9 16 4 1 18 1 7 2 8 11 8 10 5 20 6 15 19 17 14 3 1 9 16 2 1 9 2 3 13 5 3 13 12 2 7 7 14 3 13 12 2 7 18 5 13 12 7 2 19 9 1 9 16 4 3 13 6 15 19 10 3 13 18 17 14...
output:
No No Yes Yes Yes Yes No Yes Yes Yes Yes No No No Yes No Yes No No No Yes No Yes Yes Yes Yes Yes No Yes Yes Yes No No Yes No Yes No Yes No No Yes No No Yes Yes Yes Yes Yes Yes Yes No No Yes Yes No No Yes No Yes Yes No No No No Yes Yes No No Yes No Yes No No Yes Yes Yes No Yes No No Yes Yes No No Yes...
result:
ok 100000 tokens
Test #22:
score: 0
Accepted
time: 42ms
memory: 4080kb
input:
30 100000 6 16 17 23 11 10 16 23 4 23 27 10 25 8 6 26 2 14 13 19 28 30 24 3 13 14 20 7 14 29 1 6 21 5 3 2 12 1 10 28 22 23 1 13 11 20 15 10 11 21 9 22 10 8 6 11 20 18 7 6 16 23 17 4 22 9 18 23 17 4 22 9 26 11 10 27 8 25 28 30 15 20 7 18 21 7 19 14 29 2 3 24 12 10 6 11 20 7 18 21 5 10 15 27 10 26 16 ...
output:
Yes Yes Yes Yes No Yes No Yes No No Yes No Yes No Yes Yes No Yes Yes No Yes No Yes Yes No No Yes Yes No Yes Yes Yes Yes No No Yes Yes No No Yes No Yes No No Yes No No Yes Yes Yes Yes No No Yes No No Yes Yes Yes Yes No Yes Yes No Yes Yes No No No No No Yes Yes No Yes Yes Yes No Yes No No No Yes No No...
result:
ok 100000 tokens
Test #23:
score: 0
Accepted
time: 45ms
memory: 3984kb
input:
40 92713 3 1 26 13 26 21 14 4 23 14 33 3 7 28 36 19 39 34 23 38 8 39 39 36 19 23 20 14 32 36 26 14 9 2 25 27 40 16 13 30 14 28 17 6 17 34 26 10 14 9 22 31 19 25 20 24 37 11 39 29 2 16 31 37 32 35 3 24 12 17 15 9 10 18 36 11 6 5 10 25 27 36 11 37 31 22 32 35 39 3 31 22 39 18 24 3 33 1 26 10 18 13 30 ...
output:
Yes Yes No No Yes Yes No Yes Yes Yes Yes No Yes No Yes No Yes No Yes Yes Yes No Yes Yes No No No Yes Yes Yes No Yes No Yes No No Yes No No No Yes Yes Yes No Yes Yes Yes Yes No Yes Yes Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No No Yes Yes No No No No No No Yes No No Yes Yes No Y...
result:
ok 92713 tokens
Test #24:
score: 0
Accepted
time: 45ms
memory: 4084kb
input:
50 75394 30 25 34 23 50 31 47 6 27 7 17 28 37 30 14 24 44 36 34 49 5 2 31 19 8 36 30 38 29 43 6 34 31 45 7 24 38 12 2 43 33 38 1 8 46 11 33 18 3 31 8 30 40 31 44 21 15 30 25 29 4 10 33 16 30 34 31 28 38 41 13 19 38 31 48 31 36 42 36 10 45 20 7 22 21 32 22 44 11 29 39 25 9 43 26 25 33 35 36 9 11 46 1...
output:
No Yes Yes Yes No No No Yes No Yes No No No No No Yes Yes Yes Yes Yes Yes Yes Yes No No No No Yes Yes Yes No No Yes Yes Yes No Yes No No Yes Yes Yes No No No Yes No No No No No Yes Yes No No No Yes Yes Yes No No Yes No No No No Yes Yes No Yes No Yes No Yes No Yes No Yes No No No Yes No Yes No Yes No...
result:
ok 75394 tokens
Test #25:
score: 0
Accepted
time: 37ms
memory: 12996kb
input:
100000 100000 22031 19709 79977 20677 72195 10689 88600 65820 9422 9595 3821 93983 96434 92645 72154 63751 88298 50712 58441 10216 66429 11541 80376 50932 50750 3251 39637 9534 35886 1323 34267 26052 61878 74481 49528 38924 69738 16187 99731 43694 18246 31836 68871 3281 17124 1158 95557 48000 65959 ...
output:
No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
ok 100000 tokens
Test #26:
score: 0
Accepted
time: 45ms
memory: 11776kb
input:
100000 100000 6390 17242 19936 20882 46229 37775 87701 45891 93858 43746 24030 30025 21273 3891 8969 19204 31507 99402 31610 22619 57908 71859 86596 48565 69684 42945 81569 46463 11482 1436 69395 25798 83954 12570 38345 22133 99955 65046 47955 34204 37747 85317 19733 67085 12058 1916 8229 88515 3055...
output:
No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
ok 100000 tokens
Test #27:
score: 0
Accepted
time: 42ms
memory: 11752kb
input:
100000 100000 65796 41231 47215 20437 14648 92497 7368 16204 1057 12939 57423 58031 90889 26728 19075 73300 16433 75923 44452 80414 69850 59598 99777 15742 35503 49371 20702 80793 88570 51926 92517 94171 37244 20383 29247 19506 81624 62559 2926 63517 96697 65725 29639 38173 74903 34618 313 16309 299...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #28:
score: 0
Accepted
time: 43ms
memory: 11676kb
input:
100000 100000 49565 66073 21944 4457 28322 40724 77401 81004 433 54017 3920 51304 21061 36288 14752 22530 92090 5883 9978 78398 92537 35543 88335 45607 83800 53358 77729 40863 1541 42486 96162 58764 41980 21524 83274 15162 84917 67941 74664 63431 54624 33582 35792 18967 29901 70394 38286 61456 86428...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #29:
score: 0
Accepted
time: 41ms
memory: 11956kb
input:
100000 100000 1766 4748 32844 9107 73356 52002 29127 35776 77551 96310 6586 12633 931 30529 97055 93805 71514 17120 15322 89816 48447 85139 69178 18689 88038 53343 18983 2203 31527 99630 92008 23951 82997 93138 74484 96972 36465 83542 10207 38726 70768 90541 6516 33979 57143 27898 2602 94702 72636 2...
output:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 100000 tokens
Test #30:
score: 0
Accepted
time: 110ms
memory: 13404kb
input:
100000 100000 38656 38649 49244 49240 72097 72092 16362 16367 89712 89708 31833 31828 1776 1769 28913 28906 61888 61878 7131 7124 28437 28442 20338 20329 68540 68539 31334 31328 83244 83234 6344 6343 53941 53948 78386 78388 40417 40413 97136 97140 17048 17039 74885 74879 37932 37939 72242 72240 9052...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #31:
score: 0
Accepted
time: 125ms
memory: 12084kb
input:
100000 100000 91113 91209 82125 82196 17061 17030 63492 63450 86825 86766 20090 20048 98842 98857 83335 83270 8996 9015 65800 65720 49122 49155 84038 84135 45583 45609 71664 71592 80151 80184 55978 56066 84122 84142 47884 47984 6616 6659 24124 24141 44203 44230 88031 87936 21094 21143 52361 52425 93...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #32:
score: 0
Accepted
time: 134ms
memory: 11704kb
input:
100000 100000 50728 50654 44261 45163 22208 22565 58688 58373 32612 33030 71660 71873 89913 89664 75805 76744 71503 71934 27322 28111 55812 55356 33720 32754 48440 48264 41048 41781 93214 94182 17629 17722 17561 18146 28329 27383 98169 98356 1216 1055 84703 84515 2881 2084 87390 88222 21264 21663 43...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #33:
score: 0
Accepted
time: 137ms
memory: 11668kb
input:
100000 100000 31222 33552 41521 44119 50990 49903 44464 43003 15190 22921 47485 53253 74261 79380 85164 93724 59780 55724 93738 98324 63895 60609 21017 18180 433 773 93075 97786 8027 11031 12196 12724 97981 90548 96946 87968 93529 86667 20125 16341 63577 54107 90336 99374 52847 52441 35212 35612 691...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #34:
score: 0
Accepted
time: 148ms
memory: 11792kb
input:
100000 100000 12095 71885 9520 19536 6341 58535 9549 31319 17658 31062 26096 84345 55575 98102 41278 39200 54189 4024 9555 15722 84991 33220 57827 29323 17571 57697 89020 37327 13499 12471 15923 46106 46684 27028 68544 94977 72265 95916 25582 17437 84373 12019 40053 70207 30578 14849 99726 5741 8896...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #35:
score: 0
Accepted
time: 19ms
memory: 11748kb
input:
100000 100000 58286 1 92801 1 1 23835 31111 1 63517 1 1 64597 85533 1 22562 1 1 88412 75722 1 1 59697 92715 1 1 81332 74340 1 871 1 1 21972 1 54497 66797 1 10937 1 1 80448 29777 1 8287 1 1 65626 82496 1 88110 1 81770 1 79830 1 64455 1 1 5287 54867 1 19241 1 84920 1 40595 1 1 91660 86005 1 9536 1 1 4...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #36:
score: 0
Accepted
time: 27ms
memory: 11956kb
input:
100000 100000 1 31153 1 70648 65640 2 2 42097 1 30566 79120 79118 79694 79695 1 15175 58998 58996 46344 2 60522 1 69811 69809 2 10516 2 29288 84465 2 43108 2 46861 1 1 79362 85016 1 2 33704 2 65391 83512 83511 96951 1 62813 62814 1 80646 2 54179 88522 88521 29945 2 57863 2 2 22120 86745 1 8607 2 325...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #37:
score: 0
Accepted
time: 29ms
memory: 11824kb
input:
100000 100000 4 6165 61280 61285 79316 79317 75138 75139 3294 3 1 81489 10503 4 11462 4 95690 95693 6053 2 3 34295 66316 66320 9365 4 35707 5 2 4704 1 51638 13980 4 17619 5 14348 5 1 1157 38076 3 99377 99376 42362 3 58971 58969 2 48323 70177 3 5 10946 76634 76633 1 97298 5 44538 77954 1 16166 4 7346...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #38:
score: 0
Accepted
time: 38ms
memory: 11808kb
input:
100000 100000 69019 69027 10 20115 79300 79296 66171 66164 98706 98700 4 47454 57286 57289 78954 78960 92664 92658 5 24956 1 3044 55786 55795 73188 8 9 2296 67932 67937 8528 9 81852 81842 33011 10 51298 51293 67010 2 95125 95119 54265 4 1 35228 61407 61406 82568 82562 3 26672 5 16416 74458 74467 296...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #39:
score: 0
Accepted
time: 43ms
memory: 11740kb
input:
100000 100000 35 23329 87458 87437 35 99794 57784 57747 39576 3 76333 76305 49205 29 2218 21 65211 65244 36543 48 96822 96776 10507 12 77139 77096 17 337 11 19269 63630 63601 26 2484 23942 26 6 19197 89865 89888 87821 87823 15698 22 2617 8 38048 3 37076 28 17 2205 66500 66504 51236 51277 86214 86203...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #40:
score: 0
Accepted
time: 49ms
memory: 11672kb
input:
100000 100000 46 29253 32 11065 75112 75016 97872 97943 83462 83559 55450 55378 2 14708 89044 88960 98802 98709 88777 88765 83571 83601 37363 60 57778 57821 12825 71 42 13650 68 27305 9 25066 52407 52445 92990 92923 79698 79702 38704 66 75102 75030 64 3133 47898 1 3047 64 41 46208 51715 51738 93 669...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #41:
score: 0
Accepted
time: 27ms
memory: 18672kb
input:
100000 100000 64269 64268 66535 66536 9759 9758 42907 42908 80000 84213 80000 83489 27749 27748 86199 80000 80000 80659 11615 11614 93420 1 2529 2528 96161 1 79473 79474 83518 80000 43109 43110 37111 37112 46604 46603 1 93666 54540 54541 84237 80000 62717 62718 24720 24719 57226 57225 8333 8334 1572...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100000 tokens
Test #42:
score: 0
Accepted
time: 136ms
memory: 11856kb
input:
100000 37 29162 63623 96664 54044 11535 67257 10642 29054 10206 58115 95878 4300 94836 69937 78765 28295 22874 53200 43075 87524 13107 77611 7813 13031 51591 40743 7168 67498 25699 32495 7125 37661 28803 9718 18154 16537 86140 56605 89290 3771 36638 63730 57297 68534 25220 8566 98229 56905 48005 462...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 37 tokens
Test #43:
score: 0
Accepted
time: 133ms
memory: 11840kb
input:
100000 33 60074 18401 35678 11648 38252 92824 51971 94160 24926 70750 19026 46634 14302 30542 40772 16995 74011 54458 39554 11112 15458 2470 40516 48499 47136 92413 74957 81119 86949 69165 2914 22736 93669 29627 81851 64391 96131 18955 85414 48801 11987 81925 44883 43397 57347 15860 25315 42763 2252...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 33 tokens
Test #44:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
1 1 1 1
output:
Yes
result:
ok "Yes"
Extra Test:
score: 0
Extra Test Passed