Submission #905912


Source Code Expand

#include <memory.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

const int md = 924844033;
const int gen = 5;

int pw(int a, int b) {
  int x = 1, step = 1 << 30;
  while (step > 0) {
    x = (long long)x * x % md;
    if (step & b) x = (long long)x * a % md;
    step >>= 1;
  }
  return x;
}

void fft(vector <int> &a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    int j = 0;
    int x = i, y = n - 1;
    while (y > 0) {
      j = (j << 1) + (x & 1);
      x >>= 1;
      y >>= 1;
    }
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 1; len < n; len *= 2) {
    int root = pw(gen, (md - 1) / (2 * len));
    for (int i = 0; i < n; i += 2 * len) {
      int w = 1;
      for (int j = 0; j < len; j++) {
        int u = a[i + j];
        int v = (long long)a[i + j + len] * w % md;
        a[i + j] = u + v;
        if (a[i + j] >= md) a[i + j] -= md;
        a[i + j + len] = u - v;
        if (a[i + j + len] < 0) a[i + j + len] += md;
        w = (long long)w * root % md;
      }
    }
  }
}

vector <int> multiply(vector <int> a, vector <int> b) {
  int an = a.size();
  int bn = b.size();
  int need = an + bn - 1;
  int nn = 1;
  while (nn < 2 * an || nn < 2 * bn) nn <<= 1;
  a.resize(nn);
  b.resize(nn);
  fft(a);
  fft(b);
  for (int i = 0; i < nn; i++) a[i] = (long long)a[i] * b[i] % md;
  reverse(++a.begin(), a.end());
  fft(a);
  int inv = pw(nn, md - 2);
  for (int i = 0; i < nn; i++) a[i] = (long long)a[i] * inv % md;
  a.resize(need);
  return a;
}

const int N = 1 << 19;

int fact[N], invfact[N];

int C(int n, int k) {
  if (n < 0 || k < 0 || k > n) return 0;
  int ans = fact[n];
  ans = (long long)ans * invfact[k] % md;
  ans = (long long)ans * invfact[n - k] % md;
  return ans;
}

vector <int> g[N];
int cnt[N];
int n;

int dfs(int v, int pr) {
  int sz = g[v].size();
  int res = 1;
  for (int i = 0; i < sz; i++) {
    int u = g[v][i];
    if (u == pr) {
      continue;
    }
    res += dfs(u, v);
  }
  cnt[res]++;
  cnt[n - res]++;
  return res;
}

int ans[N];

int main() {
  fact[0] = 1;
  invfact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (long long)fact[i - 1] * i % md;
    int x = 1, step = 1 << 30;
    while (step > 0) {
      x = (long long)x * x % md;
      if (step & (md - 2)) x = (long long)x * i % md;
      step >>= 1;
    }
    invfact[i] = (long long)invfact[i - 1] * x % md;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int foo, bar;
    scanf("%d %d", &foo, &bar);
    foo--; bar--;
    g[foo].push_back(bar);
    g[bar].push_back(foo);
  }
  for (int i = 0; i < N; i++) {
    cnt[i] = 0;
  }
  dfs(0, -1);
  for (int i = 0; i < N; i++) {
    cnt[i] = (long long) cnt[i] * fact[i] % md;
  }
  vector <int> x, y;
  for (int i = 0; i < N; i++) {
    x.push_back(cnt[i]);
  }
  for (int i = N - 1; i >= 0; i--) {
    y.push_back(invfact[i]);
  }
  vector <int> z = multiply(x, y);
  for (int i = 1; i <= n; i++) {
    ans[i] = z[i + N - 1];
    ans[i] = (long long) ans[i] * invfact[i] % md;
    ans[i] = ((C(n, i) * 1LL * (n + 1) - ans[i]) % md + md) % md;
    printf("%d\n", ans[i]);
  }
  return 0;
}

Submission Info

Submission Time
Task F - Many Easy Problems
User tourist
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 3625 Byte
Status AC
Exec Time 791 ms
Memory 50032 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:130:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:136:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &foo, &bar);
                               ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1900 / 1900
Status
AC × 3
AC × 48
Set Name Test Cases
Sample example0, example1, example2
All doublestar0, doublestar1, doublestar2, doublestar3, doublestar4, example0, example1, example2, line0, line1, line2, line3, line4, maxrand0, maxrand1, maxrand10, maxrand11, maxrand12, maxrand13, maxrand14, maxrand15, maxrand16, maxrand17, maxrand18, maxrand19, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, star0, star1, star2, star3, star4
Case Name Status Exec Time Memory
doublestar0 AC 696 ms 39788 KB
doublestar1 AC 696 ms 39788 KB
doublestar2 AC 695 ms 39788 KB
doublestar3 AC 702 ms 39788 KB
doublestar4 AC 696 ms 39788 KB
example0 AC 609 ms 33132 KB
example1 AC 608 ms 33132 KB
example2 AC 617 ms 33132 KB
line0 AC 787 ms 49904 KB
line1 AC 785 ms 49904 KB
line2 AC 785 ms 50032 KB
line3 AC 790 ms 49904 KB
line4 AC 791 ms 49904 KB
maxrand0 AC 760 ms 39664 KB
maxrand1 AC 755 ms 39664 KB
maxrand10 AC 766 ms 39664 KB
maxrand11 AC 755 ms 39660 KB
maxrand12 AC 755 ms 39664 KB
maxrand13 AC 757 ms 39664 KB
maxrand14 AC 761 ms 39664 KB
maxrand15 AC 755 ms 39664 KB
maxrand16 AC 762 ms 39664 KB
maxrand17 AC 757 ms 39664 KB
maxrand18 AC 759 ms 39656 KB
maxrand19 AC 755 ms 39664 KB
maxrand2 AC 759 ms 39664 KB
maxrand3 AC 756 ms 39664 KB
maxrand4 AC 759 ms 39664 KB
maxrand5 AC 768 ms 39792 KB
maxrand6 AC 759 ms 39664 KB
maxrand7 AC 762 ms 39660 KB
maxrand8 AC 763 ms 39664 KB
maxrand9 AC 761 ms 39664 KB
rand0 AC 641 ms 33260 KB
rand1 AC 624 ms 33136 KB
rand2 AC 635 ms 33260 KB
rand3 AC 637 ms 33256 KB
rand4 AC 631 ms 33136 KB
rand5 AC 637 ms 33260 KB
rand6 AC 636 ms 33264 KB
rand7 AC 637 ms 33260 KB
rand8 AC 630 ms 33136 KB
rand9 AC 739 ms 33136 KB
star0 AC 688 ms 40172 KB
star1 AC 690 ms 40172 KB
star2 AC 688 ms 40172 KB
star3 AC 691 ms 40172 KB
star4 AC 688 ms 40172 KB