QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688309 | #9530. A Game On Tree | doyo | Compile Error | / | / | C++20 | 1.9kb | 2024-10-30 03:04:58 | 2024-10-30 03:04:58 |
Judging History
This is the latest submission verdict.
- [2024-10-30 03:04:58]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-10-30 03:04:58]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>=k;--i)
#define int long long
const int N = 1e5 + 111;
const int Mod = 998244353;
vector<int> e[N];
int ans;
int f[N],fl[N],fll[N],h[N],tmp[N];
int totsize[N];
int size[N];
int ksm(int x,int y){
int ans = 1;
while(y){
if(y&1) ans = ans * x % Mod;
y>>=1,x=x*x%Mod;
}
return ans;
}
int inv(int x){return ksm(x,Mod-2);}
void get_size(int x,int fa){
totsize[x] = 1;
for(auto nxt:e[x])if(nxt!=fa){
get_size(nxt,x);
totsize[x] += totsize[nxt];
}
}
void dfs(int x,int fa){
size[x] = 1;
f[x] = 1;
for(auto nxt:e[x])if(nxt!=fa){
dfs(nxt,x);
int g = (f[nxt] + size[nxt]*2);
int gl = fl[nxt] + f[nxt];
int gll = fll[nxt] + 2*fl[nxt] + f[nxt];
//和其它子树跨根贡献
ans += g * fll[x] + f[x] * gll + 2 * fl[x] * gl;
ans %= Mod;
//自己子树内一条到根x,一条不到根x的贡献
//自己内部那一条到x的可以连出去
h[x] += (tmp[nxt] + h[nxt])%Mod * (totsize[x]-size[nxt])%Mod,h[x] %= Mod;
f[x] += g;
f[x] += 2 * ((size[x]-1) * size[nxt]);//要求必须有一个在nxt中
f[x] %= Mod;
fl[x] += gl,fl[x] %= Mod;
fll[x] += gll,fll[x] %= Mod;
tmp[x] += gll * 2 * (totsize[x]-size[nxt]);
tmp[x] %= Mod;
size[x] += size[nxt];
}
ans += h[x];
h[x] %= Mod;
}
void sol(){
int n;
cin>>n;
FOR(i,1,n-1){
int x,y;
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
ans = 0;
get_size(1,0);
dfs(1,0);
int iv = inv(n*(n-1)/2%Mod);
cout<<ans*iv%Mod*iv%Mod<<'\n';
FOR(i,1,n) e[i].clear();
FOR(i,1,n) f[i] = 0,fl[i] = 0,fll[i] = 0,h[i] = 0,tmp[i] = 0;
}
signed main(){
// freopen("1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
sol();
}
// cout<<endl;
// cout<<918384806ll*100%Mod;
return 0;
}
详细
answer.code: In function ‘void dfs(long long int, long long int)’: answer.code:31:9: error: reference to ‘size’ is ambiguous 31 | size[x] = 1; | ^~~~ In file included from /usr/include/c++/13/string:53, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from answer.code:1: /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:35:35: error: reference to ‘size’ is ambiguous 35 | int g = (f[nxt] + size[nxt]*2); | ^~~~ /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:43:63: error: reference to ‘size’ is ambiguous 43 | h[x] += (tmp[nxt] + h[nxt])%Mod * (totsize[x]-size[nxt])%Mod,h[x] %= Mod; | ^~~~ /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:45:31: error: reference to ‘size’ is ambiguous 45 | f[x] += 2 * ((size[x]-1) * size[nxt]);//要求必须有一个在nxt中 | ^~~~ /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:45:44: error: reference to ‘size’ is ambiguous 45 | f[x] += 2 * ((size[x]-1) * size[nxt]);//要求必须有一个在nxt中 | ^~~~ /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:49:49: error: reference to ‘size’ is ambiguous 49 | tmp[x] += gll * 2 * (totsize[x]-size[nxt]); | ^~~~ /usr/include/c++/13/bits/range_access.h:274:5: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])’ 274 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/13/bits/range_access.h:264:5: note: ‘template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)’ 264 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ answer.code:12:5: note: ‘long long int size [100111]’ 12 | int size[N]; | ^~~~ answer.code:51:17: error: reference to ‘size’ is ambiguous 51 | size[x] += ...