QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#302875 | #6225. 生成树 | luyiming123 | 100 ✓ | 106ms | 38524kb | C++14 | 2.2kb | 2024-01-11 14:32:45 | 2024-01-11 14:32:45 |
Judging History
answer
# include <bits/stdc++.h>
# define pii pair<int, int>
# define pii64 pair<i64, i64>
# define mp make_pair
using namespace std;
using i64 = long long;
const i64 mod = 998244353;
void Add(i64 &x, i64 y) { x = (x + y) % mod; if(x < 0) x += mod; return; }
void Mul(i64 &x, i64 y) { x = x * y % mod; return; }
const int N = 2e5 + 5;
int n, m;
map <int, pii64> g[N]; // first 联通 second 不连通
i64 prod = 1ll;
bool del[N];
void Build(void)
{
queue <int> Q;
for(int i = 1; i <= n; i++)
{
if((int)g[i].size() <= 2) Q.push(i);
}
while(!Q.empty())
{
int x = Q.front(); Q.pop();
if(del[x]) continue; del[x] = 1;
// printf("build : x = %d, deg = %d\n", x, (int)g[x].size());
if((int)g[x].size() == 1)
{
int v = g[x].begin() -> first;
Mul(prod, g[x].begin() -> second.first);
g[v].erase(x);
g[x].clear();
if(!del[v] && (int)g[v].size() <= 2) Q.push(v);
}
else if((int)g[x].size() == 2)
{
auto [y, z] = mp(g[x].begin() -> first, g[x].rbegin() -> first);
auto [f1, g1] = g[x].begin() -> second;
auto [f2, g2] = g[x].rbegin() -> second;
i64 nf = f1 * f2 % mod, ng = ((f1 * g2 % mod) + (f2 * g1 % mod)) % mod;
if(g[y].find(z) == g[y].end()) // 没有 (y,z) 这条边
{
g[y][z] = g[z][y] = {nf, ng};
}
else
{
auto [fp, gp] = g[y][z];
g[y][z] = g[z][y] = {((nf * gp % mod) + (ng * fp % mod)) % mod, ng * gp % mod};
}
g[y].erase(x), g[z].erase(x);
g[x].clear();
if(!del[y] && (int)g[y].size() <= 2) Q.push(y);
if(!del[z] && (int)g[z].size() <= 2) Q.push(z);
}
}
return;
}
int main(void)
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++)
{
int u, v; scanf("%d%d", &u, &v);
if(g[u].find(v) == g[u].end()) g[u][v] = g[v][u] = {1, 1};
else g[u][v].first++, g[v][u].first++;
}
Build();
printf("%lld\n", prod);
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 13408kb
input:
1828 1828 277 1778 1778 1650 1650 1169 1778 1812 1169 1041 1650 662 662 1187 662 939 1041 224 224 1098 1169 497 1169 1443 224 1356 1169 719 662 781 1169 818 1041 514 1778 986 939 1721 818 1102 1098 1376 719 1028 818 1084 1812 79 1187 722 719 67 79 1816 1721 695 514 1458 781 696 79 656 224 159 1169 6...
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 3ms
memory: 13400kb
input:
1816 1816 123 240 123 1242 123 1055 240 521 1242 927 521 590 1055 1257 240 514 927 848 1257 603 590 1631 848 1419 1419 1502 603 1761 514 447 1502 609 603 313 313 1322 1631 1482 447 1361 609 1375 447 1624 1624 845 1322 9 1361 1290 1375 737 1624 1813 1290 1752 1290 586 586 933 933 1223 9 1144 1144 17 ...
output:
111
result:
ok single line: '111'
Subtask #2:
score: 10
Accepted
Test #3:
score: 10
Accepted
time: 19ms
memory: 19572kb
input:
48897 49999 44175 43993 44175 13021 13021 23273 13021 35214 44175 43686 23273 25433 25433 46383 43686 45608 13021 26466 46383 13484 23273 28961 43686 21379 25433 46792 45608 16454 44175 3160 13484 16479 46792 39917 3160 11777 39917 30437 26466 19880 39917 29973 43686 43378 26466 40225 23273 38230 30...
output:
778245294
result:
ok single line: '778245294'
Test #4:
score: 0
Accepted
time: 21ms
memory: 19856kb
input:
46495 49999 18809 25060 18809 20105 25060 14021 14021 11908 20105 25840 20105 45172 11908 2540 45172 43458 25060 42642 14021 30673 25060 11344 11344 31485 20105 38798 20105 1297 11908 23 23 8876 14021 16485 43458 37234 42642 15882 31485 34755 25060 24921 25060 4755 30673 3332 38798 42105 24921 34288...
output:
246777581
result:
ok single line: '246777581'
Subtask #3:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 52ms
memory: 26300kb
input:
96912 99999 71789 3940 71789 21169 21169 50408 50408 68720 68720 67449 50408 69195 69195 64168 64168 70336 69195 81723 3940 91136 21169 75782 50408 36767 71789 77653 50408 30673 30673 79224 70336 4586 77653 32309 91136 57060 36767 3517 71789 16769 75782 11348 68720 46490 64168 15995 36767 51887 5040...
output:
373712628
result:
ok single line: '373712628'
Test #6:
score: 0
Accepted
time: 42ms
memory: 26036kb
input:
93838 99999 70859 84560 84560 47786 70859 28659 47786 68306 84560 30646 68306 74308 47786 17627 28659 23677 68306 13344 30646 41537 74308 81822 13344 68192 41537 78973 68192 39506 13344 39886 78973 81944 81944 77078 81944 81305 81305 78681 39886 48824 78681 31993 39506 54883 39886 49425 49425 45444 ...
output:
839730642
result:
ok single line: '839730642'
Test #7:
score: 0
Accepted
time: 49ms
memory: 25744kb
input:
93217 99999 39897 48691 48691 70455 39897 66817 39897 25247 66817 34625 34625 59442 34625 82125 48691 66391 34625 70534 82125 27147 25247 28264 34625 59838 59442 69379 27147 68103 69379 22810 66391 15567 59838 15685 59838 71678 15567 28010 59838 7600 68103 69439 28010 15816 15685 39777 28010 44976 1...
output:
70137593
result:
ok single line: '70137593'
Subtask #4:
score: 10
Accepted
Test #8:
score: 10
Accepted
time: 48ms
memory: 25920kb
input:
92616 99999 70768 12420 70768 67024 70768 37650 67024 14933 12420 81054 81054 6944 70768 9552 14933 31629 70768 51744 81054 62067 31629 49539 51744 47773 9552 19607 81054 89603 6944 2797 81054 78691 70768 39322 37650 16268 31629 34316 78691 18322 70768 46861 70768 36460 9552 42042 51744 53292 53292 ...
output:
810112214
result:
ok single line: '810112214'
Test #9:
score: 0
Accepted
time: 47ms
memory: 26032kb
input:
94017 99999 24807 46668 24807 81260 81260 28843 24807 339 24807 85051 339 89974 85051 6774 89974 54730 6774 69479 85051 51263 85051 85168 85168 1149 1149 41024 54730 70391 6774 29667 29667 43389 70391 50356 70391 50688 29667 17145 41024 92883 92883 11499 92883 48754 92883 80483 11499 3362 92883 7241...
output:
73515925
result:
ok single line: '73515925'
Subtask #5:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 53ms
memory: 26032kb
input:
91653 99999 1786 58358 1786 87672 1786 62883 1786 56997 56997 79414 87672 56317 56997 30068 58358 43013 1786 25272 56317 11600 11600 57554 25272 37668 87672 30501 79414 1591 1591 74 30501 74650 57554 83362 87672 25595 1786 19541 25272 68790 30068 59157 19541 56546 79414 59557 79414 32173 56317 63887...
output:
396960248
result:
ok single line: '396960248'
Test #11:
score: 0
Accepted
time: 49ms
memory: 26316kb
input:
98027 99999 68700 70996 68700 70969 70996 87037 68700 31954 31954 76351 70969 67408 87037 30644 76351 74201 70969 95791 30644 57725 67408 67730 30644 9543 95791 17418 95791 36144 57725 89464 17418 96341 89464 95071 9543 80303 80303 75802 36144 28295 28295 13083 36144 94918 28295 36606 94918 97547 80...
output:
142117900
result:
ok single line: '142117900'
Subtask #6:
score: 10
Accepted
Test #12:
score: 10
Accepted
time: 45ms
memory: 26112kb
input:
98982 100000 37308 3159 37308 76920 37308 67591 67591 78501 76920 30922 67591 90524 3159 70630 67591 82536 70630 85743 70630 73885 85743 51097 82536 81427 70630 75802 82536 11006 75802 11893 82536 94161 75802 66471 51097 19126 19126 4071 75802 90741 75802 8924 66471 9660 8924 50226 50226 13970 50226...
output:
3947657
result:
ok single line: '3947657'
Test #13:
score: 0
Accepted
time: 46ms
memory: 26052kb
input:
92717 100000 88071 40013 40013 12184 88071 68384 88071 54188 40013 68412 68384 32761 12184 18940 32761 70231 70231 23569 68384 23421 54188 37005 32761 8334 23421 61868 32761 82547 70231 52689 23421 88714 18940 92131 40013 51926 40013 9007 51926 90144 32761 88549 32761 19068 12184 43987 54188 44910 8...
output:
572124101
result:
ok single line: '572124101'
Subtask #7:
score: 10
Accepted
Test #14:
score: 10
Accepted
time: 53ms
memory: 25972kb
input:
99170 100000 58553 14320 14320 9444 58553 22219 14320 77126 22219 32808 58553 62144 58553 72681 72681 72235 77126 74762 72681 95464 72235 70259 95464 18298 70259 63380 18298 88666 72235 65028 70259 26344 70259 39126 65028 38489 70259 54083 26344 28793 63380 82981 88666 94908 54083 15140 94908 21117 ...
output:
259608098
result:
ok single line: '259608098'
Test #15:
score: 0
Accepted
time: 54ms
memory: 25584kb
input:
90629 100000 48443 18045 48443 41239 48443 51834 51834 87579 41239 35227 18045 10696 51834 86499 87579 85448 87579 37628 41239 73251 51834 9093 9093 64160 37628 69239 18045 36211 51834 84369 86499 20177 10696 77129 87579 41104 69239 85578 41104 15266 41104 24080 77129 64552 69239 16705 48443 78819 1...
output:
41632667
result:
ok single line: '41632667'
Subtask #8:
score: 10
Accepted
Test #16:
score: 10
Accepted
time: 60ms
memory: 32472kb
input:
148738 150000 97229 147704 147704 3732 3732 126210 147704 114875 97229 4145 114875 125662 126210 54609 126210 125530 125662 57240 3732 12701 114875 148509 125530 127724 57240 36638 54609 145259 125530 16588 16588 82269 148509 110113 12701 83842 145259 86308 36638 91488 110113 18954 86308 4751 18954 ...
output:
767723653
result:
ok single line: '767723653'
Test #17:
score: 0
Accepted
time: 81ms
memory: 32376kb
input:
138710 150000 53931 85292 85292 88589 53931 94589 85292 93632 94589 53422 53422 45414 93632 127800 45414 14891 45414 81869 88589 103316 85292 137429 53422 80797 53422 46149 85292 118979 53422 88912 81869 115796 115796 92856 53931 18436 45414 29822 127800 90152 90152 112533 46149 33694 45414 9543 534...
output:
376267810
result:
ok single line: '376267810'
Subtask #9:
score: 10
Accepted
Test #18:
score: 10
Accepted
time: 98ms
memory: 37964kb
input:
183279 200000 46233 1718 1718 145581 1718 99335 145581 149635 46233 44778 1718 7931 99335 14807 149635 86473 7931 50719 86473 86707 7931 138797 14807 106593 106593 28 86707 89350 106593 163773 106593 55983 89350 110272 89350 4686 4686 71136 110272 27450 110272 135707 71136 163719 110272 173695 71136...
output:
329641010
result:
ok single line: '329641010'
Test #19:
score: 0
Accepted
time: 102ms
memory: 38344kb
input:
184852 200000 143798 70410 143798 37446 37446 182726 182726 134625 143798 59164 59164 156722 70410 63575 134625 4665 37446 57518 156722 100315 4665 73340 73340 85752 59164 55342 143798 161481 63575 128530 63575 48989 85752 50513 143798 177429 59164 18324 37446 85571 70410 96780 48989 166166 48989 17...
output:
989875361
result:
ok single line: '989875361'
Subtask #10:
score: 10
Accepted
Test #20:
score: 10
Accepted
time: 106ms
memory: 38524kb
input:
193116 200000 94070 92162 92162 141789 141789 191032 94070 86611 141789 146661 141789 85085 94070 15000 85085 186121 146661 64671 85085 25108 186121 152468 15000 87079 87079 29491 64671 156412 29491 192599 64671 162723 25108 10551 87079 172614 172614 122064 162723 96437 96437 61867 156412 4076 61867...
output:
163752784
result:
ok single line: '163752784'
Test #21:
score: 0
Accepted
time: 101ms
memory: 38336kb
input:
184472 200000 97581 179943 179943 173014 173014 172243 173014 24977 97581 64985 179943 34565 24977 31528 173014 67095 67095 69368 179943 422 173014 22135 31528 151726 31528 23472 179943 122709 179943 162977 422 144423 67095 110563 31528 113571 22135 171376 113571 14174 179943 65293 69368 109387 1799...
output:
710341069
result:
ok single line: '710341069'