QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182050 | #6858. Play on Tree | masterhuang | WA | 126ms | 19752kb | C++20 | 850b | 2023-09-17 10:19:31 | 2023-09-17 10:19:31 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=2e5+5,mod=1e9+7;
int T,n;LL f[N];
vector<int>g[N];
inline int ksm(int x,int p){int s=1;for(;p;(p&1)&&(s=1ll*s*x%mod),x=1ll*x*x%mod,p>>=1);return s;}
void dfs(int x,int fa){for(int i:g[x]) if(i^fa) dfs(i,x),f[x]^=(f[i]+1);}
void dfs1(int x,int fa)
{
if(fa) f[x]^=(f[fa]^(f[x]+1)+1);
for(int i:g[x]) if(i^fa) dfs1(i,x);
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
while(T--)
{
cin>>n;int ans=0;memset(f,0,sizeof(f));
for(int i=1,u,v;i<n;i++) cin>>u>>v,g[u].push_back(v),g[v].push_back(u);
dfs(1,0);dfs1(1,0);for(int i=1;i<=n;i++) ans+=(f[i]>0);
cout<<(1ll*ans*ksm(n,mod-2)%mod)<<"\n";
for(int i=1;i<=n;i++) g[i].clear();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 126ms
memory: 19752kb
input:
3 199999 144802 35753 35753 9646 9646 148183 9646 167003 9646 199831 9646 193968 9646 182279 9646 185547 9646 106896 9646 196577 9646 150627 9646 147736 9646 180949 9646 179482 9646 196999 9646 191636 9646 184859 9646 173080 9646 155500 9646 191682 9646 169619 9646 191285 9646 106525 9646 187324 964...
output:
221491110 765128832 152099157
result:
wrong answer 1st lines differ - expected: '256641286', found: '221491110'