QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569550#8078. Spanning Treeliubw_#WA 29ms12196kbC++201.6kb2024-09-17 00:38:192024-09-17 00:38:19

Judging History

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

  • [2024-09-17 00:38:19]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:12196kb
  • [2024-09-17 00:38:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define max(A,B) (A>B? A:B)
#define min(A,B) (A<B? A:B)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pir(X) pair<X,X>
#define mpr(A,B) make_pair(A,B)
#define fr first
#define sc second
using namespace std;

const int mod=998244353;
int pls(int a,int b){
    if(a+b>=mod) return a+b-mod;
    if(a+b<0) return a+b+mod;
    return a+b;
}
int mul(int a,int b){
    return (ll)a*b%mod;
}
int qpow(int a,int b){
    int ret=1;
    while(b){
        if(b&1) ret=mul(ret,a);
        a=mul(a,a);
        b>>=1;
    }
    return ret;
}
int inv(int x){
    return qpow(x,mod-2);
}

const int N=1e6+10;
int n;
struct edge{
    int x,y;
}e1[N],e2[N];

struct UF_S{
    int fa[N],siz[N];
    int find(int x){
        if(x==fa[x]) return x;
        fa[x]=find(fa[x]);
        return fa[x];
    }
    bool mrg(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return 0;
        if(siz[x]<siz[y]) swap(x,y);
        fa[y]=x,siz[x]+=siz[y];
        return 1;
    }
    void init(int n){
        for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1;
    }
}s;

void fst_IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main(){
    fst_IO();
    cin>>n;
    s.init(n);
    for(int i=1;i<n;i++) cin>>e1[i].x>>e1[i].y;
    for(int i=1;i<n;i++) cin>>e2[i].x>>e2[i].y;
    int ans=1;
    for(int i=1;i<n;i++){
        int x=e1[i].x,y=e1[i].y;
        ans=mul(ans,inv(mul(s.siz[x],s.siz[y])));
        s.mrg(x,y);
    }
    cout<<ans<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9744kb

input:

3
1 2
1 3
1 2
1 3

output:

499122177

result:

ok single line: '499122177'

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 12196kb

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:

718173392

result:

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