Submission #907572


Source Code Expand

#include <bits/stdc++.h>
 
using namespace std;
 
int const MOD = 924844033;
int mul(int x, int y) {
  return (int) ((long long) x * y % MOD);
}
 
int modpow(int a, int b) {
  int ret = 1;
  while (b > 0) {
    if (b & 1) {
      ret = mul(ret, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
int const N = 1234567;
int FACT[N], INVFACT[N], INV[N];
 
int c(int n, int k) {
  if (k > n || k < 0) return 0;
  return mul(FACT[n], mul(INVFACT[k], INVFACT[n - k]));
}
 
int ans[N];
int n;
 
int sz[N];
 
vector<int> edges[N];
 
int f[N];
 
 
void dfs(int v, int pv) {
  sz[v] = 1;
  for (int to : edges[v]) {
    if (to != pv) {
      dfs(to, v);
      sz[v] += sz[to];
    }
  }
  add(f[n], 1);
  add(f[n - sz[v]], MOD - 1);
  for (int to : edges[v]) {
    if (to != pv) {
      add(f[sz[to]], MOD - 1);
    }
  }
}
 
int const G = 5;
int ROOT;
int const F = 21;
int rpws[(1 << F) + 1];
 
int inverse(int x, int bits) {
  int y = 0;
  for (int i = 0; i < bits; i++) {
    y = (y << 1) | (x & 1);
    x >>= 1;
  }
  return y;
}
int px[1 << F], py[1 << F];
 
void fft(int *a, int bits, bool inv) {
  int n = 1 << bits;
  for (int i = 0; i < n; i++) {
    int j = inverse(i, bits);
    if (i < j) {
      std::swap(a[i], a[j]);
    }
  }
  for (int len = 2; len <= n; len <<= 1) {
    int half = len >> 1;
    int step = (1 << F) / len;
    for (int i = 0; i < n; i += len) {
      int k = inv ? (1 << F) : 0;
      for (int j = 0; j < half; j++) {
        int u = a[i + j];
        int v = mul(a[i + j + half], rpws[k]);
        int x = u;
        add(x, v);
        int y = u;
        add(y, MOD - v);
        a[i + j] = x;
        a[i + j + half] = y;
        if (inv) {
          k -= step;
        } else {
          k += step;
        }
      }
    }
  }
  if (inv) {
    int invn = modpow(n, MOD - 2);
    for (int i = 0; i < n; i++) {
      a[i] = mul(a[i], invn);
    }
  }
}
 
void mul(int *px, int *py, int bits) {  
  fft(px, bits, false);
  fft(py, bits, false);
  int n = 1 << bits;
  for (int i = 0; i < n; i++) {
    px[i] = mul(px[i], py[i]);
  }
  fft(px, bits, true);
}
 
void go(int l, int r) {
  if (l + 1 >= r) return;
  int mid = (l + r) >> 1;
  go(l, mid);
  go(mid, r);
  int len = (r - l + 1) / 2 + 2;
  int p2 = 1;
  int bits = 0;
  while (p2 < len) {
    p2 <<= 1;
    ++bits;
  }
  fill(px, px + 2 * p2, 0);
  fill(py, py + 2 * p2, 0);
  for (int i = mid; i < r; i++) {
    px[i - mid] = f[i];
  }
  // for (int i = 0; i < p2; i++) printf("%d ", px[i]);
  // printf("* ");
  for (int i = l; i < mid; i++) {
    py[p2 - (i - l) - 1] = INVFACT[i];
  }
  // for (int i = 0; i < p2; i++) {
  //   printf("%d ", py[i]);
  // }
  int lsize = mid - l;
  mul(px, py, bits + 1);
  // printf(" =");
  // for (int i = 0; i < 2 * p2; i++) printf("%d ", px[i]);
  // puts("");
  for (int i = p2 - lsize; i < 2 * p2; i++) {
    add(ans[i - (p2 - lsize) + 1], px[i]);
  }
}
 
int main() {
  int po = (MOD - 1) / (1 << 21);
  ROOT = 1;
  for (int i = 0; i < po; i++) {
    ROOT = mul(ROOT, G);
  }
  rpws[0] = 1;
  for (int i = 1; i <= 1 << F; i++) {
    rpws[i] = mul(ROOT, rpws[i - 1]);
  }
  INV[1] = 1;
  for (int i = 2; i < N; i++) {
    INV[i] = mul(MOD - MOD / i, INV[MOD % i]);
  }
  FACT[0] = INVFACT[0] = 1;
  for (int i = 1; i < N; i++) {
    FACT[i] = mul(i, FACT[i - 1]);
    INVFACT[i] = mul(INV[i], INVFACT[i - 1]);
  }
  scanf("%d", &n);
  for (int i = 0; i + 1 < n; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v;
    --u;
    edges[v].push_back(u);
    edges[u].push_back(v);
  }
  dfs(0, -1);
  for (int i = 0; i <= n; i++) f[i] = mul(f[i], FACT[i]);
  go(0, n + 1);
  for (int i = 1; i <= n; i++) {
    printf("%d\n", mul(ans[i], INVFACT[i]));
  }
}

Submission Info

Submission Time
Task F - Many Easy Problems
User Alaref
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 3956 Byte
Status AC
Exec Time 1034 ms
Memory 77824 KB

Compile Error

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

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 969 ms 64888 KB
doublestar1 AC 971 ms 64888 KB
doublestar2 AC 970 ms 64888 KB
doublestar3 AC 973 ms 64888 KB
doublestar4 AC 971 ms 64888 KB
example0 AC 84 ms 51840 KB
example1 AC 84 ms 51840 KB
example2 AC 84 ms 51840 KB
line0 AC 998 ms 77696 KB
line1 AC 1012 ms 77696 KB
line2 AC 1006 ms 77824 KB
line3 AC 1009 ms 77696 KB
line4 AC 998 ms 77696 KB
maxrand0 AC 995 ms 64768 KB
maxrand1 AC 1006 ms 64768 KB
maxrand10 AC 1020 ms 64768 KB
maxrand11 AC 1027 ms 64768 KB
maxrand12 AC 1019 ms 64768 KB
maxrand13 AC 1014 ms 64768 KB
maxrand14 AC 1034 ms 64768 KB
maxrand15 AC 1008 ms 64896 KB
maxrand16 AC 1011 ms 64768 KB
maxrand17 AC 1021 ms 64768 KB
maxrand18 AC 1013 ms 64768 KB
maxrand19 AC 1001 ms 64768 KB
maxrand2 AC 1012 ms 64768 KB
maxrand3 AC 1011 ms 64768 KB
maxrand4 AC 1002 ms 64768 KB
maxrand5 AC 1008 ms 64768 KB
maxrand6 AC 1008 ms 64768 KB
maxrand7 AC 1013 ms 64768 KB
maxrand8 AC 1010 ms 64768 KB
maxrand9 AC 1009 ms 64768 KB
rand0 AC 93 ms 51968 KB
rand1 AC 85 ms 51840 KB
rand2 AC 90 ms 51968 KB
rand3 AC 92 ms 51968 KB
rand4 AC 86 ms 51840 KB
rand5 AC 92 ms 52096 KB
rand6 AC 88 ms 51968 KB
rand7 AC 92 ms 52096 KB
rand8 AC 85 ms 51840 KB
rand9 AC 87 ms 51968 KB
star0 AC 979 ms 65268 KB
star1 AC 958 ms 65268 KB
star2 AC 964 ms 65268 KB
star3 AC 965 ms 65268 KB
star4 AC 965 ms 65268 KB