QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250709#6225. 生成树zzy09220 497ms85924kbC++142.3kb2023-11-13 15:59:422023-11-13 15:59:43

Judging History

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

  • [2023-11-13 15:59:43]
  • 评测
  • 测评结果:0
  • 用时:497ms
  • 内存:85924kb
  • [2023-11-13 15:59:42]
  • 提交

answer

#include <bits/stdc++.h>

constexpr int N = 500005;
const int mod = 0x3b800001;

int n, m, tot;
std::set<int> G[N];
std::map<std::pair<int, int>, int> id;
int u[N << 1], v[N << 1], f[N << 1], g[N << 1];

inline int &to(int uu, const int &id) {
    return uu == u[id] ? v[id] : u[id];
}

int deg[N];

inline int add_e(int uu, int vv, int ff, int gg) {
    ++tot;
    u[tot] = uu;
    v[tot] = vv;
    G[uu].emplace(tot);
    G[vv].emplace(tot);
    id[std::make_pair(uu, vv)] = id[std::make_pair(vv, uu)] = tot;
    deg[uu]++;
    deg[vv]++;
    f[tot] = ff;
    g[tot] = gg;
    return tot;
}


inline void del(int id) {
    G[u[id]].erase(id);
    G[v[id]].erase(id);
    deg[u[id]]--;
    deg[v[id]]--;
}

int main() {
    std::cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        std::cin >> u[i] >> v[i];
        G[u[i]].emplace(i);
        G[v[i]].emplace(i);
        deg[u[i]]++;
        deg[v[i]]++;
        f[i] = g[i] = 1;
        id[std::make_pair(u[i], v[i])] = id[std::make_pair(v[i], u[i])] = i;
    }
    tot = m;
    std::queue<int> q;
    for (int i = 1; i <= n; i++) 
        if (deg[i] <= 2)
            q.push(i);
    int ans = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        if (!deg[x]) break;
        if (deg[x] == 1) {
            assert((int)G[x].size() == 1);
            int idd = *G[x].begin();
            del(idd);
            ans = 1ll * ans * f[idd] % mod;
            continue;
        } else {
            assert(deg[x] == 2);
            int id1 = *G[x].begin(), id2 = *std::next(G[x].begin());
            int u = to(x, id1), v = to(x, id2);
            del(id1);
            del(id2);

            int ff = 1ll * f[id1] * f[id2] % mod, gg = (1ll * f[id1] * g[id2] + 1ll * g[id1] * f[id2]) % mod;
            if (!id.count(std::make_pair(u, v))) {
                add_e(u, v, ff, gg);
            } else {
                int idd = id[std::make_pair(u, v)];
                int tmpf = f[idd], tmpg = g[idd];
                f[idd] = (1ll * tmpf * gg + 1ll * ff * tmpg) % mod;
                g[idd] = 1ll * tmpg * gg % mod;
                if (deg[u] <= 2) q.push(u);
                if (deg[v] <= 2) q.push(v);
            }
        }
    }
    std::cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 36568kb

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:

1

result:

wrong answer 1st lines differ - expected: '8', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 80ms
memory: 46860kb

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:

664703099

result:

wrong answer 1st lines differ - expected: '778245294', found: '664703099'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 191ms
memory: 58024kb

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:

212270031

result:

wrong answer 1st lines differ - expected: '373712628', found: '212270031'

Subtask #4:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 230ms
memory: 63316kb

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:

272549932

result:

wrong answer 1st lines differ - expected: '810112214', found: '272549932'

Subtask #5:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 219ms
memory: 58344kb

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:

383958818

result:

wrong answer 1st lines differ - expected: '396960248', found: '383958818'

Subtask #6:

score: 0
Wrong Answer

Test #12:

score: 0
Wrong Answer
time: 188ms
memory: 61340kb

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:

168522925

result:

wrong answer 1st lines differ - expected: '3947657', found: '168522925'

Subtask #7:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 189ms
memory: 62584kb

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:

784137646

result:

wrong answer 1st lines differ - expected: '259608098', found: '784137646'

Subtask #8:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 310ms
memory: 70812kb

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:

445146477

result:

wrong answer 1st lines differ - expected: '767723653', found: '445146477'

Subtask #9:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 461ms
memory: 85924kb

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:

682742431

result:

wrong answer 1st lines differ - expected: '329641010', found: '682742431'

Subtask #10:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 497ms
memory: 85660kb

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:

968028736

result:

wrong answer 1st lines differ - expected: '163752784', found: '968028736'