QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#182034 | #6858. Play on Tree | masterhuang | ML | 0ms | 0kb | C++20 | 848b | 2023-09-17 10:02:00 | 2023-09-17 10:02:00 |
answer
#include<bits/stdc++.h>
#define P pair<int,int>
#define fi first
#define se second
#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;
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
Memory Limit Exceeded
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...