QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548129 | #8670. 独立 | 275307894a | 100 ✓ | 1109ms | 49532kb | C++14 | 7.6kb | 2024-09-05 15:43:18 | 2024-09-05 15:43:18 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2000+5,M=N*4+5,K=1e7+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
using poly=vector<ll>;
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
ll sgn(int x){return x&1?mod-1:1;}
namespace Poly{
const int N=1<<21,g=3;
int tr[N],k,a[N],b[N];ll pw[N];
void init(int n){
for(k=2;k<=n;k<<=1);
for(int i=0;i<k;i++) tr[i]=(tr[i>>1]>>1)|(i&1?k/2:0);
pw[k/2]=1;pw[k/2+1]=mpow(g,(mod-1)/k);
for(int i=k/2+2;i<k;i++) pw[i]=pw[i-1]*pw[k/2+1]%mod;
for(int i=k/2-1;i;i--) pw[i]=pw[i<<1];
}
void ntt(int *A,int k,int flag){
static ull a[N];for(int i=0;i<k;i++) a[tr[i]]=A[i];
for(int i=2;i<=k;i<<=1){
ll *e=pw+i/2;
for(int j=0;j<k;j+=i){
for(int h=j;h<j+i/2;h++){
int x=a[h+i/2]*e[h-j]%mod;
a[h+i/2]=a[h]+mod-x;a[h]+=x;
}
}
if(i==(1<<18)){
for(int j=0;j<k;j++) a[j]%=mod;
}
}
for(int i=0;i<k;i++) A[i]=a[i]%mod;
if(flag) return;
reverse(A+1,A+k);
ll iv=mpow(k);for(int i=0;i<k;i++) A[i]=A[i]*iv%mod;
}
namespace Public{
poly operator *(const poly &A,const poly &B){
int n=A.size(),m=B.size(),lim=n+m-1;
init(lim);
copy(A.begin(),A.end(),a);fill(a+n,a+k,0);
copy(B.begin(),B.end(),b);fill(b+m,b+k,0);
ntt(a,k,1);ntt(b,k,1);
for(int i=0;i<k;i++) a[i]=1ll*a[i]*b[i]%mod;
ntt(a,k,0);
poly c(lim);copy(a,a+lim,c.begin());
return c;
}
poly& operator *=(poly &A,const poly &B){
return A=A*B;
}
poly operator *(const poly &A,const int B){
poly C=A;for(int i=0;i<C.size();i++) C[i]=1ll*C[i]*B%mod;
return C;
}
poly& operator *=(poly &A,const int &B){
return A=A*B;
}
poly operator +(const poly &A,const poly &B){
poly C(max(A.size(),B.size()));
for(int i=0;i<A.size();i++) C[i]=A[i];
for(int i=0;i<B.size();i++) C[i]=(B[i]+C[i])%mod;
return C;
}
poly& operator +=(poly &A,const poly &B){
return A=A+B;
}
poly operator -(const poly &A,const poly &B){
poly C(max(A.size(),B.size()));
for(int i=0;i<A.size();i++) C[i]=A[i];
for(int i=0;i<B.size();i++) C[i]=(C[i]+mod-B[i])%mod;
return C;
}
poly& operator -=(poly &A,const poly &B){
return A=A-B;
}
poly operator %(const poly &A,const int &B){
poly C=A;
if(C.size()>B) C.resize(B);
return C;
}
poly& operator %=(poly &A,const int B){
return A=A%B;
}
poly inve(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({(int)mpow(A[0])});
poly A0=inve(A%(n+1>>1),n+1>>1);
return A0*(poly({2})-A*A0%n)%n;
}
poly sqrt(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({1});
poly A0=sqrt(A%(n+1>>1),n+1>>1);
return (A0*A0%n+A)*inve(A0,n)%n*(mod+1>>1);
}
poly der(poly A){
poly B(A.size()-1);
for(int i=1;i<A.size();i++) B[i-1]=1ll*A[i]*i%mod;
return B;
}
poly integ(poly A){
poly B(A.size()+1);
static ll inv[N];inv[1]=1;for(int i=2;i<=A.size();i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
for(int i=0;i<A.size();i++) B[i+1]=inv[i+1]*A[i]%mod;
return B;
}
poly ln(poly A,int n=-1){
if(n==-1) n=A.size();
return integ(der(A)*inve(A,n)%n)%n;
}
poly exp(poly A,int n=-1){
if(n==-1) n=A.size();
if(n==1) return poly({1});
poly A0=exp(A%(n+1>>1),n+1>>1);
return A0*(poly({1})-ln(A0,n)+A)%n;
}
poly mpow(poly A,int n,ll k){gdb(n,k);
auto p=find_if(A.begin(),A.end(),[](ll x){return x;})-A.begin();
if(p==A.size()) return A;
poly B(A.size()-p);for(int i=p;i<A.size();i++) B[i-p]=A[i];
ll v=::mpow(B[0],k%Mod),iv=::mpow(B[0]);
for(ll &i:B) i=i*iv%mod;B=ln(B,n);
for(ll &i:B) i=k%mod*i%mod;B=exp(B,n);
for(ll &i:B) i=i*v%mod;
for(int i=n-1;~i;i--) B[i]=(i>=1ll*k*p?B[i-k*p]:0);
return B;
}
}
}using namespace Poly::Public;
int n,m;
vector<int> S[N];
ll ans;
ll dp[N][N],f[N],g[N],inv[N],frv[N],pw[N];
int siz[N],sum[N];
ll LGLR(ll *f,int len,int x){
static ll pre[N],suf[N];
pre[0]=1;for(int i=1;i<=len;i++) pre[i]=pre[i-1]*(x+mod-i)%mod;
suf[len+1]=1;for(int i=len;i;i--) suf[i]=suf[i+1]*(x+mod-i)%mod;
ll tot=0;
for(int i=1;i<=len;i++) tot+=pre[i-1]*suf[i+1]%mod*f[i]%mod*frv[i-1]%mod*sgn(len-i)%mod*frv[len-i]%mod;
return tot%mod;
}
void LGLRS(ll *f,int len,ll *dp,int k){
if(!k) return;
// for(int i=1;i<=k;i++) dp[i]=LGLR(f,len,m-i);
poly F(f+1,f+len+1);
for(int i=1;i<=len;i++) F[i-1]=F[i-1]*frv[i-1]%mod*sgn(len-i)%mod*frv[len-i]%mod;
static ll frc[N*2],inv[N*2],frv[N*2];
for(int i=frc[0]=1;i<=len+k;i++) frc[i]=frc[i-1]*(m-k-len+(i-1)+mod)%mod;
for(int i=frv[0]=1;i<=len+k;i++) inv[i]=mpow(m-k-len+(i-1)+mod),frv[i]=frv[i-1]*inv[i]%mod;
poly G(inv+1,inv+len+k);
reverse(G.begin(),G.end());
reverse(all(F));
F*=G;
for(int i=1;i<=k;i++) dp[i]=F[i+len-2]*frc[len+k-i]%mod*frv[k-i]%mod,gdb(dp[i]);
/*for(int i=1;i<=k;i++){
dp[i]=0;
for(int j=1;j<=len;j++) (dp[i]+=F[j-1]*inv[len+k-i-j+1])%=mod;
dp[i]=dp[i]*frc[len+k-i]%mod*frv[k-i]%mod;
gdb(dp[i],f[1],f[2],len,LGLR(f,len,m-i));
}*/
}
void dfs(int x,int La){
for(int i:S[x]) if(i^La) dfs(i,x);
siz[x]=sum[x]=1;dp[x][0]=1;
for(int i:S[x]) if(i^La){
copy(dp[x],dp[x]+siz[x]+1,f);
copy(dp[i],dp[i]+siz[i]+1,g);
for(int j=siz[x]+1;j<=siz[x]+siz[i];j++) f[j]=LGLR(f,siz[x],j);
for(int j=siz[i]+1;j<=siz[x]+siz[i];j++) g[j]=LGLR(g,siz[i],j);
fill(dp[x],dp[x]+siz[x]+1,0);
poly F(f,f+siz[x]+siz[i]+1),G(g,g+siz[x]+siz[i]+1);
F*=G;
for(int j=0;j<=siz[x]+siz[i];j++) dp[x][j]=F[j];
// for(int j=0;j<=siz[x]+siz[i];j++) for(int h=0;j+h<=siz[x]+siz[i];h++) (dp[x][j+h]+=f[j]*g[h])%=mod;
siz[x]+=siz[i];
if(siz[x]>m) fill(dp[x]+m+1,dp[x]+siz[x]+1,0),siz[x]=m;
sum[x]+=sum[i];
}
copy(dp[x],dp[x]+siz[x]+1,f);
for(int i=1;i<=siz[x];i++) (f[i]+=f[i-1])%=mod;
int k=siz[x]+2;
while(k>m) dp[x][k]=0,k--;
while(k&&m-k<=siz[x]) dp[x][k]=f[m-k],k--;
LGLRS(f,siz[x],dp[x],k);
// for(int i=1;i<=siz[x]+2;i++) dp[x][i]=(i>m?0:(i==m?f[0]:LGLR(f,siz[x],m-i)));
copy(dp[x]+1,dp[x]+siz[x]+2,f+1);
for(int i=2;i<=siz[x]+1;i++) (f[i]+=f[i-1])%=mod;
dp[x][0]=(pw[sum[x]]+mod-LGLR(f,siz[x]+1,m))%mod;
copy(dp[x],dp[x]+siz[x]+3,f);
for(int i=0;i<=siz[x]+2;i++) (f[i]*=i)%=mod;
for(int i=1;i<=siz[x]+2;i++) (f[i]+=f[i-1])%=mod;
ans+=LGLR(f,siz[x]+2,m)*pw[n-sum[x]]%mod;
}
void Solve(){
scanf("%d%d",&n,&m);
inv[1]=1;for(int i=2;i<=n+2;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
for(int i=frv[0]=1;i<=n+2;i++) frv[i]=frv[i-1]*inv[i]%mod;
for(int i=pw[0]=1;i<=n;i++) pw[i]=pw[i-1]*m%mod;
for(int i=1;i<n;i++){
int x,y;scanf("%d%d",&x,&y);
S[x].push_back(y);S[y].push_back(x);
}
dfs(1,0);
printf("%lld\n",ans%mod);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 0ms
memory: 16476kb
input:
4 1 1 2 1 3 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 11
Accepted
time: 2ms
memory: 16180kb
input:
2 4 1 2
output:
50
result:
ok single line: '50'
Test #3:
score: 11
Accepted
time: 0ms
memory: 16300kb
input:
3 1 1 2 1 3
output:
2
result:
ok single line: '2'
Test #4:
score: 11
Accepted
time: 0ms
memory: 16264kb
input:
5 5 1 2 1 3 1 4 4 5
output:
30873
result:
ok single line: '30873'
Test #5:
score: 11
Accepted
time: 1ms
memory: 16488kb
input:
5 5 1 2 2 3 1 4 1 5
output:
30873
result:
ok single line: '30873'
Test #6:
score: 11
Accepted
time: 0ms
memory: 16296kb
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: 1ms
memory: 16388kb
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: 1ms
memory: 16392kb
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: 0ms
memory: 18420kb
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: 16496kb
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: 2ms
memory: 16384kb
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: 0ms
memory: 16316kb
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: 2ms
memory: 28812kb
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: 8ms
memory: 24640kb
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: 0ms
memory: 20604kb
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: 5ms
memory: 22784kb
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: 54ms
memory: 23456kb
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: 12ms
memory: 24932kb
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: 20ms
memory: 24568kb
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: 20ms
memory: 24524kb
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: 20ms
memory: 24660kb
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: 12ms
memory: 21004kb
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: 3ms
memory: 16892kb
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: 4ms
memory: 24704kb
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: 4ms
memory: 20568kb
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: 3ms
memory: 22900kb
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: 65ms
memory: 25376kb
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: 18ms
memory: 24680kb
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: 23ms
memory: 24756kb
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: 22ms
memory: 25012kb
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: 26ms
memory: 25032kb
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: 8ms
memory: 20972kb
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: 42ms
memory: 39520kb
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: 54ms
memory: 43680kb
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: 39ms
memory: 47464kb
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: 50ms
memory: 49532kb
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: 1109ms
memory: 47896kb
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: 233ms
memory: 45640kb
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: 431ms
memory: 47592kb
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: 418ms
memory: 47752kb
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: 147ms
memory: 46076kb
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: 586ms
memory: 46192kb
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'