QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#380031 | #8570. Idola-Tree | ucup-team191# | WA | 1636ms | 56744kb | C++23 | 2.0kb | 2024-04-06 20:44:35 | 2024-04-06 20:44:35 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)
const int N=300010,MOD=998244353,M=5e7+10;
const char en='\n';
const ll LLINF=1ll<<60;
int t,n,k,ss[N],par[N];
ll sussI[N],sussO[N];
ll st[M];
vi ch[N],ch1[N];
void dfs(int i,int p=0)
{
ss[i]=1;
sussI[i]=0;
par[i]=p;
for (auto x: ch[i]) if (x!=p)
{
dfs(x,i);
ch1[i].pb(x);
ss[i]+=ss[x];
sussI[i]+=sussI[x];
}
sussI[i]+=ss[i];
}
void dfs2(int i)
{
ll su=sussO[i];
for (auto x: ch1[i]) su+=sussI[x];
for (auto x: ch1[i])
{
sussO[x]=su-sussI[x]+(n-ss[x]);
dfs2(x);
}
}
int mul(int a,int b)
{
return a*1ll*b%MOD;
}
int sq(int a)
{
return mul(a,a);
}
int cb(int a)
{
return mul(a,sq(a));
}
void ad(int&a,int b)
{
a+=b;
if (a>=MOD) a-=MOD;
}
int add(int a,int b)
{
if (a+b>=MOD) return a+b-MOD;
return a+b;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>t;
while (t--)
{
cin>>n>>k;
for (int i=1;i<=n;++i) ch[i].clear(),ch1[i].clear();
for (int i=1;i<n;++i)
{
int a,b;
cin>>a>>b;
ch[a].pb(b);
ch[b].pb(a);
}
if (n==2)
{
int an=0;
for (int i=1;i<=k;++i) ad(an,cb(sq(i)));
cout<<an<<en;
continue;
}
k-=n-1;
int ro=1;
while (ch[ro].size()==1) ++ro;
sussO[ro]=0;
dfs(ro);
dfs2(ro);
ll po=0;
for (int i=2;i<=n;++i) po+=ss[i]*1ll*sussO[i]+(n-ss[i])*1ll*sussI[i]-ss[i]*1ll*(n-ss[i]);
vl vals;
for (int i=1;i<=n;++i) if (ch[i].size()==1) vals.pb(2*sussO[i]+n-2+1);
sort(all(vals));
queue<ll> q;
po%=MOD;
int pt=1,an=cb(po),vs=vals.size();
q.push(vals[0]);
//cout<<po<<en;
for (int i=0;i<k;++i)
{
ll u=q.front();
q.pop();
po=(po+u+2*i)%MOD;
//cout<<po<<en;
ad(an,cb(po));
ll nov=u+2*(n-2);
while (pt<vs && vals[pt]<nov) q.push(vals[pt]),++pt;
q.push(nov);
}
cout<<an<<en;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9584kb
input:
2 4 3 1 4 1 3 2 1 4 4 1 4 1 3 2 1
output:
3375 25327
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
4 4 3 1 4 1 3 2 1 4 4 1 4 1 3 2 1 5 4 1 4 1 3 1 2 5 4 5 5 1 4 1 3 1 2 5 4
output:
3375 25327 54872 249984
result:
ok 4 tokens
Test #3:
score: -100
Wrong Answer
time: 1636ms
memory: 56744kb
input:
4 300000 50000000 216838 200677 44849 12926 125086 157230 26195 29767 241694 21336 21336 24457 105861 84565 184655 45583 175336 97945 286044 30927 295273 249694 109469 1566 193560 251229 176229 288707 206166 13532 166218 264413 299977 95587 159105 48116 57912 82606 97296 193689 115029 121192 68068 1...
output:
794192074 705873422 585085721 388230489
result:
wrong answer 1st words differ - expected: '968050473', found: '794192074'