QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#381607 | #8570. Idola-Tree | ucup-team1004 | WA | 1316ms | 38152kb | C++17 | 2.3kb | 2024-04-07 19:14:51 | 2024-04-07 19:14:51 |
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=3e5+5,M=2000+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-8;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;
int n,C;vector<int> S[N];
int siz[N];ll f1[N],f2[N];
void DP1(int x,int La){
siz[x]=1;f1[x]=0;
for(int i:S[x]) if(i^La) DP1(i,x),f1[x]+=f1[i]+siz[i],siz[x]+=siz[i];
}
void DP2(int x,int La){
for(int i:S[x]) if(i^La) f2[i]=f2[x]+n-siz[i];
ll tot=0;for(int i:S[x]) if(i^La) f2[i]+=tot,tot+=f1[i]+siz[i];
reverse(all(S[x]));
tot=0;for(int i:S[x]) if(i^La) f2[i]+=tot,tot+=f1[i]+siz[i];
for(int i:S[x]) if(i^La) DP2(i,x);
}
ll w[N];int wh;
void Solve(){
int i,j;scanf("%d%d",&n,&C);
for(i=1;i<=n;i++) S[i].clear();
for(i=1;i<n;i++){
int x,y;scanf("%d%d",&x,&y);
S[x].emplace_back(y);S[y].emplace_back(x);
}
int rt=1;for(i=2;i<=n;i++) if(S[i].size()>=2) rt=i;
DP1(rt,0);f2[rt]=0;DP2(rt,0);
ll tot=0,ans=0;for(j=1;j<=n;j++) if(j^rt) tot+=(f1[j]%mod*(n-siz[j])+f2[j]%mod*siz[j])%mod;
wh=0;for(j=1;j<=n;j++) if(j^rt&&S[j].size()==1) w[++wh]=f2[j];
sort(w+1,w+wh+1);
queue<ll> q;q.emplace(w[1]);int R=2;
int add=0;
for(i=n-1;i<=C;i++){
ans+=1ll*tot*tot%mod*tot%mod;
ll x=q.front();q.pop();
tot+=2*(x+add)+n-1;tot%=mod;
add++;
while(R<=wh&&w[R]-add<x+n-2) q.emplace(w[R]-add),R++;
q.emplace(x+n-2);
}
printf("%lld\n",ans%mod);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16932kb
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: 17564kb
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: 1316ms
memory: 38152kb
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:
443226322 275615563 646410166 107910364
result:
wrong answer 1st words differ - expected: '968050473', found: '443226322'