QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110917 | #6559. A Tree and Two Edges | maspy | AC ✓ | 174ms | 10200kb | C++23 | 26.0kb | 2023-06-04 19:10:28 | 2023-06-04 19:10:30 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
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); }
// (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, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#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) {
assert(!que.empty());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
assert(!que.empty());
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;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, 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;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, 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"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T x) {
x.write();
}
template <class T>
void write(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __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 3 "main.cpp"
#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 {
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; }
constexpr bool is_directed() { return directed; }
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;
}
// 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();
}
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];
}
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);
}
}
vc<int> new_idx;
vc<bool> used_e;
// G における頂点 V[i] が、新しいグラフで i になるようにする
// {G, es}
pair<Graph<T, directed>, vc<int>> rearrange(vc<int> V) {
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> es;
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) {
used_e[e.id] = 1;
G.add(new_idx[a], new_idx[b], e.cost);
es.eb(e.id);
}
}
}
FOR(i, n) new_idx[V[i]] = -1;
for (auto&& eid: es) used_e[eid] = 0;
G.build();
return {G, es};
}
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 をとっていろいろ。
// 木以外、非連結でも dfs 順序や親がとれる。
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 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: 0-indexed */
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<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 2 "library/graph/compress_tree.hpp"
// (圧縮された木の頂点ラベルたち、グラフ)
template <typename TREE>
pair<vc<int>, typename TREE::Graph_type> compress_tree(TREE& tree, vc<int> V) {
// 大事な点をリストアップする
// もともとの根は含まれるようにする
sort(all(V), [&](auto& x, auto& y) { return tree.LID[x] < tree.LID[y]; });
int n = len(V);
FOR(i, n) {
int j = (i + 1 == n ? 0 : i + 1);
V.eb(tree.lca(V[i], V[j]));
}
V.eb(tree.V[0]);
sort(all(V), [&](auto& x, auto& y) { return tree.LID[x] < tree.LID[y]; });
V.erase(unique(all(V)), V.end());
// 辺を張ってグラフを作る
n = len(V);
using GT = typename TREE::Graph_type;
using WT = typename GT::cost_type;
GT G(n);
vc<int> st = {0};
FOR(i, 1, n) {
while (1) {
int p = V[st.back()];
int v = V[i];
if (tree.in_subtree(v, p)) break;
st.pop_back();
}
int p = V[st.back()];
int v = V[i];
WT d = tree.depth_weighted[v] - tree.depth_weighted[p];
G.add(st.back(), i, d);
st.eb(i);
}
G.build();
return {V, G};
}
#line 2 "library/ds/unionfind/unionfind.hpp"
struct UnionFind {
int n, n_comp;
vc<int> dat; // par or (-size)
UnionFind(int n = 0) { build(n); }
void build(int m) {
n = m, n_comp = m;
dat.assign(n, -1);
}
void reset() { build(n); }
int operator[](int x) {
while (dat[x] >= 0) {
int pp = dat[dat[x]];
if (pp < 0) { return dat[x]; }
x = dat[x] = pp;
}
return x;
}
ll size(int x) {
assert(dat[x] < 0);
return -dat[x];
}
bool merge(int x, int y) {
x = (*this)[x], y = (*this)[y];
if (x == y) return false;
if (-dat[x] < -dat[y]) swap(x, y);
dat[x] += dat[y], dat[y] = x, n_comp--;
return true;
}
};
#line 6 "main.cpp"
void solve() {
LL(N, Q);
Graph<int, 0> G(N);
vc<pi> edge;
UnionFind uf(N);
FOR(N + 1) {
INT(a, b);
--a, --b;
if (uf.merge(a, b))
G.add(a, b);
else
edge.eb(a, b);
}
G.build();
Tree<decltype(G)> tree(G);
vc<int> new_idx(N);
FOR(Q) {
INT(a, b);
--a, --b;
vc<int> V;
for (auto&& [x, y]: edge) V.eb(x), V.eb(y);
V.eb(a), V.eb(b);
auto [W, new_tree] = compress_tree<decltype(tree)>(tree, V);
int n = len(W);
FOR(i, n) new_idx[W[i]] = i;
Graph<int, 0> H(n);
for (auto&& e: new_tree.edges) H.add(e.frm, e.to);
for (auto&& [x, y]: edge) H.add(new_idx[x], new_idx[y]);
H.build();
a = new_idx[a], b = new_idx[b];
// H.debug();
int ANS = 0;
vc<int> used_v(H.N);
vc<int> used_e(H.M);
auto dfs = [&](auto& dfs, int v) -> void {
if (v == b) {
++ANS;
return;
}
for (auto&& e: H[v]) {
if (used_e[e.id] || used_v[e.to]) continue;
used_e[e.id] = used_v[e.to] = 1;
dfs(dfs, e.to);
used_e[e.id] = used_v[e.to] = 0;
}
};
used_v[a] = 1;
dfs(dfs, a);
print(ANS);
}
}
signed main() {
int T = 1;
// INT(T);
FOR(T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3556kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 1 2 1 3 1 4 2 3 2 4 3 4
output:
3 3 3 3 3 4
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
6 4 1 2 1 3 1 6 2 3 3 4 3 5 4 5 1 2 1 3 1 4 1 6
output:
2 2 4 1
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 93ms
memory: 7724kb
input:
50000 50000 11561 23122 14261 28523 24407 48814 17947 35894 14803 29607 19557 39115 12415 24830 9583 19167 18397 36794 439 878 18040 36080 17150 34300 7922 15845 18938 37877 18625 37250 6459 12919 9818 19636 3579 7158 21323 42646 23882 47764 13603 27207 8353 16707 15907 31814 20935 41871 11686 23372...
output:
4 3 3 4 4 3 1 3 4 1 3 4 3 4 3 3 1 3 3 3 4 4 4 3 3 3 4 3 3 3 1 3 3 3 3 4 4 4 4 3 4 3 3 3 4 3 4 4 4 4 3 4 4 4 4 3 3 3 4 4 4 4 4 4 3 4 3 4 1 4 1 1 4 3 3 4 3 3 1 4 3 3 4 4 3 3 4 4 4 3 4 3 4 4 4 4 4 3 4 3 3 3 1 3 4 4 3 4 3 4 3 3 4 1 4 3 3 3 4 4 4 4 3 3 3 3 3 4 4 4 4 3 3 4 3 4 4 3 3 4 4 4 1 3 3 3 3 4 4 3 ...
result:
ok 50000 lines
Test #4:
score: 0
Accepted
time: 125ms
memory: 7832kb
input:
50000 50000 1730 3460 17535 35071 14108 28216 20630 41260 2091 4182 8112 16225 21373 42746 6685 13371 21142 42284 12168 24337 22564 45128 16103 32207 9254 18508 21369 42739 1955 3911 13696 27392 3929 7858 1777 3555 23382 46764 830 1660 17722 35444 11495 22991 10184 20369 13697 27395 24728 49456 4037...
output:
1 1 3 3 3 4 4 4 4 4 3 3 3 4 1 3 4 3 3 1 3 3 4 3 1 4 3 3 4 3 3 4 4 4 1 1 4 1 3 4 3 1 4 4 3 3 3 4 1 4 4 1 3 1 3 3 3 1 1 3 3 3 3 3 4 3 4 4 3 3 4 4 4 3 3 4 4 4 3 4 3 3 3 3 3 3 3 3 4 4 1 4 3 4 1 4 4 4 4 3 4 1 4 4 3 4 3 4 3 4 3 1 4 3 1 1 3 3 4 4 1 3 3 3 4 3 3 4 4 4 4 4 3 3 4 3 4 1 1 3 4 4 3 4 4 3 3 4 4 3 ...
result:
ok 50000 lines
Test #5:
score: 0
Accepted
time: 174ms
memory: 7808kb
input:
50000 50000 21879 43758 12510 25020 2593 5187 16048 32096 9697 19394 12606 25212 3860 7720 8231 16462 23983 47966 10852 21705 6919 13839 1385 2770 4040 8080 14298 28596 22248 44496 4245 8490 14486 28972 11445 22891 21557 43114 20946 41892 23374 46749 78 157 4617 9234 8198 16396 12228 24456 16125 322...
output:
4 2 2 2 4 2 1 2 2 2 4 2 1 2 4 2 2 4 4 4 2 1 4 2 2 4 2 4 2 2 1 4 2 2 1 1 4 4 2 2 2 4 2 4 2 4 4 4 2 2 4 2 2 4 1 4 1 4 4 2 4 4 2 2 2 2 4 2 2 1 2 1 4 2 4 4 4 4 2 2 2 4 4 1 2 1 2 4 4 4 2 2 2 2 4 4 4 4 4 2 4 2 4 4 2 4 4 4 4 4 2 4 2 2 4 4 4 1 2 2 2 4 1 2 4 1 2 2 4 2 4 4 2 4 2 2 4 1 4 1 2 4 2 2 4 4 4 4 4 4 ...
result:
ok 50000 lines
Test #6:
score: 0
Accepted
time: 85ms
memory: 7780kb
input:
50000 50000 1451 2795 8910 29108 638 5810 24117 38535 2769 44109 7603 8789 14090 14819 5315 11076 22885 25853 26110 39470 1513 20322 13635 44414 1284 5229 5998 19700 1872 45691 5872 37168 4991 6456 34921 41632 16532 30269 3118 4987 2732 20486 26292 44061 2054 41607 20367 21071 33204 36717 35801 4725...
output:
2 2 4 4 4 4 4 2 4 4 4 4 4 4 4 2 1 4 4 1 4 4 1 4 4 2 4 2 4 2 1 4 4 4 4 1 1 1 4 2 4 1 4 2 4 1 1 2 2 2 4 4 1 1 1 4 1 1 4 2 4 4 1 4 2 2 4 4 4 2 1 4 4 1 1 4 4 1 2 1 2 1 4 2 1 2 4 2 4 4 4 4 4 1 2 2 1 1 1 4 2 1 4 4 2 4 2 4 4 1 1 4 4 2 2 1 2 1 1 4 4 4 4 4 4 1 1 1 4 2 4 1 2 2 1 4 4 4 4 4 4 1 4 4 2 1 2 2 2 1 ...
result:
ok 50000 lines
Test #7:
score: 0
Accepted
time: 73ms
memory: 7816kb
input:
50000 50000 1106 3307 13115 16051 30404 45806 2295 20076 3525 6384 9118 24628 3288 26835 17933 47506 26180 48256 23161 45529 10483 15545 5252 35302 10105 16247 14301 26402 104 216 562 29098 1517 16503 1494 5468 8057 47252 5582 15425 8766 41483 10952 31098 20891 49612 13088 18868 18880 28314 8650 208...
output:
1 2 4 2 4 4 2 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 1 2 1 4 4 1 2 4 2 1 4 4 4 4 4 2 4 4 4 4 1 2 1 2 1 4 4 2 2 4 4 1 4 4 4 2 2 2 1 4 2 4 2 4 4 4 2 2 4 2 2 1 4 4 2 4 4 4 2 1 4 1 4 4 4 4 4 4 1 2 2 2 4 1 2 1 4 2 4 2 4 4 4 1 4 2 4 4 2 4 2 4 2 4 4 1 4 4 2 1 4 4 4 2 4 2 2 2 2 2 4 4 2 4 4 2 2 4 1 2 1 4 4 2 2 2 4 ...
result:
ok 50000 lines
Test #8:
score: 0
Accepted
time: 76ms
memory: 10192kb
input:
50000 50000 36923 36924 2905 2906 20948 20949 17459 17460 37562 37563 48652 48653 19674 19675 5083 5084 18973 18974 6652 6653 14171 14172 10957 10958 29643 29644 18578 18579 8742 8743 28856 28857 3692 3693 9716 9717 26628 26629 10272 10273 3581 3582 5952 5953 8810 8811 48242 48243 49449 49450 22461 ...
output:
3 3 3 4 4 3 4 3 3 4 3 3 4 1 3 3 3 4 4 1 4 3 3 1 4 4 3 3 4 1 4 3 4 3 1 3 3 4 3 3 4 3 4 3 3 4 1 4 4 4 4 3 3 1 4 4 1 3 3 3 3 4 3 3 4 3 4 3 3 3 4 3 4 1 4 4 1 4 4 4 3 4 4 4 3 3 1 3 4 4 4 4 4 3 4 3 4 4 3 1 4 4 3 4 4 1 4 4 4 3 3 4 3 4 4 4 3 3 4 3 3 3 4 4 3 4 3 4 4 3 4 3 3 4 1 4 3 4 4 4 4 4 1 4 4 1 1 4 4 4 ...
result:
ok 50000 lines
Test #9:
score: 0
Accepted
time: 89ms
memory: 10200kb
input:
50000 50000 24442 24443 33810 33811 1074 1075 19395 19396 17355 17356 18062 18063 16633 16634 14075 14076 16668 16669 42955 42956 2381 2382 8174 8175 33065 33066 23490 23491 12964 12965 43083 43084 34043 34044 3067 3068 32847 32848 34631 34632 20740 20741 5545 5546 36224 36225 40474 40475 8726 8727 ...
output:
3 3 4 4 4 3 4 4 4 4 3 4 4 4 4 4 4 3 4 1 1 3 4 4 3 4 4 4 1 4 3 4 4 4 3 4 4 4 4 4 3 3 4 4 3 4 4 1 3 1 4 4 4 4 1 3 4 4 4 4 1 3 3 4 4 4 4 4 3 4 4 4 4 4 4 4 4 4 4 1 3 4 4 1 4 4 4 4 1 4 1 4 4 1 4 1 3 4 4 4 4 4 3 4 4 4 4 3 3 1 4 3 4 3 3 4 3 4 4 4 4 3 4 4 4 3 4 4 4 4 3 1 4 3 3 3 4 4 4 4 4 4 4 4 3 4 1 3 4 3 ...
result:
ok 50000 lines
Test #10:
score: 0
Accepted
time: 82ms
memory: 9948kb
input:
50000 50000 40842 40843 12739 12740 46074 46075 30742 30743 22435 22436 4320 4321 9400 9401 40706 40707 8828 8829 18753 18754 49910 49911 39576 39577 8444 8445 25799 25800 49700 49701 37009 37010 2714 2715 25544 25545 38257 38258 48120 48121 16639 16640 49101 49102 13588 13589 15000 15001 46269 4627...
output:
4 4 3 1 3 4 4 4 4 3 3 4 4 1 3 3 4 3 1 4 3 4 3 3 1 3 3 4 3 4 4 4 3 4 3 4 3 3 4 3 4 4 4 1 3 4 4 4 4 3 3 4 4 4 3 4 3 3 3 4 4 4 3 3 4 4 4 4 3 4 3 1 4 3 3 4 1 4 4 3 3 3 4 3 4 4 1 4 4 4 4 4 3 4 4 4 3 3 4 4 3 3 4 1 4 1 3 4 4 4 3 4 4 1 4 4 1 4 3 4 3 4 4 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 4 4 4 3 4 3 4 4 1 3 1 3 ...
result:
ok 50000 lines
Test #11:
score: 0
Accepted
time: 75ms
memory: 7828kb
input:
50000 50000 8009 12254 22108 22277 5752 17047 4139 8705 1591 4046 29067 29462 14609 40048 465 23331 4440 14716 9607 9722 13461 30905 36645 38691 1569 25431 2752 4554 214 34538 36719 44914 21390 24345 29832 31704 21884 44025 23443 39152 7339 21353 11648 46289 1971 3851 13124 18924 24293 31487 14625 2...
output:
3 3 3 3 1 3 1 3 1 3 3 1 3 1 1 1 1 3 3 3 1 4 3 1 3 3 3 3 3 3 3 1 3 3 4 3 3 1 3 3 1 3 1 1 3 3 4 4 3 1 3 1 4 1 3 3 3 3 3 4 3 3 3 1 3 3 1 3 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 4 4 3 4 1 3 1 4 1 3 1 1 1 1 3 1 3 3 3 3 3 3 1 1 3 1 4 3 3 3 3 3 1 3 3 1 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 3 3 3 1 1 3 4 1 1 3 4 3 3 1 1 ...
result:
ok 50000 lines
Test #12:
score: 0
Accepted
time: 98ms
memory: 7732kb
input:
50000 50000 25911 28394 6660 10841 8387 28553 3683 10256 13802 22801 12147 23011 16188 43369 5992 27667 12961 16775 2715 9516 28953 35973 2983 8072 11231 11882 8072 21167 5834 13733 5340 25884 462 1070 959 27073 809 4568 1345 25432 4809 8997 6625 44504 11148 14179 6983 30617 5970 13330 36575 37652 2...
output:
3 3 4 4 3 4 3 3 3 3 3 3 3 4 3 3 3 3 4 3 4 3 3 3 3 3 3 3 3 3 4 4 3 4 4 1 3 3 4 4 3 4 3 3 3 3 4 3 3 1 4 3 3 3 3 4 3 3 1 3 1 1 3 3 4 3 4 3 3 3 4 1 3 3 3 3 3 1 3 1 3 3 3 4 3 3 3 3 4 3 4 3 3 3 3 3 3 3 3 3 3 4 3 3 4 4 3 3 3 1 3 3 3 4 4 3 3 1 3 3 3 3 3 3 3 3 4 4 3 3 3 3 3 3 3 4 3 4 1 4 4 3 3 3 4 1 4 3 3 3 ...
result:
ok 50000 lines
Test #13:
score: 0
Accepted
time: 85ms
memory: 7820kb
input:
50000 50000 42553 43740 18549 40701 3806 34236 10812 24567 1202 22133 944 18780 5622 8617 9734 23242 29968 32325 6567 9568 6845 17190 1949 7833 22214 23070 1384 15280 6170 6561 28119 31703 6100 48374 980 8110 8426 15001 3332 7523 8030 23908 974 5799 7318 11335 14037 15714 13671 20465 43715 47320 210...
output:
1 4 4 1 3 1 4 3 3 1 4 4 3 4 1 4 3 3 4 4 4 4 3 3 4 4 4 4 4 3 1 4 4 3 4 4 1 1 4 1 4 3 4 1 1 4 3 3 1 1 1 3 3 3 4 1 1 1 4 4 3 3 3 3 3 1 1 3 1 3 3 3 1 1 3 4 1 1 1 3 3 3 4 1 3 3 1 3 4 3 4 4 3 4 3 4 3 4 3 3 4 3 3 1 3 4 3 1 4 1 1 3 4 1 3 1 4 4 4 4 1 4 1 4 3 1 1 1 3 3 1 3 3 4 1 1 3 3 3 1 1 3 4 4 4 3 4 3 1 1 ...
result:
ok 50000 lines
Test #14:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
4 1 1 2 1 3 1 4 2 3 3 4 2 3
output:
3
result:
ok single line: '3'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
6 1 1 2 2 6 1 5 2 3 1 4 3 6 4 5 2 4
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3508kb
input:
6 6 3 6 1 4 2 6 4 5 1 2 2 3 1 5 2 3 3 6 4 6 1 5 5 6 1 2
output:
2 2 4 2 4 1
result:
ok 6 lines
Test #17:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
7 1 1 3 3 4 1 2 3 5 6 7 2 6 4 5 2 7 2 5
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
17 8 1 2 2 3 3 4 4 5 1 6 6 7 7 8 8 9 1 10 10 11 11 12 12 13 1 14 14 15 15 16 16 17 5 9 13 17 1 5 2 6 3 7 4 8 5 9 1 8 1 16 2 11
output:
2 2 2 2 2 2 2 4
result:
ok 8 lines
Test #19:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 4 3 4 1 4 1 2 2 4 1 3 1 3 1 2 1 3 2 3
output:
3 3 3 4
result:
ok 4 lines
Test #20:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
5 5 2 4 2 5 1 2 1 4 1 5 2 3 3 4 4 5 2 5 3 4 3 4
output:
3 4 3 3 3
result:
ok 5 lines
Test #21:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
6 6 2 3 1 2 2 4 4 5 3 5 1 3 1 6 2 6 1 4 3 5 1 6 1 4 1 3
output:
3 4 3 1 4 3
result:
ok 6 lines
Test #22:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
7 7 2 5 1 6 4 7 5 6 1 2 1 3 2 4 3 5 2 3 2 4 1 2 2 7 3 5 1 7 2 7
output:
4 1 3 1 3 3 1
result:
ok 7 lines
Test #23:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
8 8 2 3 5 6 6 8 1 8 1 7 7 8 3 4 1 2 3 5 2 6 3 6 1 4 1 8 5 8 3 7 6 7 6 8
output:
3 3 3 3 3 4 4 3
result:
ok 8 lines
Test #24:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
9 9 2 8 4 5 5 6 2 7 1 2 4 6 4 9 1 5 2 4 2 3 4 7 5 7 3 5 3 4 6 7 2 5 4 9 1 2 3 6
output:
3 3 3 3 4 3 1 3 4
result:
ok 9 lines
Test #25:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
10 10 4 10 1 6 2 8 7 8 6 8 2 5 4 9 2 3 1 2 3 4 4 7 7 9 2 5 8 9 2 8 1 5 1 4 3 7 5 7 4 9 5 9
output:
3 1 3 3 3 4 3 3 1 3
result:
ok 10 lines
Test #26:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
11 11 1 2 2 3 9 10 3 6 7 11 2 5 3 9 1 4 2 6 3 5 4 7 2 8 9 10 8 11 6 8 2 9 3 11 4 5 3 9 8 9 9 10 3 11 2 4
output:
1 1 3 3 3 3 1 3 1 3 1
result:
ok 11 lines
Test #27:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
12 12 1 5 1 6 1 2 5 7 4 8 2 8 5 12 5 9 9 10 6 11 11 12 2 3 3 4 1 5 1 7 2 12 5 6 3 8 3 4 9 12 2 7 4 7 8 11 1 5 7 12
output:
2 2 2 2 2 2 2 2 4 4 2 2
result:
ok 12 lines
Test #28:
score: 0
Accepted
time: 2ms
memory: 3552kb
input:
13 13 4 5 5 11 1 3 2 4 4 10 2 10 7 9 1 6 1 2 1 4 6 8 4 7 8 12 7 13 2 8 2 9 3 13 2 11 3 9 2 3 7 9 2 6 10 13 2 7 11 12 2 8 7 13
output:
3 3 3 3 3 3 1 3 3 3 3 3 1
result:
ok 13 lines
Test #29:
score: 0
Accepted
time: 2ms
memory: 3504kb
input:
14 14 1 3 10 12 1 11 3 7 1 4 2 6 3 14 2 9 3 13 5 10 4 8 13 14 1 2 2 8 3 5 9 11 10 12 3 5 1 14 2 7 7 12 2 7 3 5 7 11 9 13 8 14 4 11 5 11 8 12
output:
2 1 1 2 2 1 2 1 1 4 4 2 1 2
result:
ok 14 lines
Test #30:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
15 15 5 6 10 15 8 10 6 7 2 3 9 14 1 2 9 12 1 5 3 10 2 8 3 4 1 9 6 13 1 14 7 11 2 14 6 11 9 12 5 10 11 15 8 9 4 14 4 10 6 13 4 6 1 8 3 8 8 14 2 11 9 13
output:
2 1 1 2 2 4 4 2 1 2 2 2 4 1 2
result:
ok 15 lines
Test #31:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
16 16 12 13 2 6 1 4 1 2 3 8 4 10 7 9 2 14 10 15 2 3 6 11 13 16 5 12 1 7 2 5 13 15 3 16 12 16 1 2 13 16 4 12 2 5 5 11 5 16 1 2 3 5 4 9 9 11 13 14 5 12 5 12 5 9 12 16
output:
4 3 3 4 3 3 4 3 4 3 3 3 3 3 4 4
result:
ok 16 lines
Test #32:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
17 17 4 9 3 14 2 4 2 8 3 10 9 11 3 7 1 3 1 2 4 13 4 5 10 17 2 3 6 12 6 16 5 6 1 10 3 15 4 16 3 6 1 14 3 14 12 15 8 12 2 14 6 13 1 8 14 17 9 17 4 15 12 14 1 6 7 16 10 12 9 17
output:
1 3 3 1 3 1 3 1 3 3 4 3 3 3 3 4 4
result:
ok 17 lines
Test #33:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
18 18 4 9 3 13 3 4 5 14 1 12 6 11 6 16 1 15 6 14 2 3 2 6 4 7 1 2 1 5 6 8 7 17 1 18 16 17 9 10 1 15 12 17 7 17 12 17 4 14 6 16 4 15 2 9 8 18 3 5 7 17 7 9 2 13 7 15 9 14 6 7 1 9 1 17
output:
1 4 3 4 4 3 4 3 3 4 3 3 3 4 4 3 4 4
result:
ok 18 lines
Test #34:
score: 0
Accepted
time: 2ms
memory: 3512kb
input:
19 19 2 7 6 9 11 19 4 10 8 17 3 6 3 5 8 11 2 18 5 13 1 3 10 13 9 15 12 17 6 16 3 4 4 8 1 2 12 14 6 12 5 11 10 14 4 19 1 3 1 9 3 15 7 19 3 9 4 5 14 18 3 8 11 14 1 4 3 12 1 5 5 16 4 17 14 18 1 17
output:
4 4 3 1 3 3 3 3 3 3 3 3 3 3 3 4 3 3 3
result:
ok 19 lines
Test #35:
score: 0
Accepted
time: 2ms
memory: 3500kb
input:
20 20 3 8 6 12 1 5 7 14 18 20 13 20 1 2 8 11 8 12 10 17 8 15 1 4 4 7 11 19 2 3 2 9 5 10 12 18 8 13 5 16 4 6 9 20 8 9 5 16 1 18 6 16 6 8 10 13 1 10 1 9 1 12 19 20 2 17 3 20 4 11 2 12 7 14 3 20 18 20 1 5 2 13
output:
4 3 1 4 3 3 4 1 3 3 3 3 4 3 3 1 4 3 1 4
result:
ok 20 lines
Test #36:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
100 200 15 84 22 89 29 48 46 59 3 5 33 69 20 77 1 56 2 13 13 60 5 24 24 97 45 52 23 37 8 23 47 99 41 75 7 25 69 70 24 93 18 27 4 51 67 78 5 30 2 3 6 39 1 2 13 16 8 26 73 74 25 28 17 47 70 83 72 79 9 66 15 91 4 10 9 11 24 33 22 29 1 4 4 32 20 41 70 100 43 55 59 89 6 7 2 14 1 90 41 54 13 20 28 98 28 3...
output:
3 3 4 3 4 4 4 1 1 3 3 4 4 4 4 4 4 4 4 4 3 3 3 3 4 4 1 3 4 3 3 3 1 3 3 4 4 4 1 3 3 4 3 3 4 4 3 3 3 3 1 3 4 1 4 4 3 3 1 3 4 3 1 3 3 3 3 4 1 3 3 1 3 3 3 3 3 3 3 4 4 3 3 3 3 4 3 4 4 4 4 4 3 4 3 4 3 4 3 3 4 3 1 3 4 4 4 3 3 3 3 3 1 3 3 4 3 3 4 3 4 4 1 3 3 3 3 4 3 1 3 3 4 4 3 3 3 4 1 3 3 4 3 3 4 3 3 3 3 3 ...
result:
ok 200 lines
Test #37:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
200 100 22 24 21 187 7 13 64 141 7 86 5 55 21 63 162 193 2 28 91 157 109 127 78 152 3 159 12 150 1 4 135 161 39 68 107 198 35 48 118 149 61 147 62 184 18 74 30 80 3 7 113 139 84 179 18 75 7 31 77 129 126 195 53 70 19 37 6 49 22 92 79 117 12 83 54 96 45 58 11 61 18 131 125 197 91 177 157 169 28 56 35...
output:
3 3 3 3 3 3 1 4 3 3 3 3 4 3 3 1 4 3 3 3 1 4 1 1 1 3 3 3 3 3 3 3 3 1 3 4 3 3 3 3 3 4 3 4 4 1 3 3 3 1 3 1 1 1 3 3 3 1 1 3 3 1 1 4 3 1 1 1 1 3 4 4 3 1 3 1 1 3 3 4 4 3 3 4 3 4 1 3 3 3 3 1 1 3 3 3 1 1 3 3
result:
ok 100 lines