QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#418302 | #8670. 独立 | Acoipp | 100 ✓ | 1321ms | 56176kb | C++14 | 6.7kb | 2024-05-23 12:24:53 | 2024-05-23 12:24:57 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#define ll long long
#define mod 998244353
#define N 3005
#define M 10005
using namespace std;
vector<ll> op[M];
ll n,m,x,y,i,jc[M],inv[M],ans,f[N][N],son[M];
namespace lglr{
ll f1[M],f2[M],tot,p1[M],p2[M];
inline ll solve(ll x){
if(x<=tot) return f2[x];
p1[0] = 1,p2[tot+1] = 1;
for(ll i=1;i<=tot;i++) p1[i]=p1[i-1]*(x-i)%mod;
for(ll i=tot;i>=1;i--) p2[i]=p2[i+1]*(x-i)%mod;
ll ans = 0;
for(ll i=1;i<=tot;i++){
if((tot-i)%2==0) ans = (ans+p1[i-1]*p2[i+1]%mod*f2[i]%mod*inv[i-1]%mod*inv[tot-i])%mod;
else ans = (ans-p1[i-1]*p2[i+1]%mod*f2[i]%mod*inv[i-1]%mod*inv[tot-i])%mod;
}
return (ans%mod+mod)%mod;
}
}
inline ll qmi(ll a,ll b,ll p){
ll res = 1%p,t = a;
while(b){
if(b&1) res=res*t%p;
t=t*t%p;
b>>=1;
}
return res;
}
namespace poly{
ll n,m,len,res[M],G,invG,invn,nn,qm[M],qm2[M],temp[M],tempa[M],tempb[M],temp2[M],c[M],TF7[M];
inline void init(ll n){
for(ll i=0;i<n;i++){
res[i]=((res[i>>1])>>1);
if(i&1) res[i]+=(n>>1);
}
for(ll i=0;i<13;i++){
ll w1=qmi(G,(mod-1)/(1<<(i+1)),mod);
ll w2=qmi(invG,(mod-1)/(1<<(i+1)),mod);
for(ll j=0,now=1,now2=1;j<(1<<i);j++,now=now*w1%mod,now2=now2*w2%mod) qm[(1<<i)+j]=now,qm2[(1<<i)+j]=now2;
}
}
inline void ntt(ll *f,ll n,ll type){
static unsigned long long tmp[M];
ll u = __builtin_ctz((1ll<<13)/n);
for(ll i=0;i<n;i++) tmp[i]=f[res[i]>>u];
for(ll i=1;i<n;i<<=1){
for(ll r=(i<<1),j=0;j<n;j+=r){
for(ll k=0;k<i;k++){
ll y = (type==1?qm[i|k]:qm2[i|k])*tmp[j|k|i]%mod;
tmp[j|k|i] = (tmp[j|k]+mod-y),tmp[j|k]+=y;
}
}
}
for(ll i=0;i<n;i++) f[i]=tmp[i]%mod;
}
inline void times(ll *a,ll *b,ll *cp,ll n,ll m,ll tim){
if(n+m<=150){
for(ll i=0;i<n+m-1;i++) c[i]=0;
for(ll i=0;i<n;i++){
for(ll j=0;j<m;j++) c[i+j]=(c[i+j]+a[i]*b[j])%mod;
}
for(ll i=0;i<n+m-1;i++) cp[i]=c[i];
return ;
}
ll nn = n,mm = m,op = 1;
while(op<=n+m) op*=2;
n=op;
if(tim==0){
for(ll i=0;i<n;i++) tempa[i]=(i>=nn?0:a[i]);
for(ll i=0;i<n;i++) tempb[i]=(i>=mm?0:b[i]);
ntt(tempa,n,1),ntt(tempb,n,1);
for(ll i=0;i<n;i++) c[i]=tempa[i]*tempb[i]%mod;
ntt(c,n,-1);
ll invn = qmi(n,mod-2,mod);
for(ll i=0;i<nn+mm;i++) cp[i]=c[i]*invn%mod;
}
else{
for(ll i=0;i<n;i++) tempa[i]=(i>=nn?0:a[i]);
ntt(tempa,n,1);
for(ll i=0;i<n;i++) c[i]=tempa[i]*b[i]%mod;
ntt(c,n,-1);
ll invn = qmi(n,mod-2,mod);
for(ll i=0;i<nn+mm;i++) cp[i]=c[i]*invn%mod;
}
}
}
ll f1[M],f2[M],f3[M],f4[M],f5[M],f6[M],f7[M],f8[M],ls=1,rs=0,now=1;
inline void dfs(ll x,ll fa){
son[x] = 1;
for(ll i=0;i<op[x].size();i++){
if(op[x][i]==fa) continue;
dfs(op[x][i],x);
}
ll p=0;
f1[0]=1;
for(ll i=1;i<=n+2;i++) f1[i]=0;
for(ll i=0;i<op[x].size();i++){
if(op[x][i]==fa) continue;
if(p==0){
for(ll j=0;j<=n+2;j++) f1[j]=f[op[x][i]][j];
son[x]+=son[op[x][i]];
p=1;
continue;
}
for(ll j=0;j<=n+2;j++) f2[j]=f[op[x][i]][j];
// cout<<"begin "<<x<<" "<<op[x][i]<<endl;
// for(ll j=0;j<=n+2;j++) cout<<f1[j]<<" ";
// cout<<endl;
// for(ll j=0;j<=n+2;j++) cout<<f2[j]<<" ";
// cout<<endl;
son[x]+=son[op[x][i]];
poly::times(f1,f2,f1,n+3,n+3,0);
// for(ll j=0;j<=n+2;j++) cout<<f1[j]<<" ";
// cout<<endl;
// cout<<"end "<<x<<" "<<op[x][i]<<endl;
}
// for(ll i=0;i<=n+2;i++) cout<<f1[i]<<" ";
// cout<<endl;
for(ll i=1;i<=n+2;i++){
f4[i]=(f4[i-1]+f1[i])%mod;
f5[i]=f4[i]*inv[i-1]%mod*inv[n+2-i]%mod;
if((n+2-i)%2==1) f5[i]=(mod-f5[i])%mod;
}
for(ll i=1;i<=n+2;i++) f6[i]=f5[i];
if((n+3)+2*(n+2)+1<=200) poly::times(f6,f8,f6,n+3,2*(n+2)+1,0);
else poly::times(f6,f7,f6,n+3,2*(n+2)+1,1);
for(ll i=1;i<=n+2;i++) f3[i]=f6[2*(n+2)-i];
ls=1,rs=0;
for(ll i=1;i<=n+2;i++){
if(m-i<=n+2) f3[i]=f4[m-i];
else{
if(ls==1&&rs==0){
now=1;
for(ll j=m-i-(n+2);j<=m-i-1;j++) now=now*j%mod;
ls=1,rs=1;
}
else now=now*(m-i-(n+2))%mod*qmi(m-(i-1)-1,mod-2,mod)%mod;
f3[i]=f3[i]*now%mod;
}
f3[i]=(f3[i]+f1[0])%mod;
}
lglr::tot = n+2;
for(ll i=1;i<=n+2;i++) lglr::f1[i]=i,lglr::f2[i]=(lglr::f2[i-1]+f3[i])%mod;
f3[0] = (qmi(m,son[x],mod)-lglr::solve(m)+mod)%mod;
for(ll i=0;i<=n+2;i++) f[x][i]=f3[i];
// cout<<"! "<<x<<endl;
// for(ll i=0;i<=n+2;i++) cout<<f3[i]<<" ";
// cout<<endl;
lglr::tot = n+2;
for(ll i=1;i<=n+2;i++) lglr::f1[i]=i,lglr::f2[i]=(lglr::f2[i-1]+f[x][i]*i)%mod;
ans = (ans+lglr::solve(m)*qmi(m,n-son[x],mod))%mod;
// cout<<"! "<<ans<<endl;
}
int main(){
// freopen("1.in","r",stdin);
poly::G=3,poly::invG=qmi(poly::G,mod-2,mod),poly::init(1<<13);
ios::sync_with_stdio(false);
cin>>n>>m;
jc[0]=1;
for(i=1;i<=5000;i++) jc[i]=jc[i-1]*i%mod;
inv[5000]=qmi(jc[5000],mod-2,mod);
for(i=5000;i>=1;i--) inv[i-1]=inv[i]*i%mod;
for(i=1;i<n;i++) cin>>x>>y,op[x].push_back(y),op[y].push_back(x);
for(ll i=0;i<=2*(n+2);i++) f7[2*(n+2)-i]=qmi((m-i+mod)%mod,mod-2,mod)%mod,f8[2*(n+2)-i]=f7[2*(n+2)-i];
ll op = 1,kl = (n+3)+2*(n+2)+1;
while(op<=kl) op*=2;
poly::ntt(f7,op,1);
dfs(1,-1);
cout<<ans<<endl;
return 0;
}
/*
2 4
1 2
50
3 2
1 2
1 3
*/
详细
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 2ms
memory: 6020kb
input:
4 1 1 2 1 3 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4268kb
input:
2 4 1 2
output:
50
result:
ok single line: '50'
Test #3:
score: 0
Accepted
time: 0ms
memory: 6156kb
input:
3 1 1 2 1 3
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6336kb
input:
5 5 1 2 1 3 1 4 4 5
output:
30873
result:
ok single line: '30873'
Test #5:
score: 0
Accepted
time: 2ms
memory: 6240kb
input:
5 5 1 2 2 3 1 4 1 5
output:
30873
result:
ok single line: '30873'
Test #6:
score: 0
Accepted
time: 2ms
memory: 8064kb
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: 2ms
memory: 6328kb
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: 0
Accepted
time: 2ms
memory: 6312kb
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: 0
Accepted
time: 0ms
memory: 6096kb
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: 0
Accepted
time: 0ms
memory: 6096kb
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: 0
Accepted
time: 2ms
memory: 8044kb
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: 0
Accepted
time: 2ms
memory: 7928kb
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: 3ms
memory: 8384kb
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: 0
Accepted
time: 33ms
memory: 14608kb
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: 0
Accepted
time: 11ms
memory: 14156kb
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: 0
Accepted
time: 27ms
memory: 16288kb
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: 0
Accepted
time: 27ms
memory: 16844kb
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: 0
Accepted
time: 43ms
memory: 18516kb
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: 0
Accepted
time: 33ms
memory: 20608kb
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: 0
Accepted
time: 36ms
memory: 16768kb
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: 0
Accepted
time: 43ms
memory: 16784kb
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: 0
Accepted
time: 16ms
memory: 12328kb
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: 5ms
memory: 8180kb
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: 0
Accepted
time: 53ms
memory: 14640kb
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: 0
Accepted
time: 16ms
memory: 12268kb
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: 0
Accepted
time: 46ms
memory: 14564kb
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: 0
Accepted
time: 63ms
memory: 18692kb
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: 0
Accepted
time: 78ms
memory: 16720kb
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: 0
Accepted
time: 62ms
memory: 18472kb
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: 0
Accepted
time: 68ms
memory: 18476kb
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: 0
Accepted
time: 62ms
memory: 16792kb
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: 0
Accepted
time: 17ms
memory: 12328kb
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: 771ms
memory: 43108kb
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: 0
Accepted
time: 987ms
memory: 47868kb
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: 0
Accepted
time: 533ms
memory: 49340kb
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: 0
Accepted
time: 577ms
memory: 51508kb
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: 0
Accepted
time: 1040ms
memory: 56176kb
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: 0
Accepted
time: 1321ms
memory: 53336kb
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: 0
Accepted
time: 1134ms
memory: 54092kb
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: 0
Accepted
time: 1138ms
memory: 53784kb
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: 0
Accepted
time: 564ms
memory: 54136kb
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: 0
Accepted
time: 1180ms
memory: 52536kb
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'