QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124379#6666. Grafbashkort#0 90ms39984kbC++203.5kb2023-07-14 18:01:532024-07-04 00:40:17

Judging History

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

  • [2024-07-04 00:40:17]
  • 评测
  • 测评结果:0
  • 用时:90ms
  • 内存:39984kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 18:01:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> powers{1}, edgeCnt{0};

    while (powers.back() < n) {
        powers.push_back(powers.back() * 3);
        edgeCnt.push_back(edgeCnt.back() * 3 + 3);
    }

    if (powers.back() != n || edgeCnt.back() != m) {
        cout << "ne\n";
        return 0;
    }

    vector<vector<int>> adjR(n), adjL(n);
    vector<pair<int, int>> edges(m);
    vector<int> deg(n), used(n + m / 3, -1);

    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        x -= 1, y -= 1;
        if (x > y) {
            swap(x, y);
        }
        edges[i] = {x, y};
        deg[x] += 1, deg[y] += 1;
    }

    for (int i = 0; i < m; ++i) {
        auto [x, y] = edges[i];
        if (deg[x] > deg[y]) {
            swap(x, y);
        }
        adjR[x].emplace_back(y);
        adjL[y].emplace_back(x);
    }

    vector<vector<int>> tree(n + m / 3);
    int top = n;

    auto addEdge = [&](int x, int y) {
        tree[x].push_back(y);
        tree[y].push_back(x);
    };

    for (int i = 0; i < n; ++i) {
        for (int to : adjL[i]) {
            used[to] = i;
        }
        for (int to : adjL[i]) {
            for (int k : adjR[to]) {
                if (used[k] == i) {
                    addEdge(top, i);
                    addEdge(top, to);
                    addEdge(top, k);
                    top += 1;
                }
            }
        }
    }

    if (top != n + m / 3) {
        cout << "ne\n";
        return 0;
    }

    auto isTree = [&](auto self, int v, int par) -> int {
        if (used[v]) {
            cout << "ne\n";
            exit(0);
        }
        used[v] = true;
        int siz = 1;
        for (int to : tree[v]) {
            if (to != par) {
                siz += self(self, to, v);
            }
        }
        return siz;
    };

    if (isTree(isTree, 0, -1) != n + m / 3) {
        cout << "ne\n";
        return 0;
    }

    vector<int> siz(n + m / 3);
    fill(used.begin(), used.end(), false);

    auto dfsSz = [&](auto self, int v, int par) -> void {
        siz[v] = 1;
        for (int to : tree[v]) {
            if (to != par && !used[to]) {
                self(self, to, v);
                siz[v] += siz[to];
            }
        }
    };

    auto centroid = [&](auto self, int v, int par, int x) -> int {
        for (int to : tree[v]) {
            if (to != par && !used[to] && siz[to] * 2 > x) {
                return self(self, to, v, x);
            }
        }
        return v;
    };

    auto check = [&](auto self, int v, int id) -> bool {
        used[v] = true;
        dfsSz(dfsSz, v, -1);
        if (v < n && siz[v] == 1 && id == 0) {
            return true;
        }
        if (powers[id] + edgeCnt[id] / 3 != siz[v] || v < n) {
            return false;
        }
        for (int to : tree[v]) {
            if (!used[to]) {
                if (!self(self, centroid(centroid, to, v, siz[to]), id - 1)) {
                    return false;
                }
            }
        }
        return true;
    };

    dfsSz(dfsSz, 0, -1);

    if (check(check, centroid(centroid, 0, -1, n + m / 3), size(powers) - 1)) {
        cout << "da\n";
    } else {
        cout << "ne\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

9 12
7 9
1 5
8 5
4 6
3 4
1 8
6 3
7 5
2 9
4 5
7 4
2 7

output:

ne

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #35:

score: 20
Accepted
time: 0ms
memory: 3532kb

input:

729 1093
340 310
430 713
576 240
138 297
618 162
328 418
143 713
568 220
252 387
219 400
593 491
330 472
722 643
679 598
356 112
701 213
344 408
500 190
225 72
351 688
283 542
215 449
135 194
306 382
266 83
576 289
563 721
345 656
567 694
580 355
127 487
352 310
687 322
620 520
583 466
678 308
19 10...

output:

ne

result:

ok single line: 'ne'

Test #36:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

729 1092
638 250
254 320
297 589
143 720
686 343
468 25
722 60
190 624
421 63
612 42
270 146
577 541
70 707
363 484
286 178
643 210
112 70
7 455
211 431
209 484
386 45
585 402
184 326
557 382
180 406
30 686
299 634
268 97
342 687
172 377
233 505
86 174
105 372
333 466
491 579
390 465
477 176
348 427...

output:

ne

result:

ok single line: 'ne'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

729 1092
301 205
596 371
190 64
77 258
283 304
306 454
210 177
327 251
20 388
185 482
339 284
313 586
368 338
612 47
613 323
559 114
233 296
271 397
705 714
125 159
49 496
286 174
278 521
456 134
422 123
201 283
314 599
354 328
492 339
49 153
628 334
275 190
505 275
326 15
241 348
42 102
65 717
224 ...

output:

ne

result:

ok single line: 'ne'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

243 363
31 225
187 117
147 160
229 44
168 179
164 107
173 146
78 102
47 50
38 13
222 83
115 24
14 240
185 61
199 111
119 225
98 80
126 102
42 235
43 216
59 129
109 193
179 27
218 142
114 50
46 174
47 99
120 6
103 221
136 187
19 191
65 180
57 160
166 83
185 229
48 139
114 143
150 101
208 80
24 74
7 6...

output:

ne

result:

ok single line: 'ne'

Test #39:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

729 1093
73 12
701 403
473 596
214 290
248 310
317 639
507 457
298 227
185 326
430 27
61 34
547 636
99 685
607 45
6 101
283 377
310 33
42 132
573 647
483 658
112 113
647 324
518 616
302 247
71 465
586 187
81 396
621 606
435 498
667 677
24 333
414 497
111 164
510 628
665 82
325 719
536 556
719 704
24...

output:

ne

result:

ok single line: 'ne'

Test #40:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

729 1092
663 607
327 712
424 22
507 89
138 363
465 228
129 291
389 682
73 477
581 622
582 543
78 487
55 479
186 50
619 167
490 615
677 191
42 574
323 136
283 120
433 325
531 530
144 24
620 239
368 225
12 166
452 686
361 526
248 709
586 606
39 110
229 696
686 647
260 333
403 150
88 462
529 449
513 35...

output:

ne

result:

ok single line: 'ne'

Test #41:

score: -20
Wrong Answer
time: 1ms
memory: 3680kb

input:

729 1092
659 490
150 263
166 478
382 659
135 290
603 656
601 301
64 689
81 160
197 133
438 593
379 482
522 493
238 72
362 664
648 240
471 168
32 153
282 407
648 492
276 218
593 106
193 537
613 369
632 167
235 236
663 319
37 416
577 659
111 601
578 483
645 529
100 636
457 312
200 161
515 344
591 706
...

output:

ne

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #69:

score: 15
Accepted
time: 69ms
memory: 29540kb

input:

177147 265719
79646 110581
42107 166686
174516 92541
11418 84874
89568 79680
101533 167489
143016 26545
83401 102450
122789 91031
140172 64836
143906 82843
45757 98991
164963 130550
33432 152305
80043 16055
49162 39443
59476 89357
146429 111186
99327 115855
166381 89990
91164 139281
121510 124610
16...

output:

ne

result:

ok single line: 'ne'

Test #70:

score: 0
Accepted
time: 56ms
memory: 29500kb

input:

177147 265719
38681 77992
106972 53905
88649 110477
113934 98724
78662 109263
134699 83502
31991 92472
126170 144
119650 132169
84458 92531
24682 66176
131541 177081
97342 131339
103685 102763
130223 36375
142925 66285
105340 117815
111137 162166
43022 15242
120307 54486
78258 164394
52991 104308
65...

output:

ne

result:

ok single line: 'ne'

Test #71:

score: 0
Accepted
time: 79ms
memory: 39012kb

input:

177147 265719
80151 35717
121902 3023
160759 169382
24887 142159
40782 159514
23600 98839
121180 62418
122763 152478
148678 114794
11943 72581
173127 2884
97280 4969
155030 45742
120300 148466
134742 140635
79483 24583
71636 91841
140421 126108
44434 53426
133218 79051
161302 161964
59589 111719
961...

output:

ne

result:

ok single line: 'ne'

Test #72:

score: 0
Accepted
time: 90ms
memory: 38668kb

input:

177147 265719
23535 148931
151961 42693
126734 69633
41675 97286
148290 110970
18165 83792
5192 133074
101128 76523
76671 146056
37165 145496
108304 76746
47477 140906
73419 48220
39470 54859
81251 91381
88943 87801
102113 126514
153800 35348
116125 49494
114248 11690
150336 26095
40669 90388
3210 9...

output:

ne

result:

ok single line: 'ne'

Test #73:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

177147 265720
170712 62225
99915 128584
115624 72186
110450 90393
65021 158547
110390 161798
28967 132365
78897 47218
68752 69351
40606 17503
79654 32708
98155 146206
156781 52063
126696 159590
11625 167534
29472 10242
143508 43084
154423 175381
150212 141153
5882 3903
142063 39110
158366 31577
2263...

output:

ne

result:

ok single line: 'ne'

Test #74:

score: -15
Wrong Answer
time: 72ms
memory: 39984kb

input:

177147 265719
67351 167238
129901 55608
68480 135374
104799 141169
109735 94431
87690 136110
134896 150128
94005 84319
29006 124099
31988 157247
99008 24808
30090 15310
10480 16443
98191 89543
98109 139907
59896 166679
121226 129438
83139 84515
163834 143237
162513 60464
6858 120706
23808 13193
8871...

output:

ne

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #103:

score: 50
Accepted
time: 62ms
memory: 29496kb

input:

177147 265719
132920 57252
64370 50983
162323 103641
126430 64347
64421 107962
35533 30427
171597 160614
120187 121996
103235 117200
122594 156637
121481 108177
115386 6337
28269 153079
43775 171594
164425 165290
59340 170257
20858 74213
162837 103195
171976 121082
68853 33317
152714 8959
47095 9036...

output:

ne

result:

ok single line: 'ne'

Test #104:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

177147 265720
98251 19107
36929 5082
59297 17482
166275 130189
125119 161493
151977 35937
4540 92380
52037 36475
105282 76892
8397 7997
162679 100647
12685 34568
53625 30405
136245 147693
95596 151955
66119 156086
92822 98840
66600 97472
42324 130091
34459 150929
81661 38148
1174 30859
113776 90353
...

output:

ne

result:

ok single line: 'ne'

Test #105:

score: 0
Accepted
time: 21ms
memory: 12080kb

input:

59049 88572
14041 31673
1168 11350
38714 28802
37877 22048
49987 22707
26786 49980
2818 13974
10003 17358
51907 30794
16816 20935
8685 53622
49148 54509
3371 26238
50806 4657
57731 38759
38131 9810
28974 19191
5485 27763
9140 36793
45914 17712
23433 31979
29334 8721
7313 42734
12130 24011
36906 5164...

output:

ne

result:

ok single line: 'ne'

Test #106:

score: 0
Accepted
time: 58ms
memory: 29420kb

input:

177147 265719
119867 167070
130132 12752
120764 56321
15572 66501
139543 82691
70068 42197
61383 135281
122332 161897
68678 68884
51691 172281
33415 150511
101102 101300
108117 151586
39194 21123
173495 82522
134499 170131
15461 53912
114257 106087
137475 32697
31578 172314
139488 145536
118015 1288...

output:

ne

result:

ok single line: 'ne'

Test #107:

score: 0
Accepted
time: 59ms
memory: 29564kb

input:

177147 265719
32229 30186
75313 76163
111944 168135
43914 37095
22266 44860
166052 93754
169557 55704
108797 163872
45432 112994
80343 100383
110188 66178
135008 105902
155873 72661
44225 151314
2720 88316
66950 133820
20039 85930
91897 17236
40370 91049
112750 27809
48067 13266
126431 53691
127666 ...

output:

ne

result:

ok single line: 'ne'

Test #108:

score: 0
Accepted
time: 29ms
memory: 14908kb

input:

59049 88572
26511 33490
28852 45905
27461 12238
3574 21240
10401 47111
25108 30094
41731 23065
34029 50912
24637 3051
39816 52369
17677 44545
29603 11717
24661 41876
6322 19702
11178 38322
12480 26080
47105 3194
12178 36578
32634 16221
25540 24583
42234 24601
15926 7470
5428 20505
18895 24343
6641 2...

output:

ne

result:

ok single line: 'ne'

Test #109:

score: 0
Accepted
time: 84ms
memory: 38804kb

input:

177147 265719
109974 161035
10257 149062
121470 37587
101821 92037
121099 27132
31616 170660
46299 85346
105465 61610
133310 53913
20419 23471
11021 49161
161237 108062
27418 106411
42549 75808
90998 78111
32550 19003
10562 170797
77403 67800
34756 24189
88268 56154
14749 154026
5889 159314
104655 1...

output:

ne

result:

ok single line: 'ne'

Test #110:

score: 0
Accepted
time: 83ms
memory: 38708kb

input:

177147 265719
108664 58201
64269 6343
120585 157969
151929 136534
168726 15269
25610 60139
11181 158806
139226 97957
107369 141067
135947 160932
162045 50711
105512 5940
172321 5888
7221 99888
120318 20857
24810 151590
135587 8881
143228 24034
6096 39018
73071 58377
173193 124153
97410 69946
74197 7...

output:

ne

result:

ok single line: 'ne'

Test #111:

score: 0
Accepted
time: 60ms
memory: 29492kb

input:

177147 265719
32981 44699
147062 61378
88263 172913
58385 30028
98963 22183
21517 65343
40334 104039
63687 1318
136538 117786
2824 90817
170979 107527
93628 112008
35891 28456
164720 154877
2494 115639
119501 113995
31926 105269
92857 99010
174834 17842
11538 142621
125432 105466
135353 157000
68024...

output:

ne

result:

ok single line: 'ne'

Test #112:

score: 0
Accepted
time: 57ms
memory: 29432kb

input:

177147 265719
167966 17672
92091 174891
69156 176406
144245 124379
124290 42270
59738 92303
86870 83034
79441 52547
15702 45945
164475 43564
132133 61402
27448 122029
45378 131195
35639 152970
550 29347
134069 145338
111946 144913
58629 120345
90261 66787
8482 156139
106048 76828
151397 165340
22520...

output:

ne

result:

ok single line: 'ne'

Test #113:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

177147 265720
84549 59066
8533 97512
95654 45173
28525 150968
86580 149227
57726 67651
52781 160528
97950 141266
100850 14838
166553 138190
61634 14254
57547 24000
168524 11255
116362 130964
170815 172567
120074 7542
128396 3289
29898 125597
163966 69876
50139 142020
84785 71240
22378 26807
135344 1...

output:

ne

result:

ok single line: 'ne'

Test #114:

score: 0
Accepted
time: 78ms
memory: 39100kb

input:

177147 265719
68898 132920
29665 73506
20531 169214
103475 58989
61733 32239
151574 63398
119411 169525
24793 25207
41292 44383
133706 111802
174419 1600
74876 147063
161499 174674
10278 7799
123599 8481
146302 166032
1313 90856
60646 95512
106779 134984
41603 43637
15001 37449
153582 123699
108004 ...

output:

ne

result:

ok single line: 'ne'

Test #115:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

59049 88573
48002 20129
7630 33065
13470 58907
56979 49428
24783 51171
35198 55138
26000 13842
56782 34295
54165 5732
52635 46706
40182 1575
48144 56529
25104 1814
30791 45557
24736 48013
51257 51882
26582 54128
26950 47776
18073 51674
24939 54097
24871 44506
23664 28536
3218 34786
44770 14839
46589...

output:

ne

result:

ok single line: 'ne'

Test #116:

score: -50
Wrong Answer
time: 69ms
memory: 39024kb

input:

177147 265719
134788 176770
110415 30012
70814 170685
31716 97968
166427 107186
55319 99947
990 168895
127047 57299
122397 109455
67762 167879
120077 134331
18803 64603
48445 33935
104943 45500
128895 87604
148759 151945
94766 103320
129651 15389
26640 140574
173781 39496
132805 125367
168455 59830
...

output:

ne

result:

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