QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419649#8670. 独立alpha1022100 ✓481ms19384kbC++149.0kb2024-05-24 07:44:292024-05-24 07:44:30

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 07:44:30]
  • 评测
  • 测评结果:100
  • 用时:481ms
  • 内存:19384kb
  • [2024-05-24 07:44:29]
  • 提交

answer

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

const int mod = 998244353, K = 23, Root = 31;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
int quo2(int x) { return (x + (x & 1 ? mod : 0)) >> 1; }
void add(int &x, int y) { x += y, x = x >= mod ? x - mod : x; }
void sub(int &x, int y) { x -= y, x = x < 0 ? x + mod : x; }
void fam(int &x, int y, int z) { x = (x + (ll)y * z) % mod; }
int mpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1) {
    if (b & 1) ret = (ll)ret * a % mod;
    a = (ll)a * a % mod;
  }
  return ret;
}

const int BRUTE_N2_LIMIT = 50;

struct NumberTheory {
  mt19937 rng;
  void exGcd(int a, int b, int &x, int &y) {
    if (!b) {
      x = 1, y = 0;
      return;
    }
    exGcd(b, a % b, y, x), y -= a / b * x;
  }
  int inv(int a, int p = mod) {
    int x, y;
    exGcd(a, p, x, y);
    if (x < 0) x += p;
    return x;
  }
} nt;

namespace Simple {
  int n = 1;
  vector<int> fac({1, 1}), ifac({1, 1}), inv({0, 1});
  void build(int m) {
    n = m;
    fac.resize(n + 1), ifac.resize(n + 1), inv.resize(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
    fac[0] = ifac[0] = 1;
    for (int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % mod, ifac[i] = (ll)ifac[i - 1] * inv[i] % mod;
  }
  void check(int k) {
    int m = n;
    if (k > m) {
      while (k > m) m <<= 1;
      build(m);
    }
  }
  int gfac(int k) {
    check(k);
    return fac[k];
  }
  int gifac(int k) {
    check(k);
    return ifac[k];
  }
  int ginv(int k) {
    check(k);
    return inv[k];
  }
}

struct SimpleSequence {
  function<int(int)> func;
  SimpleSequence(const function<int(int)> &func): func(func) {}
  int operator[](int k) const { return func(k); }
} gfac(Simple::gfac), gifac(Simple::gifac), ginv(Simple::ginv);

int binom(int n, int m) {
  if (m > n || m < 0) return 0;
  return (ll)gfac[n] * gifac[m] % mod * gifac[n - m] % mod;
}

namespace NTT {
  int L = -1;
  vector<int> root;
  void init(int l) {
    L = l;
    root.resize((1 << L) + 1);
    int n = 1 << L, *w = root.data();
    w[0] = 1, w[1 << L] = mpow(Root, 1 << (K - 2 - L));
    for (int i = L; i; --i) w[1 << (i - 1)] = (ll)w[1 << i] * w[1 << i] % mod;
    for (int i = 1; i < n; ++i) w[i] = (ll)w[i & (i - 1)] * w[i & -i] % mod;
  }
  void DIF(int *a, int l) {
    int n = 1 << l;
    for (int len = n >> 1; len; len >>= 1)
      for (int *j = a, *o = root.data(); j != a + n; j += len << 1, ++o)
        for (int *k = j; k != j + len; ++k) {
          int r = (ll)*o * k[len] % mod;
          k[len] = reduce(*k - r), add(*k, r);
        }
  }
  void DIT(int *a, int l) {
    int n = 1 << l;
    for (int len = 1; len < n; len <<= 1)
      for (int *j = a, *o = root.data(); j != a + n; j += len << 1, ++o)
        for (int *k = j; k != j + len; ++k) {
          int r = norm(*k + k[len]);
          k[len] = (ll)*o * (*k - k[len] + mod) % mod, *k = r;
        }
  }
  void fft(int *a, int lgn, int d = 1) {
    if (L < lgn) init(lgn);
    int n = 1 << lgn;
    if (d == 1) DIF(a, lgn);
    else {
      DIT(a, lgn), reverse(a + 1, a + n);
      int nInv = mod - (mod - 1) / n;
      for (int i = 0; i < n; ++i) a[i] = (ll)a[i] * nInv % mod;
    }
  }
}

struct poly {
  vector<int> a;
  poly(ll v = 0): a(1) {
    if ((v %= mod) < 0) v += mod;
    a[0] = v;
  }
  poly(const poly &o): a(o.a) {}
  poly(const vector<int> &o): a(o) {}
  poly(initializer_list<int> o): a(o) {}
  operator vector<int>() const { return a; }
  int operator[](int k) const { return k < a.size() ? a[k] : 0; }
  int &operator[](int k) {
    if (k >= a.size()) a.resize(k + 1);
    return a[k];
  }
  int deg() const { return (int)a.size() - 1; }
  void redeg(int d) { a.resize(d + 1); }
  int size() const { return a.size(); }
  void resize(int s) { a.resize(s); }
  bool empty() const { return a.empty(); }
  int back() const { return a.back(); }
  poly slice(int d) const {
    if (d < a.size()) return vector<int>(a.begin(), a.begin() + d + 1);
    vector<int> ret = a;
    ret.resize(d + 1);
    return ret;
  }
  poly shift(int k) const {
    if (size() + k <= 0) return 0;
    vector<int> ret(size() + k);
    for (int i = max(0, k); i < ret.size(); ++i) ret[i] = a[i - k];
    return ret;
  }
  int *base() { return a.data(); }
  const int *base() const { return a.data(); }

  poly operator-() const {
    poly ret = a;
    for (int i = 0; i < a.size(); ++i) ret[i] = neg(ret[i]);
    return ret;
  }
  poly operator*(const poly &) const;
  poly &operator*=(const poly &o) {
    *this = operator*(o);
    return *this;
  }
};

poly zeroes(int d) { return vector<int>(d + 1); }

namespace NTT {
  void fft(poly &a, int lgn, int d = 1) { fft(a.base(), lgn, d); }
  void fft(vector<int> &a, int lgn, int d = 1) { fft(a.data(), lgn, d); }
}

using NTT::fft;

poly poly::operator*(const poly &o) const {
  int n = deg(), m = o.deg();
  if (n == -1 || m == -1) return vector<int>();
  if (n <= 10 || m <= 10 || n + m <= BRUTE_N2_LIMIT) {
    poly ret = zeroes(n + m);
    for (int i = 0; i <= n; ++i)
      for (int j = 0; j <= m; ++j) fam(ret[i + j], a[i], o[j]);
    return ret;
  }
  n += m;
  int l = 0;
  while ((1 << l) <= n) ++l;
  poly ret = a, tmp = o;
  ret.resize(1 << l), tmp.resize(1 << l);
  fft(ret, l), fft(tmp, l);
  for (int i = 0; i < (1 << l); ++i) ret[i] = (ll)ret[i] * tmp[i] % mod;
  fft(ret, l, -1);
  return ret.slice(n);
}

struct Transposition {
  vector<int> _mul(int l, vector<int> res, const poly &b) {
    vector<int> tmp(1 << l);
    memcpy(tmp.data(), b.base(), sizeof(int) * (b.deg() + 1));
    reverse(tmp.begin() + 1, tmp.end());
    fft(tmp.data(), l);
    for (int i = 0; i < (1 << l); ++i) res[i] = (ll)res[i] * tmp[i] % mod;
    fft(res.data(), l, -1);
    return res;
  }
  poly bfMul(const poly &a, const poly &b) {
    int n = a.deg(), m = b.deg();
    poly ret = zeroes(n - m);
    for (int i = 0; i <= n - m; ++i)
      for (int j = 0; j <= m; ++j) ret[i] = (ret[i] + (ll)a[i + j] * b[j]) % mod;
    return ret;
  }
  poly mul(const poly &a, const poly &b) {
    if (a.deg() < b.deg()) return 0;
    if (a.deg() <= BRUTE_N2_LIMIT) return bfMul(a, b);
    int l = 0;
    while ((1 << l) <= a.deg()) ++l;
    vector<int> res(1 << l);
    memcpy(res.data(), a.base(), sizeof(int) * (a.deg() + 1));
    fft(res.data(), l);
    res = _mul(l, res, b);
    res.resize(a.deg() - b.deg() + 1);
    return res;
  }
} tp;

int main() {
  int n, m; scanf("%d%d", &n, &m);
  vector<vector<int>> e(n);
  for (int i = 1; i < n; ++i) {
    int u, v; scanf("%d%d", &u, &v), --u, --v, e[u].push_back(v), e[v].push_back(u);
  }
  vector<int> fa(n, -1), siz(n, 1); vector<poly> f(n);
  int ans = 0;
  if (m <= n + 1) {
    function<void(int)> dfs = [&](int u) {
      f[u] = poly(1).slice(m - 1);
      for (int v : e[u])
        if (v != fa[u])
          fa[v] = u, dfs(v), f[u] = (f[u] * f[v]).slice(m - 1), siz[u] += siz[v];
      for (int i = 1; i < m; ++i) add(f[u][i], f[u][i - 1]);
      int fix = mpow(m, siz[u]);
      for (int i = 0; i < m; ++i) sub(fix, f[u][i]);
      f[u].redeg(m), reverse(f[u].base(), f[u].base() + m + 1), add(f[u][0], fix);
      for (int i = 1; i <= m; ++i) ans = (ans + (ll)f[u][i] * i % mod * mpow(m, n - siz[u])) % mod;
    }; dfs(0);
  } else {
    vector<int> fac(n * 3 + 2), ifac(n * 3 + 2);
    fac[0] = m - n - 1;
    for (int i = 1; i <= n * 3 + 1; ++i) fac[i] = (ll)fac[i - 1] * (m - n - 1 + i) % mod;
    ifac[n * 3 + 1] = mpow(fac[n * 3 + 1], mod - 2);
    for (int i = n * 3 + 1; i; --i) ifac[i - 1] = (ll)ifac[i] * (m - n - 1 + i) % mod;
    function<void(int)> dfs = [&](int u) {
      f[u] = 1;
      for (int v : e[u])
        if (v != fa[u])
          fa[v] = u, dfs(v), f[u] *= f[v], siz[u] += siz[v];
      int fix = mpow(m, siz[u]);
      for (int i = 0; i < siz[u]; ++i)
        fix = (fix + (ll)(mod - f[u][i]) * fac[n - i + siz[u]] % mod * ifac[n - i] % mod * gifac[siz[u]]) % mod;
      poly g = zeroes(siz[u] * 2 - 2);
      for (int i = -siz[u] + 1; i < siz[u]; ++i) g[siz[u] - 1 + i] = (ll)fac[n + i + siz[u]] * ifac[n + i + 1] % mod;
      reverse(f[u].base(), f[u].base() + siz[u]);
      g = -tp.mul(g, f[u]) * gifac[siz[u] - 1];
      poly h = zeroes(siz[u]);
      for (int i = 0; i <= siz[u]; ++i) h[i] = i & 1 ? mod - binom(siz[u], i) : binom(siz[u], i);
      g = (g * h.slice(siz[u] - 1)).slice(siz[u] - 1);
      if (siz[u] & 1) g = -g;
      g.redeg(siz[u]), reverse(g.base(), g.base() + siz[u] + 1), f[u] = g;
      for (int i = 0; i <= siz[u]; ++i) f[u][i] = (f[u][i] + (ll)fix * h[i]) % mod;
      int s = 0;
      for (int i = 0; i <= siz[u]; ++i)
        s = (s + ((ll)i * (siz[u] + 1) + (ll)siz[u] * (m - i)) % mod * ifac[n - i + 1] % mod * fac[n - i + siz[u] + 1] % mod * f[u][i]) % mod;
      ans = (ans + (ll)s * mpow(m, n - siz[u]) % mod * gifac[siz[u] + 1]) % mod;
    }; dfs(0);
  }
  printf("%d\n", ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 11
Accepted

Test #1:

score: 11
Accepted
time: 1ms
memory: 3832kb

input:

4 1
1 2
1 3
1 4

output:

3

result:

ok single line: '3'

Test #2:

score: 11
Accepted
time: 1ms
memory: 3924kb

input:

2 4
1 2

output:

50

result:

ok single line: '50'

Test #3:

score: 11
Accepted
time: 0ms
memory: 3884kb

input:

3 1
1 2
1 3

output:

2

result:

ok single line: '2'

Test #4:

score: 11
Accepted
time: 1ms
memory: 3840kb

input:

5 5
1 2
1 3
1 4
4 5

output:

30873

result:

ok single line: '30873'

Test #5:

score: 11
Accepted
time: 0ms
memory: 4108kb

input:

5 5
1 2
2 3
1 4
1 5

output:

30873

result:

ok single line: '30873'

Test #6:

score: 11
Accepted
time: 1ms
memory: 3840kb

input:

5 5
1 2
1 3
2 4
3 5

output:

29268

result:

ok single line: '29268'

Subtask #2:

score: 24
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 24
Accepted
time: 0ms
memory: 4140kb

input:

20 18
1 2
2 3
1 4
1 5
1 6
1 7
5 8
1 9
1 10
2 11
5 12
11 13
5 14
5 15
3 16
7 17
15 18
9 19
19 20

output:

326123819

result:

ok single line: '326123819'

Test #8:

score: 24
Accepted
time: 0ms
memory: 4088kb

input:

18 14
1 2
2 3
3 4
2 5
1 6
4 7
7 8
5 9
6 10
7 11
2 12
1 13
4 14
4 15
8 16
3 17
1 18

output:

26385774

result:

ok single line: '26385774'

Test #9:

score: 24
Accepted
time: 1ms
memory: 3848kb

input:

20 20
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20

output:

799358395

result:

ok single line: '799358395'

Test #10:

score: 24
Accepted
time: 0ms
memory: 3856kb

input:

20 20
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20

output:

819211514

result:

ok single line: '819211514'

Test #11:

score: 24
Accepted
time: 0ms
memory: 3856kb

input:

20 18
1 2
2 3
2 4
3 5
1 6
2 7
4 8
4 9
6 10
8 11
10 12
12 13
12 14
10 15
15 16
13 17
14 18
17 19
15 20

output:

788316439

result:

ok single line: '788316439'

Test #12:

score: 24
Accepted
time: 1ms
memory: 3852kb

input:

19 19
1 2
1 3
1 4
2 5
3 6
3 7
4 8
8 9
9 10
6 11
8 12
11 13
13 14
11 15
11 16
12 17
17 18
16 19

output:

481833846

result:

ok single line: '481833846'

Subtask #3:

score: 13
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 13
Accepted
time: 1ms
memory: 3900kb

input:

131 428
1 2
2 3
1 4
4 5
3 6
5 7
4 8
7 9
4 10
5 11
1 12
9 13
3 14
10 15
2 16
15 17
13 18
11 19
14 20
19 21
1 22
16 23
17 24
19 25
2 26
1 27
5 28
4 29
29 30
10 31
25 32
22 33
19 34
15 35
24 36
19 37
29 38
15 39
4 40
30 41
6 42
9 43
29 44
36 45
38 46
20 47
26 48
13 49
17 50
45 51
9 52
24 53
43 54
26 55...

output:

855674508

result:

ok single line: '855674508'

Test #14:

score: 13
Accepted
time: 1ms
memory: 4004kb

input:

415 425
1 2
2 3
3 4
1 5
4 6
4 7
2 8
1 9
9 10
4 11
4 12
3 13
1 14
7 15
10 16
7 17
11 18
16 19
16 20
11 21
20 22
21 23
20 24
22 25
5 26
21 27
7 28
6 29
25 30
29 31
11 32
30 33
17 34
13 35
6 36
6 37
36 38
37 39
23 40
30 41
35 42
10 43
19 44
6 45
26 46
22 47
36 48
36 49
32 50
1 51
24 52
19 53
49 54
48 5...

output:

921095443

result:

ok single line: '921095443'

Test #15:

score: 13
Accepted
time: 1ms
memory: 3984kb

input:

223 325
1 2
2 3
1 4
1 5
3 6
4 7
4 8
4 9
1 10
5 11
11 12
9 13
4 14
1 15
15 16
15 17
1 18
2 19
1 20
9 21
2 22
18 23
14 24
7 25
9 26
2 27
12 28
1 29
11 30
13 31
4 32
22 33
31 34
21 35
29 36
9 37
7 38
14 39
13 40
40 41
25 42
14 43
25 44
34 45
13 46
7 47
19 48
36 49
11 50
10 51
24 52
13 53
14 54
36 55
18...

output:

954879612

result:

ok single line: '954879612'

Test #16:

score: 13
Accepted
time: 3ms
memory: 4612kb

input:

452 126
1 2
2 3
3 4
3 5
2 6
2 7
2 8
2 9
4 10
3 11
8 12
7 13
5 14
14 15
6 16
8 17
1 18
11 19
2 20
1 21
5 22
11 23
2 24
18 25
2 26
2 27
10 28
16 29
28 30
22 31
30 32
23 33
25 34
19 35
12 36
4 37
15 38
37 39
4 40
5 41
22 42
35 43
38 44
37 45
13 46
27 47
41 48
17 49
48 50
33 51
7 52
51 53
27 54
33 55
14...

output:

374580067

result:

ok single line: '374580067'

Test #17:

score: 13
Accepted
time: 22ms
memory: 5956kb

input:

500 500
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 ...

output:

318407545

result:

ok single line: '318407545'

Test #18:

score: 13
Accepted
time: 27ms
memory: 5872kb

input:

500 500
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
...

output:

792738825

result:

ok single line: '792738825'

Test #19:

score: 13
Accepted
time: 10ms
memory: 4264kb

input:

498 500
1 2
2 3
2 4
1 5
2 6
5 7
5 8
8 9
7 10
10 11
7 12
10 13
11 14
12 15
12 16
13 17
15 18
16 19
17 20
16 21
17 22
21 23
22 24
21 25
21 26
25 27
25 28
24 29
26 30
29 31
27 32
29 33
30 34
33 35
34 36
36 37
35 38
37 39
39 40
36 41
41 42
40 43
39 44
44 45
45 46
43 47
46 48
44 49
49 50
46 51
47 52
49 5...

output:

877351641

result:

ok single line: '877351641'

Test #20:

score: 13
Accepted
time: 26ms
memory: 6000kb

input:

499 492
1 2
2 3
2 4
2 5
1 6
3 7
5 8
8 9
7 10
6 11
11 12
8 13
10 14
13 15
13 16
14 17
15 18
17 19
18 20
18 21
17 22
20 23
21 24
21 25
21 26
25 27
26 28
27 29
29 30
28 31
30 32
30 33
29 34
32 35
35 36
34 37
33 38
38 39
37 40
39 41
37 42
41 43
40 44
40 45
43 46
44 47
47 48
46 49
46 50
48 51
49 52
52 53...

output:

839162155

result:

ok single line: '839162155'

Test #21:

score: 13
Accepted
time: 10ms
memory: 4320kb

input:

496 500
1 2
1 3
3 4
2 5
2 6
6 7
7 8
5 9
5 10
10 11
9 12
12 13
12 14
12 15
11 16
14 17
15 18
14 19
17 20
17 21
17 22
22 23
19 24
21 25
24 26
25 27
24 28
24 29
27 30
27 31
31 32
31 33
32 34
31 35
33 36
35 37
34 38
37 39
36 40
38 41
41 42
42 43
41 44
41 45
44 46
42 47
44 48
47 49
45 50
47 51
48 52
49 5...

output:

47619248

result:

ok single line: '47619248'

Test #22:

score: 13
Accepted
time: 0ms
memory: 4208kb

input:

250 500
1 2
1 3
3 4
3 5
5 6
5 7
7 8
7 9
9 10
9 11
11 12
11 13
13 14
13 15
15 16
15 17
17 18
17 19
19 20
19 21
21 22
21 23
23 24
23 25
25 26
25 27
27 28
27 29
29 30
29 31
31 32
31 33
33 34
33 35
35 36
35 37
37 38
37 39
39 40
39 41
41 42
41 43
43 44
43 45
45 46
45 47
47 48
47 49
49 50
49 51
51 52
51 5...

output:

765248458

result:

ok single line: '765248458'

Subtask #4:

score: 27
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #23:

score: 27
Accepted
time: 1ms
memory: 3880kb

input:

100 8917507
1 2
1 3
3 4
3 5
2 6
6 7
1 8
6 9
8 10
9 11
10 12
1 13
2 14
14 15
10 16
6 17
1 18
10 19
14 20
11 21
19 22
12 23
18 24
12 25
2 26
20 27
2 28
3 29
13 30
4 31
29 32
26 33
32 34
7 35
32 36
7 37
27 38
19 39
9 40
9 41
4 42
24 43
22 44
33 45
33 46
29 47
14 48
33 49
45 50
17 51
33 52
28 53
35 54
1...

output:

268113455

result:

ok single line: '268113455'

Test #24:

score: 27
Accepted
time: 2ms
memory: 4272kb

input:

422 19747075
1 2
2 3
1 4
3 5
3 6
4 7
4 8
8 9
9 10
5 11
8 12
10 13
7 14
2 15
15 16
8 17
15 18
14 19
4 20
1 21
11 22
20 23
11 24
14 25
15 26
7 27
17 28
9 29
23 30
12 31
3 32
16 33
1 34
30 35
16 36
17 37
28 38
29 39
32 40
3 41
10 42
33 43
37 44
19 45
17 46
26 47
5 48
44 49
42 50
31 51
29 52
40 53
51 54...

output:

946606434

result:

ok single line: '946606434'

Test #25:

score: 27
Accepted
time: 1ms
memory: 3888kb

input:

252 80449725
1 2
1 3
1 4
3 5
1 6
6 7
3 8
8 9
1 10
6 11
1 12
11 13
10 14
1 15
15 16
8 17
4 18
16 19
2 20
12 21
1 22
17 23
17 24
1 25
19 26
9 27
6 28
17 29
19 30
30 31
23 32
32 33
25 34
3 35
15 36
2 37
20 38
17 39
31 40
27 41
11 42
23 43
35 44
30 45
20 46
3 47
38 48
14 49
26 50
31 51
22 52
33 53
36 54...

output:

362245610

result:

ok single line: '362245610'

Test #26:

score: 27
Accepted
time: 1ms
memory: 4004kb

input:

405 83386580
1 2
2 3
1 4
1 5
4 6
3 7
1 8
7 9
1 10
3 11
8 12
9 13
5 14
2 15
1 16
1 17
11 18
12 19
12 20
1 21
10 22
1 23
15 24
10 25
4 26
17 27
21 28
3 29
27 30
26 31
26 32
27 33
17 34
7 35
24 36
11 37
7 38
13 39
17 40
1 41
10 42
42 43
17 44
11 45
26 46
18 47
9 48
45 49
26 50
45 51
42 52
31 53
33 54
8...

output:

678972362

result:

ok single line: '678972362'

Test #27:

score: 27
Accepted
time: 28ms
memory: 4564kb

input:

500 100000000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 ...

output:

705713378

result:

ok single line: '705713378'

Test #28:

score: 27
Accepted
time: 2ms
memory: 4352kb

input:

500 100000000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60...

output:

244438911

result:

ok single line: '244438911'

Test #29:

score: 27
Accepted
time: 5ms
memory: 4368kb

input:

491 55280954
1 2
1 3
2 4
2 5
4 6
3 7
6 8
8 9
8 10
7 11
10 12
8 13
9 14
12 15
12 16
14 17
13 18
16 19
17 20
17 21
17 22
22 23
22 24
20 25
25 26
22 27
27 28
26 29
27 30
30 31
31 32
32 33
31 34
31 35
35 36
32 37
37 38
36 39
37 40
40 41
40 42
40 43
42 44
41 45
42 46
46 47
43 48
45 49
48 50
48 51
48 52
4...

output:

564876887

result:

ok single line: '564876887'

Test #30:

score: 27
Accepted
time: 10ms
memory: 4256kb

input:

500 11609594
1 2
1 3
2 4
1 5
4 6
2 7
7 8
8 9
5 10
6 11
8 12
8 13
9 14
13 15
15 16
13 17
15 18
14 19
15 20
20 21
18 22
22 23
23 24
24 25
25 26
25 27
24 28
24 29
28 30
27 31
30 32
28 33
32 34
32 35
31 36
36 37
33 38
34 39
36 40
38 41
37 42
38 43
39 44
43 45
42 46
43 47
47 48
45 49
48 50
50 51
49 52
49...

output:

228579924

result:

ok single line: '228579924'

Test #31:

score: 27
Accepted
time: 10ms
memory: 4292kb

input:

494 31306076
1 2
1 3
3 4
4 5
1 6
4 7
5 8
6 9
5 10
8 11
9 12
8 13
13 14
10 15
13 16
12 17
14 18
15 19
18 20
16 21
18 22
22 23
19 24
21 25
22 26
25 27
27 28
26 29
26 30
30 31
30 32
29 33
31 34
31 35
33 36
35 37
34 38
37 39
36 40
36 41
39 42
42 43
39 44
44 45
45 46
46 47
46 48
44 49
48 50
50 51
51 52
4...

output:

643295951

result:

ok single line: '643295951'

Test #32:

score: 27
Accepted
time: 2ms
memory: 4188kb

input:

250 100000000
1 2
1 3
3 4
3 5
5 6
5 7
7 8
7 9
9 10
9 11
11 12
11 13
13 14
13 15
15 16
15 17
17 18
17 19
19 20
19 21
21 22
21 23
23 24
23 25
25 26
25 27
27 28
27 29
29 30
29 31
31 32
31 33
33 34
33 35
35 36
35 37
37 38
37 39
39 40
39 41
41 42
41 43
43 44
43 45
45 46
45 47
47 48
47 49
49 50
49 51
51 5...

output:

79358352

result:

ok single line: '79358352'

Subtask #5:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #33:

score: 25
Accepted
time: 2ms
memory: 4376kb

input:

1514 72630467
1 2
1 3
1 4
4 5
5 6
1 7
1 8
5 9
3 10
6 11
6 12
5 13
3 14
12 15
8 16
16 17
4 18
11 19
13 20
14 21
18 22
22 23
23 24
9 25
19 26
17 27
24 28
4 29
11 30
17 31
2 32
14 33
12 34
15 35
28 36
6 37
28 38
24 39
25 40
16 41
6 42
18 43
15 44
8 45
13 46
20 47
33 48
37 49
30 50
16 51
7 52
41 53
23 5...

output:

771044900

result:

ok single line: '771044900'

Test #34:

score: 25
Accepted
time: 3ms
memory: 4432kb

input:

1771 2668838
1 2
2 3
1 4
2 5
4 6
3 7
6 8
8 9
3 10
6 11
9 12
10 13
10 14
13 15
15 16
2 17
8 18
12 19
10 20
14 21
16 22
9 23
18 24
6 25
17 26
26 27
1 28
26 29
20 30
18 31
12 32
1 33
23 34
33 35
4 36
1 37
26 38
24 39
37 40
7 41
28 42
12 43
33 44
16 45
30 46
20 47
3 48
30 49
22 50
50 51
22 52
41 53
2 54...

output:

573260204

result:

ok single line: '573260204'

Test #35:

score: 25
Accepted
time: 182ms
memory: 13676kb

input:

1774 710
1 2
1 3
3 4
1 5
3 6
2 7
6 8
4 9
3 10
3 11
1 12
6 13
7 14
12 15
7 16
6 17
7 18
2 19
2 20
17 21
12 22
13 23
4 24
12 25
25 26
4 27
16 28
4 29
7 30
29 31
5 32
16 33
18 34
33 35
29 36
21 37
25 38
12 39
11 40
11 41
41 42
16 43
40 44
34 45
6 46
45 47
5 48
41 49
21 50
26 51
21 52
22 53
6 54
9 55
37...

output:

362013258

result:

ok single line: '362013258'

Test #36:

score: 25
Accepted
time: 211ms
memory: 17872kb

input:

1865 952
1 2
1 3
1 4
4 5
2 6
6 7
7 8
1 9
8 10
4 11
7 12
5 13
1 14
9 15
15 16
11 17
11 18
1 19
8 20
15 21
7 22
12 23
11 24
11 25
5 26
19 27
3 28
6 29
29 30
1 31
13 32
29 33
22 34
16 35
4 36
5 37
27 38
1 39
22 40
28 41
9 42
32 43
28 44
40 45
41 46
38 47
8 48
20 49
47 50
37 51
39 52
7 53
20 54
49 55
40...

output:

996024345

result:

ok single line: '996024345'

Test #37:

score: 25
Accepted
time: 481ms
memory: 14740kb

input:

2000 100000000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51...

output:

426981666

result:

ok single line: '426981666'

Test #38:

score: 25
Accepted
time: 14ms
memory: 4432kb

input:

2000 100000000
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 6...

output:

646449010

result:

ok single line: '646449010'

Test #39:

score: 25
Accepted
time: 161ms
memory: 7556kb

input:

1993 76023311
1 2
1 3
2 4
3 5
4 6
4 7
3 8
5 9
8 10
7 11
7 12
11 13
11 14
11 15
11 16
16 17
17 18
14 19
17 20
17 21
19 22
20 23
19 24
24 25
22 26
23 27
26 28
28 29
28 30
30 31
29 32
28 33
32 34
31 35
32 36
33 37
36 38
36 39
39 40
36 41
41 42
38 43
39 44
42 45
43 46
44 47
45 48
46 49
47 50
49 51
50 52...

output:

579873711

result:

ok single line: '579873711'

Test #40:

score: 25
Accepted
time: 165ms
memory: 7688kb

input:

1998 30040018
1 2
1 3
3 4
2 5
2 6
3 7
7 8
7 9
7 10
8 11
7 12
10 13
11 14
10 15
13 16
12 17
15 18
16 19
15 20
18 21
18 22
19 23
21 24
23 25
24 26
23 27
25 28
28 29
25 30
29 31
29 32
29 33
33 34
34 35
33 36
34 37
34 38
37 39
39 40
38 41
41 42
38 43
40 44
42 45
44 46
42 47
43 48
48 49
49 50
48 51
47 52...

output:

964923618

result:

ok single line: '964923618'

Test #41:

score: 25
Accepted
time: 228ms
memory: 19384kb

input:

1990 943
1 2
2 3
2 4
4 5
3 6
2 7
4 8
8 9
8 10
6 11
10 12
9 13
13 14
10 15
12 16
16 17
15 18
15 19
16 20
20 21
21 22
22 23
20 24
21 25
21 26
24 27
27 28
28 29
28 30
27 31
29 32
28 33
32 34
32 35
32 36
33 37
33 38
36 39
39 40
40 41
37 42
39 43
41 44
43 45
43 46
43 47
45 48
48 49
45 50
46 51
48 52
49 5...

output:

184212933

result:

ok single line: '184212933'

Test #42:

score: 25
Accepted
time: 257ms
memory: 10332kb

input:

2000 100000000
1 2
1 3
3 4
3 5
5 6
5 7
7 8
7 9
9 10
9 11
11 12
11 13
13 14
13 15
15 16
15 17
17 18
17 19
19 20
19 21
21 22
21 23
23 24
23 25
25 26
25 27
27 28
27 29
29 30
29 31
31 32
31 33
33 34
33 35
35 36
35 37
37 38
37 39
39 40
39 41
41 42
41 43
43 44
43 45
45 46
45 47
47 48
47 49
49 50
49 51
51 ...

output:

364931793

result:

ok single line: '364931793'