QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344794 | #4795. Taxi | Kevin5307 | WA | 191ms | 73024kb | C++20 | 1.6kb | 2024-03-05 13:01:45 | 2024-03-05 13:01:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
using ll=long long;
using pii=pair<int,int>;
const ll mod=1e9+7;
ll ksm(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
ll C[3003][3003];
vector<pii> G[3003];
int siz[3003];
int n,m;
ll calc(int s)
{
ll p=s*ksm(n-s,mod-2);
ll q=ksm(p,mod-2);
ll ret=ksm(s*(n-s),m);
ll tot1=0,tot2=0;
ll tmp1=1,tmp2=1;
vector<ll> val1(m+1),val2(m+1);
for(int i=0;i<=m;i++)
{
tot1=(tot1+(val1[i]=C[m][i]*tmp1%mod))%mod;
tot2=(tot2+(val2[i]=C[m][i]*tmp2%mod))%mod;
tmp1=tmp1*p%mod;
tmp2=tmp2*q%mod;
}
ll ans=tot1*tot2%mod*m%mod;
vector<ll> val3=val1,val4=val2;
for(int i=1;i<=m;i++)
val1[i]=(val1[i]+val1[i-1])%mod;
for(int i=1;i<=m;i++)
val2[i]=(val2[i]+val2[i-1])%mod;
for(int i=m;i;i--)
val3[i-1]=(val3[i-1]+val3[i])%mod;
for(int i=m;i;i--)
val4[i-1]=(val4[i-1]+val4[i])%mod;
for(int i=1;i<=m;i++)
ans=(ans-val1[i-1]*val4[i]%mod+mod)%mod;
for(int i=1;i<=m;i++)
ans=(ans-val2[i-1]*val3[i]%mod+mod)%mod;
return ans*ret%mod;
}
ll ans;
void dfs(int u,int fa)
{
siz[u]=1;
for(auto [v,w]:G[u])
if(v!=fa)
{
dfs(v,u);
ans=(ans+w*calc(siz[v]))%mod;
siz[u]+=siz[v];
}
}
int main()
{
for(int i=0;i<3003;i++)
C[i][i]=C[i][0]=1;
for(int i=2;i<3003;i++)
for(int j=1;j<i;j++)
C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
cin>>n>>m;
for(int i=1;i<n;i++)
{
int u,v,l;
cin>>u>>v>>l;
G[u].pb(v,l);
G[v].pb(u,l);
}
dfs(1,0);
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 191ms
memory: 73024kb
input:
2500 2500 531 1977 7285 705 44 4544 1409 2220 8896 2175 2086 9343 1947 729 2482 1114 1832 186 2388 1775 9841 1028 2097 7734 1949 2130 1115 407 1801 352 1165 254 8847 625 844 9853 551 1980 457 1683 163 7785 864 2338 1532 1214 1578 2055 387 1525 797 2070 1976 910 248 568 1444 2434 509 7641 2100 1779 6...
output:
572289452
result:
wrong answer 1st numbers differ - expected: '796272069', found: '572289452'