QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#381622#8570. Idola-Treeucup-team1004WA 1463ms37936kbC++172.1kb2024-04-07 19:27:442024-04-07 19:27:44

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 19:27:44]
  • 评测
  • 测评结果:WA
  • 用时:1463ms
  • 内存:37936kb
  • [2024-04-07 19:27:44]
  • 提交

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]+f1[x]-f1[i]-siz[i],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(i=1;i<=n;i++) if(i^rt) tot+=(f1[i]%mod*(n-siz[i])+f2[i]%mod*siz[i])%mod;
	wh=0;for(i=1;i<=n;i++) if(i^rt&&S[i].size()==1) w[++wh]=f2[i];
	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;
		gdb(tot);
		ll x=q.front();q.pop();
		tot+=2*(x+add)+n-1;tot%=mod;
		add++;
		while(R<=wh&&w[R]<x+n-2) q.emplace(w[R]),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: 17040kb

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: 16828kb

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: 1463ms
memory: 37936kb

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:

809508167
667745402
446346265
904902108

result:

wrong answer 1st words differ - expected: '968050473', found: '809508167'