QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#705281 | #9530. A Game On Tree | ocharin# | Compile Error | / | / | C++20 | 2.0kb | 2024-11-02 22:47:20 | 2024-11-02 22:47:22 |
Judging History
This is the latest submission verdict.
- [2024-11-02 22:47:22]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-02 22:47:20]
- Submitted
answer
/*
_/ _/
_/_/ _/_/_/ _/_/_/ _/_/_/ _/ _/_/ _/_/_/
_/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/ _/_/_/ _/ _/ _/_/_/ _/ _/ _/ _/
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int qpow(int a,int b){
int ans=1;
for(;b;b>>=1){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
}
return ans;
}
void solve(){
int n;
cin>>n;
vector<vector<int>>e(n+1);
for(int i=1;i<n;++i){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
vector<int>s(n+1,0ll),sz(n+1);
int res=0;
auto dfs=[&](auto dfs,int u,int fa)->void{
sz[u]=1;v
int ans=0,sum=0;
for(auto v:e[u]){
if(v==fa) continue;
dfs(dfs,v,u);
res+=(n-sz[v])*(n-sz[v])%mod*sz[v]%mod*sz[v]%mod;
if(res>=mod) res-=mod;
int tmp=s[v]-sz[v]*sz[v]%mod+mod;
if(tmp>=mod) tmp-=mod;
res+=(n-sz[v])*(n-sz[v])%mod*tmp%mod*2%mod;
if(res>=mod) res-=mod;
ans+=sum*s[v]%mod;
if(ans>=mod) ans-=mod;
sum+=s[v];
if(sum>=mod) sum-=mod;
sz[u]+=sz[v];
s[u]+=s[v];
if(s[u]>=mod) s[u]-=mod;
}
s[u]+=sz[u]*sz[u]%mod;
if(s[u]>=mod) s[u]-=mod;
res+=2*ans%mod;
if(res>=mod) res-=mod;
};
dfs(dfs,1,0);
int inv=n*(n-1)/2%mod;
inv=inv*inv%mod;
cout<<res*qpow(inv,mod-2)%mod<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--) solve();
}
Details
answer.code: In lambda function: answer.code:38:17: error: ‘v’ was not declared in this scope 38 | sz[u]=1;v | ^ answer.code:52:13: error: ‘ans’ was not declared in this scope; did you mean ‘abs’? 52 | ans+=sum*s[v]%mod; | ^~~ | abs answer.code:52:18: error: ‘sum’ was not declared in this scope 52 | ans+=sum*s[v]%mod; | ^~~ answer.code:67:16: error: ‘ans’ was not declared in this scope; did you mean ‘abs’? 67 | res+=2*ans%mod; | ^~~ | abs