QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588389 | #9278. Linear Algebra Intensifies | zjy0001 | AC ✓ | 897ms | 103756kb | C++17 | 2.0kb | 2024-09-25 10:20:31 | 2024-09-25 10:20:32 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
typedef vector<int> Vec;
typedef vector<Vec> Mat;
const int N=5e5+5,Mod=998244353;
int n,m,An,ans=1;
vector<int>G[N];
vector<tuple<int,int,int>>E;
int fd[N],A[N],id[N],nxt[N],D[N];
inline int qpow(int x,int y,int z=1){
for(;y;(y>>=1)&&(x=(LL)x*x%Mod))if(y&1)z=(LL)z*x%Mod;return z;
}
inline int Det(Mat A){
const int n=A.size();int z=1;
for(int i=0;i<n;++i)
for(int j=i+1;j<n;++j){
while(A[i][i]){
const int v=A[j][i]/A[i][i];
for(int k=i;k<n;++k)
A[j][k]=(A[j][k]-1ll*v*A[i][k])%Mod;
A[i].swap(A[j]),z=-z;
}
A[i].swap(A[j]),z=-z;
}
for(int i=0;i<n;++i)z=1ll*z*A[i][i]%Mod;
return z<0?z+Mod:z;
}
inline int find(const int&x){
return x==fd[x]?x:fd[x]=find(fd[x]);
}
inline void dfs(int u,int fa){
D[u]=D[fa]+1;
int ch=0,r=0;
for(auto v:G[u])if(v!=fa){
dfs(v,u);
if(nxt[v])++ch,r=nxt[v];
}
if(ch>1||id[u]){
id[u]=1;
for(auto v:G[u])if(v!=fa&&nxt[v])
ans=(LL)ans*(D[nxt[v]]-D[u])%Mod,
E.emplace_back(u,nxt[v],qpow(D[nxt[v]]-D[u],Mod-2));
nxt[u]=u;
}
else nxt[u]=r;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m,++n;
iota(fd+1,fd+n+1,1);
for(int i=1;i<=m;++i){
int u,v;cin>>u>>v,++v;
if(find(u)!=find(v)){
G[u].emplace_back(v);
G[v].emplace_back(u);
fd[find(u)]=find(v);
}
else{
id[u]=id[v]=1;
E.emplace_back(u,v,1);
}
}
for(int i=1;i<=n;++i)if(find(i)!=find(1))return cout<<"0\n",0;
if(E.empty())return cout<<"1\n",0;
dfs(1,0);
for(int i=1;i<=n;++i)id[i+1]+=id[i];
Mat Q(id[n],Vec(id[n]));
for(auto [u,v,w]:E)
u=id[u]-1,v=id[v]-1,
(Q[u][v]-=w)%=Mod,
(Q[v][u]-=w)%=Mod,
(Q[u][u]+=w)%=Mod,
(Q[v][v]+=w)%=Mod;
Q.pop_back();
for(auto&i:Q)i.pop_back();
cout<<(LL)ans*Det(Q)%Mod<<'\n';
return 0;
}
/*
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 23200kb
input:
3 4 1 2 2 3 1 2 3 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 3ms
memory: 18988kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 5ms
memory: 21836kb
input:
1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
10
result:
ok 1 number(s): "10"
Test #4:
score: 0
Accepted
time: 4ms
memory: 18532kb
input:
2 1 1 2
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 18704kb
input:
2 2 1 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 5ms
memory: 22356kb
input:
2 3 1 1 2 2 1 2
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 5ms
memory: 22324kb
input:
12 23 10 12 6 12 3 6 3 4 5 12 10 10 10 11 9 9 8 12 4 12 1 9 4 9 2 2 10 11 5 12 8 12 9 9 1 9 6 12 10 10 2 2 3 6 3 4
output:
3072
result:
ok 1 number(s): "3072"
Test #8:
score: 0
Accepted
time: 0ms
memory: 21840kb
input:
2 10 1 2 2 2 1 1 1 1 1 2 1 1 1 2 2 2 2 2 1 2
output:
33
result:
ok 1 number(s): "33"
Test #9:
score: 0
Accepted
time: 0ms
memory: 22320kb
input:
9 20 4 6 9 9 8 9 3 3 2 8 6 8 9 9 2 6 2 8 1 1 2 4 1 2 5 9 1 3 2 7 1 3 1 6 2 3 2 8 2 6
output:
3696
result:
ok 1 number(s): "3696"
Test #10:
score: 0
Accepted
time: 0ms
memory: 21732kb
input:
109 245 6 57 29 81 21 76 21 76 36 44 53 71 29 29 43 78 1 12 26 50 3 100 8 84 30 103 1 21 61 76 19 78 37 55 78 79 15 64 18 53 40 82 28 66 14 40 30 63 53 85 64 106 1 95 87 106 14 36 8 84 30 64 40 82 9 62 29 50 68 87 48 64 63 105 1 17 15 66 26 50 1 48 50 75 52 75 10 10 74 106 9 75 65 102 91 103 12 83 6...
output:
589921054
result:
ok 1 number(s): "589921054"
Test #11:
score: 0
Accepted
time: 0ms
memory: 18924kb
input:
100 100 46 100 45 92 86 97 72 78 44 79 35 97 31 92 88 93 49 89 12 56 7 63 58 86 51 70 81 100 33 37 29 94 12 38 31 53 26 90 77 96 10 88 26 69 44 90 6 48 37 47 60 77 32 42 40 41 50 83 83 90 95 100 21 33 17 62 12 91 59 68 63 82 11 60 48 98 5 47 56 60 1 95 38 52 25 66 51 59 4 33 95 96 55 74 26 93 25 68 ...
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 21528kb
input:
122 123 4 37 48 73 21 96 68 84 43 94 11 36 38 113 40 108 65 81 10 111 6 19 80 92 37 40 40 122 60 113 2 19 29 31 26 75 33 68 27 69 51 65 17 90 88 112 56 68 46 46 83 110 25 80 14 38 101 108 16 41 64 89 19 88 76 87 26 79 51 90 107 119 7 17 71 100 17 59 14 105 15 26 22 95 113 117 22 91 19 99 57 119 42 5...
output:
123
result:
ok 1 number(s): "123"
Test #13:
score: 0
Accepted
time: 0ms
memory: 22228kb
input:
99 200 53 74 10 80 6 73 73 81 7 37 81 93 12 55 6 40 24 96 86 89 48 89 17 75 20 65 18 52 36 89 8 24 29 33 53 72 28 45 27 35 38 73 11 41 74 76 73 86 87 93 11 73 4 19 80 88 11 80 12 21 13 86 69 78 3 18 32 47 3 49 50 93 30 60 8 19 26 70 1 62 9 96 58 94 25 35 42 91 61 70 13 96 10 44 57 73 19 85 16 37 81 ...
output:
560526429
result:
ok 1 number(s): "560526429"
Test #14:
score: 0
Accepted
time: 163ms
memory: 25280kb
input:
3000 3300 203 2193 755 2277 2141 2736 1115 1127 82 1944 573 2600 1063 1949 375 1712 395 999 950 1690 52 1226 560 2924 83 1464 1504 2104 10 986 64 1331 1631 1755 573 2344 1615 1737 2414 2804 480 2113 2174 2909 666 2914 156 1588 611 1533 528 1285 1004 2763 19 80 73 1954 777 1297 2116 2117 186 847 1056...
output:
855511535
result:
ok 1 number(s): "855511535"
Test #15:
score: 0
Accepted
time: 143ms
memory: 34164kb
input:
500000 500000 106843 246711 220148 499250 169638 287414 348384 439218 464123 485715 242531 404366 304063 470177 158965 188123 11671 470956 441213 450178 229736 319036 393409 440552 204883 324026 476519 481812 444616 468853 65586 178690 234265 263137 434457 470186 391493 410684 329022 357803 139095 4...
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 19216kb
input:
500000 1 301721 361047
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 138ms
memory: 36500kb
input:
500000 500000 98619 388571 341253 371055 201469 217888 92958 138959 14275 185016 76593 118908 448437 499659 101559 211959 162147 291039 114239 445451 218665 248802 3153 359183 256945 314214 393034 477015 204725 291777 421118 494553 439455 467768 71748 416919 203928 245846 430083 470965 354933 476142...
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 144ms
memory: 33480kb
input:
500000 500000 177093 360397 302589 367660 85299 288630 199827 242302 141963 328163 135504 138139 198476 308433 228887 382116 168447 190268 5588 231484 281079 307027 195125 362060 185089 293372 22610 208438 69594 330179 146715 479740 200305 464094 307384 448176 298448 439901 116418 402473 219948 4371...
output:
1
result:
ok 1 number(s): "1"
Test #19:
score: 0
Accepted
time: 149ms
memory: 36136kb
input:
499700 500000 199312 363387 28170 45801 218790 419838 88326 324416 118422 432158 153235 242162 11579 25299 223249 486090 163817 497246 187168 389868 95567 450717 6783 57079 266046 342045 426586 484374 31227 41797 53367 462151 221528 339573 183106 374349 99554 405978 191158 417963 215600 248217 16628...
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 777ms
memory: 50920kb
input:
499700 500000 21935 291497 3024 478103 245079 313731 289382 445058 7336 28195 78312 277188 1478 444596 110770 303251 305814 488077 392299 458444 49934 365673 98804 210611 284717 482990 169781 473469 80921 280809 2832 31209 117964 355575 80469 280739 120148 145950 99614 451361 139980 305651 273769 47...
output:
780759157
result:
ok 1 number(s): "780759157"
Test #21:
score: 0
Accepted
time: 239ms
memory: 102128kb
input:
499999 500000 337206 367714 166297 312794 307170 414738 110332 372626 212936 344573 168963 205236 160790 386652 365877 467290 72766 300544 174237 422273 101731 241073 398746 416888 456126 491059 210317 263195 109345 295637 231932 408374 52853 329207 334163 388929 125157 486076 197084 206788 292973 3...
output:
500000
result:
ok 1 number(s): "500000"
Test #22:
score: 0
Accepted
time: 249ms
memory: 40604kb
input:
400025 400325 347626 347915 4781 209476 30074 115935 143154 195884 3575 344617 247862 261061 135176 255423 178268 222368 247067 286708 340084 343728 188171 281733 41990 240994 255351 374129 165903 171225 9259 185918 137286 212423 126850 376328 62992 189751 34847 36098 8890 163372 106962 373854 44874...
output:
539971491
result:
ok 1 number(s): "539971491"
Test #23:
score: 0
Accepted
time: 209ms
memory: 37012kb
input:
300109 300400 6455 97886 125279 267449 21281 149096 216607 281358 46405 175071 12597 165532 10905 37179 125605 180980 120823 167319 90076 114751 190919 266219 107082 251302 109232 140660 128428 290381 42195 272858 131018 164771 22552 238723 229759 290134 55034 182192 37207 108904 4740 23439 20378 18...
output:
882836819
result:
ok 1 number(s): "882836819"
Test #24:
score: 0
Accepted
time: 169ms
memory: 41208kb
input:
499999 500000 47849 283106 16634 475213 1354 212127 123209 162917 271573 285753 338710 487415 160493 268905 237678 347030 132405 308987 130542 314305 343555 386154 142357 300413 100571 197171 43107 62217 142052 435822 86940 157935 202074 254928 39505 184155 55872 351366 42763 363981 182118 360911 68...
output:
2
result:
ok 1 number(s): "2"
Test #25:
score: 0
Accepted
time: 358ms
memory: 45012kb
input:
490100 490400 156712 369932 385830 470289 422686 451652 211899 262956 147118 481327 122259 164629 334205 483114 163904 402960 338978 484787 283943 460768 57259 267931 75630 163562 178413 449536 357293 395320 107150 197041 82435 265012 379336 474275 389629 468275 297678 336271 101433 247320 18671 170...
output:
418567388
result:
ok 1 number(s): "418567388"
Test #26:
score: 0
Accepted
time: 275ms
memory: 42820kb
input:
450004 450304 32697 266011 425030 429101 316811 401885 31452 257565 35162 192946 30486 291145 35013 345381 345937 399617 147064 304884 234469 347087 104761 122260 73712 324726 118741 271448 29319 57779 120877 341625 234063 274395 35730 154243 25603 208972 256148 381349 155824 206927 25196 56453 1763...
output:
620981594
result:
ok 1 number(s): "620981594"
Test #27:
score: 0
Accepted
time: 309ms
memory: 43768kb
input:
490009 490309 134383 158561 156596 248554 191181 207375 39398 414704 31355 371571 240548 438664 165053 318372 10295 107721 182673 223226 159451 448204 71681 113596 172222 405158 144438 339534 101556 358403 29436 350332 32362 84576 57221 112349 108311 202303 11882 476684 484463 489184 224724 282924 2...
output:
566276003
result:
ok 1 number(s): "566276003"
Test #28:
score: 0
Accepted
time: 380ms
memory: 103756kb
input:
490298 490598 210225 404229 2951 362841 331483 485378 6529 480859 167203 226530 1488 177457 316845 346894 103830 163223 150926 194319 201991 252388 133043 370380 245639 248027 116641 417488 121251 311507 75808 241313 1348 331818 89022 181089 339919 446073 169128 200082 57271 59144 64237 424354 55042...
output:
343584604
result:
ok 1 number(s): "343584604"
Test #29:
score: 0
Accepted
time: 580ms
memory: 47860kb
input:
494866 495166 99825 232759 23420 274946 118866 338316 31631 397272 63794 348843 252078 420375 268070 449517 49092 417443 101604 162354 131228 170520 162201 369566 151474 439659 138548 402129 263855 444394 294741 440276 99438 212690 307 417110 405833 410540 299797 300068 70745 259694 287090 287906 86...
output:
23165905
result:
ok 1 number(s): "23165905"
Test #30:
score: 0
Accepted
time: 878ms
memory: 52484kb
input:
469734 470032 24842 37234 179928 432668 310523 336074 207102 290436 144971 226528 239653 437703 196160 405776 25708 266051 156570 443810 87313 314748 83805 175806 282070 381371 218911 243720 74897 80691 103233 276556 116766 172090 24668 272161 6529 98246 123656 378790 241432 446852 191128 324209 163...
output:
195465029
result:
ok 1 number(s): "195465029"
Test #31:
score: 0
Accepted
time: 593ms
memory: 48904kb
input:
469635 469935 333845 352288 199361 346371 129944 208644 61813 329773 139360 242410 253496 406352 43353 412465 130631 192408 192634 423222 130374 322955 83713 441275 270897 464813 412276 467854 412007 469177 185122 261975 111619 180110 292090 415208 36210 447557 15978 348190 58491 405604 154543 34094...
output:
760746584
result:
ok 1 number(s): "760746584"
Test #32:
score: 0
Accepted
time: 897ms
memory: 54980kb
input:
499700 500000 358992 469294 340849 470072 189441 384117 172296 337350 131713 272631 67378 370126 79109 92814 98012 268753 232750 389178 136053 489605 57409 59870 90630 101473 206752 447545 58837 344696 249290 256036 99843 216684 339015 429470 432 35563 8275 436125 122868 401278 264824 324538 310668 ...
output:
253203006
result:
ok 1 number(s): "253203006"
Test #33:
score: 0
Accepted
time: 343ms
memory: 44944kb
input:
499039 499339 159987 251448 124976 310641 106470 220204 362424 484869 340457 433213 21659 102293 273684 325859 116000 360085 42835 443988 110794 227293 175656 495481 72767 188171 110287 123811 201406 239266 34357 220978 117450 172353 215053 259162 360436 469884 110074 277892 120457 342858 141315 171...
output:
71926140
result:
ok 1 number(s): "71926140"
Extra Test:
score: 0
Extra Test Passed