QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#612470 | #4795. Taxi | ucup-team4153# | WA | 1241ms | 185116kb | C++20 | 1.5kb | 2024-10-05 11:27:04 | 2024-10-05 11:27:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ld=long double;using ll=long long;
using pll=pair<ll,ll>;
const int M=1e9+7,N=5e3+10,inv2=(M+1)/2,P=20;const ld eps=1e-8,pi=acos(-1);
ll poww(ll bs,ll x){ll res=1;for(;x;x>>=1,(bs*=bs)%=M)if(x&1)(res*=bs)%=M;return res;}
ll invv(ll bs){return poww(bs,M-2);}
ll C[N+1][N+1];
struct S
{
int n,m;ll res=0;
struct edg{int u,v,w;};
vector<vector<int>>es;vector<edg>E;
int spr(int x,int le)
{
int sz=1;for(auto&k:es[x])if(k^le)
{
int des=E[k].u^E[k].v^x;sz+=spr(des,k);
}
if(!le)return sz;
int sA=sz,sB=n-sz;
//cout<<le<<":"<<sA<<'/'<<sB<<":"<<E[le].w<<'\n';
for(int lc=0,rc;lc<=m*2;lc++)
{
rc=m*2-lc;
ll A=poww(sA,lc),B=poww(sB,rc);
(res+=A*B%M*C[m*2][lc]*min(lc,rc)%M*E[le].w%M)%=M;
}
return sz;
}
void ini()
{
cin>>n>>m;es.resize(n+1);E.resize(n);
for(int i=1;i<n;i++)
{
auto&[u,v,w]=E[i];cin>>u>>v>>w;
es[u].push_back(i);es[v].push_back(i);
}
spr(1,0);cout<<res<<'\n';
}
void solve()
{
}
};
void precal()
{
for(int i=0;i<=N;i++)for(int j=0;j<=i;j++)
C[i][j]=j?(C[i-1][j]+C[i-1][j-1])%M:1;
}
signed main()
{
cout<<fixed<<setprecision(12);
ios::sync_with_stdio(0);
cin.tie(0);precal();
int t=1;//cin>>t;
while(t--){S SS;SS.ini();SS.solve();}
}
/*
5 2
4 5 199
3 4 20
2 3 0
1 3 0
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1241ms
memory: 185116kb
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:
483150178
result:
wrong answer 1st numbers differ - expected: '796272069', found: '483150178'