QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569563 | #8078. Spanning Tree | liubw_# | WA | 33ms | 16288kb | C++20 | 1.7kb | 2024-09-17 00:44:28 | 2024-09-17 00:44:32 |
Judging History
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;
x=s.find(x),y=s.find(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: 0ms
memory: 9752kb
input:
3 1 2 1 3 1 2 1 3
output:
499122177
result:
ok single line: '499122177'
Test #2:
score: 0
Accepted
time: 33ms
memory: 10148kb
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:
330864231
result:
ok single line: '330864231'
Test #3:
score: 0
Accepted
time: 30ms
memory: 14304kb
input:
100000 2431 82555 18148 99107 3941 5966 1071 47115 15967 53202 27778 80193 17295 91006 21981 69106 8487 92235 7229 17953 6531 81170 18678 84896 25646 98753 3087 34488 4008 80883 18556 30802 250 3839 10378 92520 27250 87378 18484 75316 12912 82770 6142 78903 18637 58366 5716 82933 25060 76764 7868 78...
output:
207623640
result:
ok single line: '207623640'
Test #4:
score: 0
Accepted
time: 29ms
memory: 10144kb
input:
100000 3677 53591 26136 80586 14460 75864 5626 70315 2145 17733 681 92982 19076 64996 1672 82873 7909 80493 1362 87683 3121 81083 1881 92956 19448 31658 26638 78109 17888 74591 31114 97492 30263 93965 15990 51796 25387 47368 26827 50839 21100 85993 8497 95004 3017 3343 12299 97797 16723 59533 19266 ...
output:
315464493
result:
ok single line: '315464493'
Test #5:
score: 0
Accepted
time: 33ms
memory: 10152kb
input:
100000 337 80784 277 63525 309 68073 50 65780 223 85983 229 99952 419 97414 210 73844 149 98533 19 92591 254 75626 413 28608 31 13397 355 9807 248 86299 177 92507 75 77718 238 94072 440 73716 34 33639 39 92470 177 76740 210 93812 460 86098 79 38556 500 4414 306 93377 341 46557 260 18020 170 70281 99...
output:
782103077
result:
ok single line: '782103077'
Test #6:
score: 0
Accepted
time: 30ms
memory: 14320kb
input:
100000 77 61768 159 75045 189 96344 27 90011 80 70404 100 10876 196 6710 83 69730 122 61478 95 34246 121 66123 76 91590 183 84813 30 22860 21 64208 197 52093 136 95550 104 74693 141 43684 76 24573 180 96323 27 63135 78 77847 110 49459 67 89691 82 98960 53 62386 94 95145 15 72896 28 92579 145 94344 9...
output:
574681591
result:
ok single line: '574681591'
Test #7:
score: 0
Accepted
time: 29ms
memory: 12260kb
input:
100000 7 93472 18 98769 12 97619 17 73647 10 16818 1 91671 7 87544 6 72485 3 92155 8 72652 13 69083 18 95717 19 96402 6 18778 9 99294 18 90017 17 79729 14 97967 11 92694 8 63979 10 97859 7 44859 2 85081 4 58827 18 98750 6 75751 11 94889 4 22678 8 84842 15 84960 5 76729 2 90310 19 55608 12 87558 16 9...
output:
45611347
result:
ok single line: '45611347'
Test #8:
score: 0
Accepted
time: 31ms
memory: 10152kb
input:
100000 7 58890 3 58280 7 27055 7 93537 1 91565 5 88595 4 84795 3 87969 5 98167 3 89215 8 68189 1 9565 2 75124 5 57314 2 80828 6 69452 7 94539 5 95670 2 69584 7 58461 2 88826 4 60983 4 64741 5 94797 5 85145 3 63668 3 29256 2 80180 3 1473 7 34495 3 25487 6 49093 4 92049 6 32240 6 60954 1 23309 2 7334 ...
output:
359179257
result:
ok single line: '359179257'
Test #9:
score: 0
Accepted
time: 33ms
memory: 16288kb
input:
100000 7 52065 5 79374 8 93846 5 98472 10 72503 4 54043 2 81067 5 25410 9 66642 4 96261 2 69048 5 53093 8 72619 5 25253 7 92182 10 85942 2 96401 10 56808 1 65642 4 94067 8 76278 5 92554 5 16028 8 95421 9 96769 9 38660 4 37431 6 89486 5 12160 5 96259 3 84728 1 51495 4 96438 6 49380 1 95929 1 27527 8 ...
output:
407203766
result:
ok single line: '407203766'
Test #10:
score: 0
Accepted
time: 32ms
memory: 10288kb
input:
100000 78 73288 63 78335 71 60255 14 89232 33 31513 96 31412 63 64415 87 60736 56 60604 9 91650 29 86482 65 90995 94 91106 15 93202 56 15471 69 40408 83 88007 42 94851 33 68754 81 58316 87 69603 1 17260 95 78585 8 39063 58 31243 20 13440 94 53628 17 88933 58 98863 65 93116 22 82543 28 86883 27 59282...
output:
517010519
result:
ok single line: '517010519'
Test #11:
score: 0
Accepted
time: 32ms
memory: 10208kb
input:
100000 442 69813 189 43985 356 86661 74 29978 381 51503 808 84079 837 91324 12 91061 238 90167 910 98749 28 45930 834 97170 636 56426 592 99796 752 67695 489 66396 688 49989 151 94252 280 5651 363 78766 223 93772 937 84602 336 78368 264 74532 701 54957 277 78254 891 97873 637 22363 582 43788 887 873...
output:
968562725
result:
ok single line: '968562725'
Test #12:
score: -100
Wrong Answer
time: 33ms
memory: 10224kb
input:
100000 31518 99113 23679 31891 224 4623 1819 48802 11333 71708 11245 92859 8309 75148 10033 89063 297 93596 18282 88408 16020 98356 27633 30998 15471 53295 8023 78199 25209 44744 27250 66553 27805 70208 31835 62514 8589 42520 10650 99871 2095 21829 21341 40322 4584 98667 25361 87279 25248 30530 2625...
output:
873358425
result:
wrong answer 1st lines differ - expected: '0', found: '873358425'