QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#724072#4934. Forbidden CardwinsunWA 16ms7056kbC++141.5kb2024-11-08 09:16:582024-11-08 09:16:59

Judging History

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

  • [2024-11-08 09:16:59]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:7056kb
  • [2024-11-08 09:16:58]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <queue>
#include <utility>
#define fi first
#define se second

using namespace std;
typedef long long LL;

template <typename Tp> inline void read(Tp& x) {
    char ch; bool op = 0; x = 0;
    do ch = getchar(), op |= ch == '-'; while (ch < '0' || ch > '9');
    do x = (x<<3)+(x<<1)+(ch&15), ch = getchar(); while (ch >= '0' && ch <= '9');
    if (op) x = -x;
}

bool Mst;
const int MAXN = 1e5+5;
const int MAXM = 1e6+5;
int n, m, a[MAXN], b[MAXN];
int use[MAXM], tar[MAXN<<1], cnt[MAXN];
bool Med;

void solve() {
    for (int _ = 0; _ < 2; ++_) {
        for (int i = 1; i <= n; ++i) {
            if (!use[a[i]]) use[a[i]] = i;
            else if (!use[b[i]]) use[b[i]] = i + n;
            else return tar[0] = i, void();
        } 
    }
    tar[0] = 1;
}

int calc(int x) {
    if (tar[x]) return tar[x];
    else if (x > n) return tar[x] = x - n;
    else if (use[b[x]] && use[b[x]] < x) return tar[x] = x; 
    else return tar[x] = calc(use[b[x]]);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("qoj4934.in", "r", stdin);
    freopen("qoj4934.out", "w", stdout);
    fprintf(stderr, "%.3lfMB\n", (&Mst - &Med) / 1048576.0);
    #endif
    read(n), read(m);
    for (int i = 1; i <= n; ++i) read(a[i]), read(b[i]);
    solve();
    for (int i = 1; i <= m; ++i) ++cnt[calc(use[i])], assert(calc(use[i]) <= n);
    for (int i = 1; i <= n; ++i) printf("%d\n", cnt[i]); 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 6
1 2
2 4
4 2

output:

3
0
3

result:

ok 3 lines

Test #2:

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

input:

4 10
1 5
2 6
3 7
4 8

output:

4
2
2
2

result:

ok 4 lines

Test #3:

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

input:

1 2
1 2

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 10ms
memory: 5096kb

input:

69332 250102
51362 228823
206751 31351
181790 44202
186695 92215
172072 173179
86663 76959
42382 25827
204750 30001
42502 11959
201030 71886
227497 216114
164282 235028
178967 181951
125356 20611
169528 174071
50985 175562
63676 208400
189134 229462
49746 131529
180236 247427
29278 229589
30381 4412...

output:

197458
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 69332 lines

Test #5:

score: 0
Accepted
time: 12ms
memory: 4420kb

input:

80145 426253
421996 34366
346502 239646
343011 88629
67397 242186
299496 244930
21243 104718
387596 328535
219758 313693
75331 382300
313805 77098
42577 148653
337458 118115
214642 386869
250381 179903
371620 42703
175776 57872
382478 385425
67153 363632
137021 301439
54496 28984
416540 87624
180610...

output:

2
2
387645
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 80145 lines

Test #6:

score: 0
Accepted
time: 15ms
memory: 7056kb

input:

100000 1000000
123135 548518
73705 792839
425849 331898
823140 91484
612409 674530
215766 587078
145133 904035
435464 107690
291461 358251
156778 270843
378425 339959
353997 687100
373365 903063
948343 203641
349073 91866
329756 348161
731516 202789
767371 938875
3496 388919
998073 384450
73693 8551...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
956616
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 lines

Test #7:

score: 0
Accepted
time: 11ms
memory: 6064kb

input:

89069 799019
589538 728126
669934 721110
689804 767765
57113 349607
788143 621300
449778 648433
451910 356399
484000 586091
699836 387252
618498 221963
42563 549795
774972 697895
765784 478517
626296 213965
174994 617652
788312 418305
509601 717678
663049 769953
167726 375932
38772 144093
140904 564...

output:

2
783305
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 89069 lines

Test #8:

score: 0
Accepted
time: 9ms
memory: 6012kb

input:

69694 877503
863663 582574
192540 50718
545855 600725
106914 337076
95953 472303
337876 352481
617099 663754
658298 249330
575057 97722
522140 520920
811913 519974
533217 425142
590101 532180
684733 355462
783334 274412
25380 75797
853682 128592
457036 274558
184076 7863
688088 614343
733047 768004
...

output:

2
2
829210
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 69694 lines

Test #9:

score: 0
Accepted
time: 6ms
memory: 6404kb

input:

68561 994844
934673 839086
678230 902049
609695 838139
172142 165310
166125 382300
733287 681492
31687 156593
743676 484561
301345 936945
511237 258689
936301 315735
750745 500110
650444 288851
407665 485171
316258 272455
868401 430224
348328 582450
368182 44256
934873 895495
466439 780819
543373 68...

output:

2
2
2
2
985873
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 68561 lines

Test #10:

score: 0
Accepted
time: 15ms
memory: 6972kb

input:

100000 1000000
750844 577520
750988 551898
71182 495851
781670 620811
429538 655630
949020 91780
352634 583957
278999 299878
401107 296003
310998 796093
134490 713012
571847 466126
97048 513189
701512 397675
328784 597378
600866 775036
123964 779641
783762 95052
581923 521272
174622 578127
940629 92...

output:

958024
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 lines

Test #11:

score: 0
Accepted
time: 15ms
memory: 6668kb

input:

97613 571574
473117 229386
423786 319808
400816 515877
51984 283789
129404 223355
36594 363548
378401 286262
173741 481783
33072 245586
443684 222118
84885 277987
521174 139691
557463 541830
447714 163559
414047 64274
366005 384713
149976 525494
497204 378402
548917 82952
184725 168981
445716 501317...

output:

542823
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 97613 lines

Test #12:

score: 0
Accepted
time: 9ms
memory: 5972kb

input:

69396 864127
464385 526906
787104 491768
38269 47670
86820 517464
353813 728363
679809 387823
517990 116740
848791 410216
587334 99062
778991 733391
832499 522941
19242 176014
751019 345373
268829 384678
55782 16440
127010 333800
535423 588225
109371 645414
145244 552479
597799 552396
600038 235109
...

output:

2
2
2
2
2
2
2
805120
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 69396 lines

Test #13:

score: 0
Accepted
time: 3ms
memory: 5852kb

input:

86470 288956
81959 261040
206019 205310
130325 15327
223490 45996
254263 134493
132914 146198
271808 230093
192789 239059
257256 18045
87950 183011
19344 266027
280038 28560
139522 285325
26554 267570
4553 143311
21451 61963
242467 238366
274767 216559
165157 8502
185945 180806
271515 104078
98160 2...

output:

239234
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 86470 lines

Test #14:

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

input:

2 2
2 1
1 2

output:

0
2

result:

ok 2 lines

Test #15:

score: 0
Accepted
time: 15ms
memory: 6952kb

input:

100000 1000000
642133 546926
123679 867209
617137 454611
472705 627306
94896 603782
523279 31451
263895 276501
142151 455942
525514 977824
263586 220101
93152 998514
117325 54406
75166 160431
174093 514041
409869 356920
751904 244516
844806 816952
904840 872203
896272 387803
522151 434957
154934 531...

output:

2
3
2
2
2
2
3
2
2
908975
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 16ms
memory: 6792kb

input:

96191 790771
239246 406927
608723 39453
647021 455246
449613 325203
500412 246565
496412 527678
775691 306215
15686 145589
789951 122377
126343 302706
704644 254834
538536 278628
68976 439516
650659 690292
496323 588418
710462 6367
227229 387492
313599 215876
281669 237302
117764 311686
70133 388917...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 96191 lines

Test #17:

score: -100
Wrong Answer
time: 10ms
memory: 4964kb

input:

86551 543901
231809 430371
538308 434317
542712 120195
323781 89341
535653 25803
423038 172132
280771 313400
527228 456621
112353 356938
487630 393471
191751 52096
151594 392894
230381 83155
362583 11099
43970 409303
356820 251516
199568 326380
74743 182624
406748 384282
534629 72327
358298 533328
3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 38835th lines differ - expected: '1', found: '3'