QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375144 | #7125. Bipartite graph coloring | I_Love_Sonechka# | WA | 125ms | 3848kb | C++14 | 1.9kb | 2024-04-02 22:02:31 | 2024-04-02 22:02:33 |
Judging History
answer
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
// c++ short types
#define Int long long
#define vt vector
const int mod = 1e9 + 7;
void add(int &a, int b) {
a += b;
if(a >= mod) {
a -= mod;
}
if(a < 0) {
a += mod;
}
}
int mul(int a, int b) {
return a * 1ll * b % mod;
}
void solver() {
int n, m; cin >> n >> m;
vt<vt<pair<int, vt<int>>>> g(n);
for(int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
vt<int> v(4);
for(auto &x: v) {
cin >> x;
}
g[--a].push_back({--b, v});
g[b].push_back({a, v});
swap(g[b].back().second[1], g[b].back().second[2]);
}
for(int i = 0; i < n; ++i) {
vt<vt<int>> data(n, vt<int>(4, 1));
vt<int> used(n, 0);
for(auto [to, v]: g[i]) {
for(int j = 0; j < 4; ++j) {
data[to][j] = mul(data[to][j], v[j]);
}
used[to] = 1;
}
g[i].clear();
for(int j = 0; j < n; ++j) if(used[j]) {
g[i].push_back({j, data[j]});
}
}
vt<vt<int>> part(2);
vt<int> cl(n, -1);
auto Dfs = [&](auto self, int e, int c) -> void {
if(cl[e] != -1) {
return ;
}
part[c].push_back(e);
cl[e] = c;
for(auto [to, v]: g[e]) {
self(self, to, !c);
}
};
for(int i = 0; i < n; ++i) {
Dfs(Dfs, i, 0);
}
if(part[0].size() < part[1].size()) {
swap(part[0], part[1]);
}
vt<int> ids(n);
for(int i = 0; i < part[1].size(); ++i) {
ids[part[1][i]] = i;
}
assert(m);
int res = 0;
for(int mask = 0; mask < (1<<part[1].size()); ++mask) {
int local = 1;
for(int i: part[0]) if(!g[i].empty()) {
vt<int> val(2, 1);
for(int j = 0; j < 2; ++j) {
for(auto [to, v]: g[i]) {
val[j] = mul(val[j], v[j*2+((mask>>ids[to])&1)]);
}
}
add(val[0], val[1]);
local = mul(local, val[0]);
}
add(res, local);
}
cout << res << "\n";
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int tt = 1;
for(int t = 0; t < tt; ++t) {
solver();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
2 1 1 2 1 2 3 4
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 2 1 2 1 0 0 1 2 3 1 0 0 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
6 8 4 2 515760416 192548286 750928404 630204195 4 1 96990010 930195875 743856200 974291870 2 3 916367011 683998013 106243265 629858251 3 1 488938 818633505 75427039 856431926 6 1 825040499 416616900 901278683 182586700 5 1 956237108 946175708 713459401 187609111 2 6 571450128 953143810 29614163 2898...
output:
875018157
result:
ok 1 number(s): "875018157"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
6 8 5 4 305165805 646361987 939715065 664871380 4 3 785203094 816716202 499298225 715547409 6 4 21032511 213990458 517271589 911788963 4 1 856872317 228562198 262244241 420955406 2 3 920999727 404400532 950309690 787921555 2 5 674490115 370205336 616957260 748567422 6 2 755981187 255385302 207167898...
output:
5971946
result:
ok 1 number(s): "5971946"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
6 9 6 1 418208264 741979129 681511060 493901728 6 2 248271873 546312028 970863761 534805934 2 5 427475096 198640833 602284601 272430568 6 3 783902954 77317710 101285668 17756084 1 4 586878280 466509949 201566118 654650422 3 4 233744606 506757237 817313103 107975060 3 5 165134408 6989766 63315779 256...
output:
703729439
result:
ok 1 number(s): "703729439"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
6 9 5 1 706774211 924534308 589164823 361671636 5 4 372327319 804478099 872830313 114583629 2 5 93687806 791916995 910439723 678545568 4 6 570150681 811253886 8953020 139054345 1 3 253787534 836583204 670814630 894452165 6 1 868581480 594133634 887407621 825172577 2 3 418352400 344434385 788366727 9...
output:
87610420
result:
ok 1 number(s): "87610420"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
6 8 4 1 885410873 827933924 400286385 326647786 2 1 964940469 434807988 691543794 349379446 3 2 482738448 98935085 676727631 126177315 3 4 131055157 942494206 44034212 82366116 2 5 545313897 989845745 65242981 825264483 4 5 271474285 158599876 737516256 652780715 2 6 383654871 972931148 412702079 38...
output:
163580590
result:
ok 1 number(s): "163580590"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
6 8 4 1 264750846 281747625 294105754 361314971 3 2 63218968 616295607 815582040 164263914 4 2 513775021 628927531 87755953 481736955 4 6 618842315 983826680 230851415 983326086 1 3 936240416 641192889 114273989 62003117 3 5 284694584 877596797 641014116 845142805 4 5 789524294 938736152 590255813 6...
output:
720504149
result:
ok 1 number(s): "720504149"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
6 8 4 2 422752456 145626742 114296194 732418644 6 1 751432052 502815935 644652993 905519455 4 1 544811593 158919976 130188057 58634957 6 3 475225693 320126446 344039689 547849566 5 4 737232351 923943814 163304996 962305265 3 4 76576520 301626425 249544683 406101114 2 6 605459133 609573864 399213328 ...
output:
491597152
result:
ok 1 number(s): "491597152"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
6 9 3 2 934666926 802012881 367489308 316445613 5 1 122047195 648415328 112100303 212356048 2 1 800007846 985152470 880252649 385943962 6 4 903868644 9806149 335345672 854443640 6 5 658616992 496745392 367939509 558691842 4 1 513717631 164977587 684091348 652493447 3 5 209886001 620583930 467232152 ...
output:
471008094
result:
ok 1 number(s): "471008094"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
6 5 4 2 243489617 152623672 223232872 353164280 4 3 184215521 826397603 909666153 537985178 4 1 497166452 995184054 97624337 578428630 6 4 792058962 766261423 58712590 743742325 5 4 385807318 26659 989089758 866818648
output:
935037561
result:
ok 1 number(s): "935037561"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
6 9 5 4 945625861 943388321 394200047 468624240 5 1 731172419 444841726 920262095 369407278 4 3 517673333 830349394 691903872 453816015 2 4 57646284 459936602 930725773 527177346 6 3 120814656 234090738 576332839 851429476 1 3 895839928 189310178 351591531 588933013 2 6 451702052 695901587 702547605...
output:
122089738
result:
ok 1 number(s): "122089738"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3832kb
input:
20 40 7 8 840030456 267142214 720699097 233044666 18 19 21761860 269682854 723421052 831077722 1 10 196589931 365240305 720999405 282385980 4 18 784632030 562488476 211811449 649459019 3 12 730692915 861841504 638807987 939178684 18 2 573499551 826188261 293967465 253612053 11 12 129164929 939633168...
output:
200090048
result:
ok 1 number(s): "200090048"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
20 40 17 15 195724193 56901517 941729941 580807288 8 3 982397451 97700235 32434955 517996747 11 7 194054801 812792709 530388774 300233720 5 4 787033907 152289025 235744531 425716147 3 18 917320618 599720803 309467137 133394481 14 9 200540409 164277404 639666236 384255633 16 15 995516433 826584272 23...
output:
396581381
result:
ok 1 number(s): "396581381"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
20 40 14 8 83767905 737318645 91040849 84995155 12 6 442942129 279045381 956074237 534227628 17 15 797365272 369374211 203837579 435597932 10 1 821143068 516557750 792193933 794749250 16 20 171632195 598924348 996019630 366808761 12 9 436949510 766053968 394109342 766020417 13 15 603716629 917162422...
output:
836678534
result:
ok 1 number(s): "836678534"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
20 40 10 9 284922726 630011247 716133061 534761036 5 2 432104418 249978128 216640948 79086792 5 15 35818519 301483414 991017566 605305147 13 10 923396233 881312311 720962099 642362674 5 1 956383866 504019361 605237766 203580425 1 3 143530813 767304837 631406738 820049336 13 5 349904223 163371536 595...
output:
60270589
result:
ok 1 number(s): "60270589"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
20 40 14 13 69868435 495823586 346526817 294559661 12 20 981728925 631015322 906926073 157269794 13 5 771457766 374253069 254847213 106659501 1 13 676760052 684103177 882242255 250181458 11 17 74405678 793222274 685628898 812938964 13 19 62635455 825477751 595750937 859800774 3 13 192392784 55781927...
output:
676556179
result:
ok 1 number(s): "676556179"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
20 40 12 10 370504482 690974439 85720319 614129219 17 2 749160755 538401736 853788970 584881243 19 5 899461216 773700546 939213074 892949529 3 10 879254542 878736721 450711533 279382781 3 5 882978353 982983515 878062120 81206420 15 11 204518113 903063660 724463809 247928904 17 15 68922609 283353263 ...
output:
968074883
result:
ok 1 number(s): "968074883"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
20 40 17 2 434802591 714116280 856746614 811523500 10 1 350096077 527083208 99492669 187419804 5 17 19012466 867109758 564467989 233058284 1 2 896297103 262438295 366443859 641608136 13 10 979525019 678869760 549981346 828195107 16 10 20171426 782243732 947508308 751803634 15 12 675928943 465879838 ...
output:
535883695
result:
ok 1 number(s): "535883695"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
20 40 5 13 997345617 549724508 944748330 202749633 10 9 198245521 432417698 101473366 703761448 16 6 595269959 576762532 372290594 369009168 3 6 795786792 340088972 24802450 438315574 18 13 684913777 349693722 674541736 631912951 8 15 766077458 650669097 854245482 942883017 1 9 635974617 368816333 4...
output:
796541145
result:
ok 1 number(s): "796541145"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
20 40 18 16 654451208 375651036 886182759 170071630 4 15 270271718 982447809 92160869 824903953 18 13 361298133 959199889 861424080 425378757 6 3 33874580 988506113 756017321 423603947 9 7 475756610 332242565 449807344 612186375 17 19 287504898 504327263 582668636 283977256 14 1 407481749 210632802 ...
output:
144316553
result:
ok 1 number(s): "144316553"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
20 40 8 4 135764546 24420285 634137915 830995359 19 8 319364393 2683697 571264114 284824764 8 18 225479233 922640515 291113735 420297354 14 8 664762879 255166379 887155179 703256083 8 17 934628338 180965429 286319477 532603369 20 10 399176497 168166271 798788280 992078678 20 4 401000876 963232444 21...
output:
500370272
result:
ok 1 number(s): "500370272"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
20 51 12 6 708883906 616079523 301922898 380436311 6 3 695529309 945988025 477966725 971326054 7 20 584054530 41631645 919656890 113908206 13 14 869634608 704771733 902021158 875816184 13 9 786216923 118258316 954334 288913631 6 10 796154625 112712341 265134793 340144773 20 11 394069377 945509127 65...
output:
6358597
result:
ok 1 number(s): "6358597"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3796kb
input:
20 99 15 6 230660528 109819698 897517403 383083797 10 20 51337908 642383269 61849058 20406305 2 9 340811479 498885794 257915334 313672043 18 14 981969347 728781798 153690585 37927931 12 9 255292958 378468141 344750524 203725273 19 18 85482334 776679862 879139326 821766530 5 2 37463159 162483827 7173...
output:
280192975
result:
ok 1 number(s): "280192975"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
20 51 8 1 30606821 122515505 976812135 830538206 2 17 44053872 999872585 874193029 382466774 17 16 187928160 623973401 192897077 543575137 2 20 258533331 301059832 434424686 583584065 7 2 42045823 803154139 977675298 737353872 16 9 128517480 755951391 501032800 23681059 20 16 300762578 473156283 973...
output:
339242832
result:
ok 1 number(s): "339242832"
Test #26:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
20 84 2 11 120158569 203894199 405688430 803507174 5 20 808947511 708954759 138907772 980357304 1 17 948635541 499422550 464495986 189181095 12 6 233521835 55883228 407155601 245943147 17 16 738224552 144546 268115525 602851994 20 9 600867432 504461699 902924793 566879446 17 11 202071365 874668972 4...
output:
742198000
result:
ok 1 number(s): "742198000"
Test #27:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
20 96 1 9 220410308 132449852 511316540 512518853 9 10 477911013 241554891 739211206 461648718 14 12 419271949 878216485 923347797 349657869 13 12 267667425 801170606 251269135 971169513 20 14 595991765 62363844 549428288 358766302 20 17 648056473 276851853 896787222 523464747 13 7 484869480 9252778...
output:
365461508
result:
ok 1 number(s): "365461508"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
20 36 9 1 878374173 183062941 640355327 174134417 14 5 381989986 243711278 950486641 104245564 12 1 183894897 880002411 100437658 667978209 8 1 990165997 635913260 400546414 152293603 5 2 851094844 331262746 39596083 182528153 1 3 867864371 360332021 425548726 294742894 1 16 68302346 789555444 67367...
output:
817685806
result:
ok 1 number(s): "817685806"
Test #29:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
20 91 3 5 217267134 214414981 857488295 666394085 5 16 456806703 411025711 899199885 127946072 1 17 367647074 823417887 383757091 84031961 17 7 731627726 335038031 205507896 479433480 7 14 740643396 704383230 902851046 301283743 3 19 597833059 87704159 174097411 785743062 1 15 493387796 206475009 34...
output:
470961107
result:
ok 1 number(s): "470961107"
Test #30:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
20 91 15 7 492665231 20048429 382663240 74912315 2 13 770471777 195830771 722181597 490448814 3 19 615960966 234725110 746734171 971742567 4 6 961588434 885037167 5123114 150678105 2 6 308903775 667083271 170712644 675873953 17 12 869386036 718307970 435459136 980806925 19 2 51455169 206516741 45261...
output:
70144704
result:
ok 1 number(s): "70144704"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
20 36 3 4 361903684 925438578 996540133 771118588 19 14 502548982 557989988 983997763 805548178 11 4 684396370 672844308 351431917 543305383 19 20 544845384 794043441 948634725 970094355 19 18 608166631 377850152 170625840 299748492 14 4 827005163 492675383 452974582 173565630 19 10 939105485 802341...
output:
710390659
result:
ok 1 number(s): "710390659"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
20 64 20 2 260608272 20430358 939972577 447580785 18 6 628646022 319488221 320887641 885599893 13 10 280242038 25768374 1897540 659048719 2 15 59448468 940074714 767468550 184294070 10 20 413962171 315221625 506399766 316415517 10 12 492010086 138634795 469367331 916536507 10 4 707702338 679810237 7...
output:
693821211
result:
ok 1 number(s): "693821211"
Test #33:
score: 0
Accepted
time: 4ms
memory: 3612kb
input:
20 100 5 19 126121801 903333668 156846553 636604136 1 8 764271469 22785109 425269775 533657831 5 10 961813220 140100273 688091219 274148493 15 8 300354063 26196791 161408154 571373383 9 7 678105730 914200210 225544141 261251092 17 13 232611289 408525629 609772132 899818970 2 15 207845499 299109635 1...
output:
248194443
result:
ok 1 number(s): "248194443"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
40 39 17 2 393025779 97869717 259115158 558992453 22 2 327468338 766624942 474686650 228102084 2 18 356279706 227261567 881241056 802296831 2 8 797004494 113291184 469129237 300575090 12 2 411012495 415847951 290548491 609844203 28 2 447524769 125533377 513061 531118017 2 39 317730623 287297895 9624...
output:
336151392
result:
ok 1 number(s): "336151392"
Test #35:
score: 0
Accepted
time: 125ms
memory: 3820kb
input:
40 100 21 8 519485335 521691284 458638549 683806640 23 11 446583208 873077884 789684752 94559261 13 40 179855118 477398382 500501679 685817631 11 26 292051350 668629872 605730403 180134882 23 40 752586913 472528859 309049903 699154676 34 25 245125083 820191813 44508094 995487706 12 16 492281158 2078...
output:
695818777
result:
ok 1 number(s): "695818777"
Test #36:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
40 100 20 15 888843752 168754951 276366277 511146580 18 35 320151512 820852842 130666555 257295319 37 15 747096275 630994657 688084536 618902597 8 13 509608098 307826939 413963144 598634346 16 8 646739550 475598141 33569431 376663844 31 18 921408720 541232211 564307288 385000247 26 15 678916692 9752...
output:
26572950
result:
ok 1 number(s): "26572950"
Test #37:
score: -100
Wrong Answer
time: 31ms
memory: 3556kb
input:
40 100 15 40 783765622 874408465 177270058 256389799 38 29 996463884 251082601 930390721 880042986 40 25 827376985 638694970 210239402 474663390 20 35 416484539 811280173 356841392 509183027 19 3 491078680 977238090 468236885 11570683 28 11 505438083 983765980 223761509 771752590 24 4 830691975 8754...
output:
472054376
result:
wrong answer 1st numbers differ - expected: '944108752', found: '472054376'