Submission #903941
Source Code Expand
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
using namespace std;
#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;
namespace std{
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
out<<'('<<a.fr<<','<<a.sc<<')';
return out;
}
}
//const int INF=5e8;
typedef long long ll;
typedef pair<int, int> Pii;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
template<int mod, int primitive_root>
class NTT {
public:
int get_mod() const { return mod; }
void _ntt(vector<ll>& a, int sign) {
const int n = sz(a);
assert((n ^ (n&-n)) == 0); //n = 2^k
const int g = 3; //g is primitive root of mod
int h = (int)mod_pow(g, (mod - 1) / n, mod); // h^n = 1
if (sign == -1) h = (int)mod_inv(h, mod); //h = h^-1 % mod
//bit reverse
int i = 0;
for (int j = 1; j < n - 1; ++j) {
for (int k = n >> 1; k >(i ^= k); k >>= 1);
if (j < i) swap(a[i], a[j]);
}
for (int m = 1; m < n; m *= 2) {
const int m2 = 2 * m;
const ll base = mod_pow(h, n / m2, mod);
ll w = 1;
FOR(x, m) {
for (int s = x; s < n; s += m2) {
ll u = a[s];
ll d = a[s + m] * w % mod;
a[s] = u + d;
if (a[s] >= mod) a[s] -= mod;
a[s + m] = u - d;
if (a[s + m] < 0) a[s + m] += mod;
}
w = w * base % mod;
}
}
for (auto& x : a) if (x < 0) x += mod;
}
void ntt(vector<ll>& input) {
_ntt(input, 1);
}
void intt(vector<ll>& input) {
_ntt(input, -1);
const int n_inv = mod_inv(sz(input), mod);
for (auto& x : input) x = x * n_inv % mod;
}
// 畳み込み演算を行う
vector<ll> convolution(const vector<ll>& a, const vector<ll>& b){
int ntt_size = 1;
while (ntt_size < sz(a) + sz(b)) ntt_size *= 2;
vector<ll> _a = a, _b = b;
_a.resize(ntt_size); _b.resize(ntt_size);
ntt(_a);
ntt(_b);
FOR(i, ntt_size){
(_a[i] *= _b[i]) %= mod;
}
intt(_a);
return _a;
}
};
ll garner(vector<Pii> mr, int mod){
mr.emplace_back(mod, 0);
vector<ll> coffs(sz(mr), 1);
vector<ll> constants(sz(mr), 0);
FOR(i, sz(mr) - 1){
// coffs[i] * v + constants[i] == mr[i].second (mod mr[i].first) を解く
ll v = (mr[i].second - constants[i]) * mod_inv<ll>(coffs[i], mr[i].first) % mr[i].first;
if (v < 0) v += mr[i].first;
for (int j = i + 1; j < sz(mr); j++) {
(constants[j] += coffs[j] * v) %= mr[j].first;
(coffs[j] *= mr[i].first) %= mr[j].first;
}
}
return constants[sz(mr) - 1];
}
typedef NTT<167772161, 3> NTT_1;
typedef NTT<469762049, 3> NTT_2;
typedef NTT<1224736769, 3> NTT_3;
//任意のmodで畳み込み演算 O(n log n)
vector<ll> int32mod_convolution(vector<ll> a, vector<ll> b,int mod){
for (auto& x : a) x %= mod;
for (auto& x : b) x %= mod;
NTT_1 ntt1; NTT_2 ntt2; NTT_3 ntt3;
auto x = ntt1.convolution(a, b);
auto y = ntt2.convolution(a, b);
auto z = ntt3.convolution(a, b);
vector<ll> ret(sz(x));
vector<Pii> mr(3);
FOR(i, sz(x)){
mr[0].first = ntt1.get_mod(), mr[0].second = (int)x[i];
mr[1].first = ntt2.get_mod(), mr[1].second = (int)y[i];
mr[2].first = ntt3.get_mod(), mr[2].second = (int)z[i];
ret[i] = garner(mr, mod);
}
return ret;
}
// garnerのアルゴリズムを直書きしたversion,速い
vector<ll> fast_int32mod_convolution(vector<ll> a, vector<ll> b,int mod){
for (auto& x : a) x %= mod;
for (auto& x : b) x %= mod;
NTT_1 ntt1; NTT_2 ntt2; NTT_3 ntt3;
assert(ntt1.get_mod() < ntt2.get_mod() && ntt2.get_mod() < ntt3.get_mod());
auto x = ntt1.convolution(a, b);
auto y = ntt2.convolution(a, b);
auto z = ntt3.convolution(a, b);
// garnerのアルゴリズムを極力高速化した
const ll m1 = ntt1.get_mod(), m2 = ntt2.get_mod(), m3 = ntt3.get_mod();
const ll m1_inv_m2 = mod_inv<ll>(m1, m2);
const ll m12_inv_m3 = mod_inv<ll>(m1 * m2, m3);
const ll m12_mod = m1 * m2 % mod;
vector<ll> ret(sz(x));
FOR(i, sz(x)){
ll v1 = (y[i] - x[i]) * m1_inv_m2 % m2;
if (v1 < 0) v1 += m2;
ll v2 = (z[i] - (x[i] + m1 * v1) % m3) * m12_inv_m3 % m3;
if (v2 < 0) v2 += m3;
ll constants3 = (x[i] + m1 * v1 + m12_mod * v2) % mod;
if (constants3 < 0) constants3 += mod;
ret[i] = constants3;
}
return ret;
}
template<lint mod>
struct Int_{
unsigned x;
unsigned mpow(Int_ a,unsigned k){
Int_ res=1;
while(k){
if(k&1) res=res*a;
a=a*a;
k>>=1;
}
return res.x;
}
unsigned inverse(Int_ a){
return mpow(a,mod-2);
}
Int_(): x(0) { }
Int_(long long sig) {
int sigt=sig%mod;
if(sigt<0) sigt+=mod;
x=sigt;
}
unsigned get() const { return (unsigned)x; }
Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
Int_ &operator=(Int_ that) { x=that.x; return *this;}
Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
bool operator==(Int_ that) const { return x==that.x; }
bool operator!=(Int_ that) const { return x!=that.x; }
Int_ operator-() const { return Int_(0)-Int_(*this);}
Int_ operator+(Int_ that) const { return Int_(*this) += that; }
Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
Int_ operator/(Int_ that) const { return Int_(*this) /= that; }
};
namespace std{
template<lint mod>
ostream &operator <<(ostream& out,const Int_<mod>& a){
out<<a.get();
return out;
}
template<lint mod>
istream &operator >>(istream& in,Int_<mod>& a){
in>>a.x;
return in;
}
};
typedef Int_<924844033> Int;
//2^23より大きく,primitive rootに3を持つもの
// const int mods[] = { 1224736769, 469762049, 167772161, 595591169, 645922817, 897581057, 998244353 };
int n;
vector<int> g[200005];
int size[200005];
int coef[200005];
void dfs(int v,int p){
size[v]=1;
for(auto to:g[v]){
if(to==p) continue;
dfs(to,v);
size[v]+=size[to];
++coef[size[to]];
++coef[n-size[to]];
}
}
Int fact[200005];
Int invf[200005];
Int C(int a,int b){
if(a<b || a<0 || b<0) return 0;
return fact[a]*invf[b]*invf[a-b];
}
int main(){
cin>>n;
fact[0]=1;
REP(i,n) fact[i+1]=fact[i]*(i+1);
Int one=1;
invf[n]=one/fact[n];
for(int i=n-1;i>=0;--i) invf[i]=invf[i+1]*(i+1);
REP(i,n-1){
int a,b;scanf("%d%d",&a,&b);--a;--b;
g[a].pb(b);
g[b].pb(a);
}
dfs(0,-1);
vector<lint> x(n),y(n);
REP(i,n){
x[i]=(fact[i]*coef[i]).x;
y[i]=invf[n-1-i].x;
}
vector<lint> z = fast_int32mod_convolution(x,y,924844033);
for(int i=1;i<=n;++i){
Int res=z[n-1+i];
res*=invf[i];
res=C(n,i)*n-res;
printf("%d\n",(int)res.x);
}
return 0;
}
Submission Info
Submission Time
2016-10-01 10:35:46+0900
Task
F - Many Easy Problems
User
hogloid
Language
C++14 (GCC 5.4.1)
Score
1900
Code Size
8164 Byte
Status
AC
Exec Time
1015 ms
Memory
50636 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:287:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int a,b;scanf("%d%d",&a,&b);--a;--b;
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1900 / 1900
Status
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
889 ms
39620 KB
doublestar1
AC
880 ms
39620 KB
doublestar2
AC
884 ms
39620 KB
doublestar3
AC
892 ms
39628 KB
doublestar4
AC
887 ms
39620 KB
example0
AC
10 ms
6528 KB
example1
AC
10 ms
6528 KB
example2
AC
9 ms
6528 KB
line0
AC
1007 ms
50636 KB
line1
AC
1008 ms
50516 KB
line2
AC
1009 ms
50628 KB
line3
AC
1010 ms
50636 KB
line4
AC
1004 ms
50636 KB
maxrand0
AC
975 ms
39748 KB
maxrand1
AC
972 ms
39748 KB
maxrand10
AC
972 ms
39620 KB
maxrand11
AC
977 ms
39620 KB
maxrand12
AC
972 ms
39748 KB
maxrand13
AC
1015 ms
39620 KB
maxrand14
AC
983 ms
39748 KB
maxrand15
AC
967 ms
39748 KB
maxrand16
AC
967 ms
39620 KB
maxrand17
AC
972 ms
39748 KB
maxrand18
AC
969 ms
39748 KB
maxrand19
AC
1000 ms
39620 KB
maxrand2
AC
977 ms
39748 KB
maxrand3
AC
980 ms
39748 KB
maxrand4
AC
972 ms
39748 KB
maxrand5
AC
967 ms
39748 KB
maxrand6
AC
967 ms
39748 KB
maxrand7
AC
977 ms
39620 KB
maxrand8
AC
973 ms
39748 KB
maxrand9
AC
972 ms
39748 KB
rand0
AC
18 ms
7040 KB
rand1
AC
10 ms
6528 KB
rand2
AC
14 ms
6784 KB
rand3
AC
18 ms
7040 KB
rand4
AC
11 ms
6656 KB
rand5
AC
18 ms
7040 KB
rand6
AC
14 ms
6784 KB
rand7
AC
18 ms
7040 KB
rand8
AC
10 ms
6528 KB
rand9
AC
13 ms
6784 KB
star0
AC
876 ms
40000 KB
star1
AC
876 ms
40008 KB
star2
AC
875 ms
40120 KB
star3
AC
874 ms
40000 KB
star4
AC
876 ms
40000 KB