QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743527#8078. Spanning TreeyhdddWA 12ms40132kbC++141.6kb2024-11-13 19:24:582024-11-13 19:24:59

Judging History

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

  • [2024-11-13 19:24:59]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:40132kb
  • [2024-11-13 19:24:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=1000010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,ans=1;
pii a[maxn],b[maxn];
int f[maxn],siz[maxn];
int fd(int x){
	if(f[x]==x)return x;
	return f[x]=fd(f[x]);
}
inline int ksm(int a,int b=mod-2){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
vector<int> id[maxn];
bool vis[maxn];
void work(){
	n=read();
	for(int i=1;i<n;i++)a[i]={read(),read()};
	for(int i=1;i<n;i++)b[i]={read(),read()};
	for(int i=1;i<n;i++)id[b[i].fi].pb(i),id[b[i].se].pb(i);
	for(int i=1;i<=n;i++)f[i]=i,siz[i]=1;
	for(int i=1;i<n;i++){
		int u=fd(a[i].fi),v=fd(a[i].se);
		if(u==v){puts("0");}
		if(id[u]>id[v])swap(id[u],id[v]);
		bool fl=0;
		for(int &j:id[u])if(!vis[j]){
			if(fd(b[j].fi)==v||fd(b[j].se)==v){
				vis[j]=1;
				fl=1;break;
			}
		}
		if(!fl){puts("0");break;}
		ans=ans*siz[u]%mod*siz[v]%mod;
		f[u]=v,siz[v]+=siz[u];
		for(int j:id[v])id[u].pb(j);
	}
	ans=ksm(ans);
	printf("%lld\n",ans);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 35084kb

input:

3
1 2
1 3
1 2
1 3

output:

499122177

result:

ok single line: '499122177'

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 40132kb

input:

100000
2183 5543
22424 59062
8387 24544
14668 74754
15788 58136
26846 99981
13646 57752
29585 62862
27383 65052
2013 13116
24490 91945
26006 61595
19000 78817
31371 67837
29311 82989
4298 20577
23212 77962
16510 85839
26010 98714
25314 96063
17206 82359
7478 76540
13890 99556
23277 64321
25684 92613...

output:

0
1

result:

wrong answer 1st lines differ - expected: '330864231', found: '0'