QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455815#7125. Bipartite graph coloringpropaneRE 0ms3856kbC++202.3kb2024-06-26 20:39:262024-06-26 20:39:28

Judging History

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

  • [2024-06-26 20:39:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3856kb
  • [2024-06-26 20:39:26]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;
const int mod = 1e9 + 7;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
}

int mul(int a, int b){
    return 1LL * a * b % mod;
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, m;
    cin >> n >> m;
    vector<array<int, 6> > p(m);
    vector<vector<pair<int, int> > > g(n + 1);
    for(int i = 0; i < m; i++){
        int a, b, c, d, e, f;
        cin >> a >> b >> c >> d >> e >> f;
        p[i] = {a, b, c, d, e, f};
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    
    vector<int> pos[2];

    vector<int> color(n + 1, - 1);

    auto dfs = [&](auto &&dfs, int u, int c) -> void {
        color[u] = c;
        pos[color[u]].push_back(u);
        for(auto [j, id] : g[u]){
            if (color[j] == -1){
                dfs(dfs, j, c ^ 1);
            }
        }
    };

    for(int i = 1; i <= n; i++){
        if (color[i] == -1){
            dfs(dfs, i, 0);
        }
    }

    if (pos[0].size() > pos[1].size()){
        swap(pos[0], pos[1]);
        for(auto &x : color) x ^= 1;
    }

    for(auto &[a, b, c, d, e, f] : p){
        if (color[a] == 1){
            swap(a, b);
            swap(d, e);
        }
    }

    vector<int> id(n);
    for(int i = 0; i < pos[0].size(); i++){
        id[pos[0][i]] = i;
    }
    
    int ans = 0;
    const int k = pos[0].size();
    for(int i = 0; i < 1 << k; i++){
        vector<array<int, 2> > sum(n + 1, {1, 1});
        for(auto [a, b, c, d, e, f] : p){
            int c1 = (i >> id[a] & 1);
            if (c1 == 0){
                sum[b][0] = mul(sum[b][0], c);
                sum[b][1] = mul(sum[b][1], d);
            }
            else{
                sum[b][0] = mul(sum[b][0], e);
                sum[b][1] = mul(sum[b][1], f);
            }
        }
        int res = 1;
        for(int j = 1; j <= n; j++){
            if (color[j] == 1){
                res = mul(res, sum[j][0] + sum[j][1]);
            }
        }
        add(ans, res);
    }
    cout << ans << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

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: 3824kb

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: 3536kb

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: 3560kb

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: 3856kb

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: 0ms
memory: 3624kb

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: 0ms
memory: 3796kb

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: 3564kb

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: -100
Runtime Error

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:


result: