QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182038#6858. Play on TreemasterhuangWA 115ms19024kbC++20847b2023-09-17 10:04:032023-09-17 10:04:03

Judging History

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

  • [2023-09-17 10:04:03]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:19024kb
  • [2023-09-17 10:04:03]
  • 提交

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,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;i<=n;i++) g[i].clear();
		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";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 115ms
memory: 19024kb

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'