QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#464189#131. ICPC teamspropaneAC ✓90ms50024kbC++203.1kb2024-07-05 21:47:132024-07-05 21:47:13

Judging History

This is the latest submission verdict.

  • [2024-07-05 21:47:13]
  • Judged
  • Verdict: AC
  • Time: 90ms
  • Memory: 50024kb
  • [2024-07-05 21:47:13]
  • Submitted

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

const int mod = 1e9 + 9;

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

void sub(int &a, int b){
    a -= b;
    if (a < 0) a += mod;
}

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

int qpow(int a, int b){
    int ans = 1;
    while(b){
        if (b & 1) ans = mul(ans, a);
        b >>= 1;
        a = mul(a, a);
    }
    return ans;
}

const int maxn = 3e6 + 5;
int fact[maxn], invfact[maxn];
int powfact3[maxn];

int p[100], sz[100];

void init(int n){
    for(int i = 0; i < n; i++){
        p[i] = i;
        sz[i] = 1;
    }
}

int find(int x){
    return p[x] == x ? x : p[x] = find(p[x]);
}

void merge(int x, int y){
    x = find(x), y = find(y);
    if (x != y){
        p[x] = y;
        sz[y] += sz[x];
    }
}

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;
    n *= 3;
    fact[0] = 1;
    for(int i = 1; i < maxn; i++) fact[i] = mul(fact[i - 1], i);
    invfact[maxn - 1] = qpow(fact[maxn - 1], mod - 2);
    for(int i = maxn - 2; i >= 0; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
    powfact3[0] = 1;
    for(int i = 1; i < maxn; i++){
        powfact3[i] = mul(powfact3[i - 1], invfact[3]);
    }

    auto C = [&](int a, int b){
        if (a < 0 or b < 0 or a < b) return 0;
        return mul(mul(fact[a], invfact[b]), invfact[a - b]);
    };

    vector<pair<int, int> > v[2];
    vector<int> q;
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        q.push_back(a);
        q.push_back(b);
        v[c].push_back({a, b});
    }

    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    vector<int> id(n + 1);
    for(int i = 0; i < q.size(); i++){
        id[q[i]] = i;
    }

    int ans = 0;
    const int s = v[1].size();
    for(int i = 0; i < 1 << s; i++){
        init(q.size());
        for(auto [x, y] : v[0]){
            merge(id[x], id[y]);
        }
        for(int j = 0; j < s; j++){
            if (i >> j & 1){
                auto [x, y] = v[1][j];
                merge(id[x], id[y]);
            }
        }
        bool ok = true;
        int cnt[4]{};
        cnt[1] = n - q.size();
        for(int i = 0; i < q.size(); i++){
            if (find(i) == i){
                if (sz[i] > 3){
                    ok = false;
                    break;
                }
                cnt[sz[i]] += 1;
            }
        }
        if (!ok or cnt[2] > cnt[1]) continue;
        int sum = mul(C(cnt[1], cnt[2]), fact[cnt[2]]);
        cnt[1] -= cnt[2];
        int t = mul(fact[cnt[1]], powfact3[cnt[1] / 3]);
        t = mul(t, invfact[cnt[1] / 3]);
        if (__builtin_parity(i)) sub(ans, mul(sum, t));
        else add(ans, mul(sum, t));
    }
    cout << ans << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 47ms
memory: 38752kb

input:

5 4
9 4 0
15 14 1
11 9 1
1 9 0

output:

12600

result:

ok single line: '12600'

Test #2:

score: 0
Accepted
time: 40ms
memory: 39008kb

input:

2 3
4 1 0
3 6 0
2 5 1

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 43ms
memory: 38952kb

input:

5 5
8 4 0
13 5 1
15 8 0
9 14 1
13 12 0

output:

2030

result:

ok single line: '2030'

Test #4:

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

input:

4 5
12 2 0
7 4 1
4 2 1
5 6 1
4 6 1

output:

1170

result:

ok single line: '1170'

Test #5:

score: 0
Accepted
time: 39ms
memory: 38748kb

input:

5 7
1 14 0
10 11 0
8 5 1
3 2 1
10 13 0
6 5 0
4 12 1

output:

308

result:

ok single line: '308'

Test #6:

score: 0
Accepted
time: 47ms
memory: 38720kb

input:

5 1
2 11 1

output:

1201200

result:

ok single line: '1201200'

Test #7:

score: 0
Accepted
time: 42ms
memory: 38788kb

input:

1 1
1 2 0

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 42ms
memory: 38660kb

input:

3 1
4 2 1

output:

210

result:

ok single line: '210'

Test #9:

score: 0
Accepted
time: 39ms
memory: 38776kb

input:

5 3
6 9 0
1 14 0
2 9 1

output:

28000

result:

ok single line: '28000'

Test #10:

score: 0
Accepted
time: 38ms
memory: 39004kb

input:

1 1
3 2 0

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 38ms
memory: 38716kb

input:

2 1
4 1 0

output:

4

result:

ok single line: '4'

Test #12:

score: 0
Accepted
time: 31ms
memory: 39004kb

input:

4 1
12 10 1

output:

12600

result:

ok single line: '12600'

Test #13:

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

input:

3 3
2 4 1
4 6 1
9 1 0

output:

34

result:

ok single line: '34'

Test #14:

score: 0
Accepted
time: 39ms
memory: 38664kb

input:

5 2
15 6 0
13 10 1

output:

169400

result:

ok single line: '169400'

Test #15:

score: 0
Accepted
time: 47ms
memory: 38780kb

input:

5 3
13 7 0
11 6 0
2 14 0

output:

5040

result:

ok single line: '5040'

Test #16:

score: 0
Accepted
time: 38ms
memory: 38784kb

input:

2 1
1 6 0

output:

4

result:

ok single line: '4'

Test #17:

score: 0
Accepted
time: 39ms
memory: 38716kb

input:

2 2
6 4 1
4 3 0

output:

3

result:

ok single line: '3'

Test #18:

score: 0
Accepted
time: 43ms
memory: 38944kb

input:

4 1
6 2 0

output:

2800

result:

ok single line: '2800'

Test #19:

score: 0
Accepted
time: 38ms
memory: 38772kb

input:

3 2
9 2 0
3 8 1

output:

50

result:

ok single line: '50'

Test #20:

score: 0
Accepted
time: 34ms
memory: 38776kb

input:

2 3
3 6 0
1 5 0
5 2 0

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 39ms
memory: 38780kb

input:

5 1
6 3 1

output:

1201200

result:

ok single line: '1201200'

Test #22:

score: 0
Accepted
time: 35ms
memory: 38812kb

input:

3 3
4 5 1
2 8 0
7 9 1

output:

36

result:

ok single line: '36'

Test #23:

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

input:

4 5
6 9 1
7 10 0
12 2 1
5 7 1
12 3 0

output:

346

result:

ok single line: '346'

Test #24:

score: 0
Accepted
time: 46ms
memory: 38712kb

input:

3 1
6 5 0

output:

70

result:

ok single line: '70'

Test #25:

score: 0
Accepted
time: 46ms
memory: 38816kb

input:

2 1
4 2 1

output:

6

result:

ok single line: '6'

Test #26:

score: 0
Accepted
time: 47ms
memory: 38780kb

input:

21 18
63 12 0
30 16 1
36 6 0
18 22 0
44 10 1
26 31 0
58 49 1
38 51 0
51 8 0
9 29 0
44 55 1
33 12 1
13 60 0
51 28 1
6 31 1
36 44 0
19 33 1
14 54 0

output:

980511883

result:

ok single line: '980511883'

Test #27:

score: 0
Accepted
time: 35ms
memory: 38776kb

input:

8 7
9 21 0
16 6 0
19 24 1
20 5 1
1 3 1
7 5 1
6 2 0

output:

314281182

result:

ok single line: '314281182'

Test #28:

score: 0
Accepted
time: 31ms
memory: 39008kb

input:

74 10
189 179 1
43 85 1
192 1 1
130 127 1
4 21 1
11 222 0
72 15 0
105 172 0
96 199 0
80 123 0

output:

210422912

result:

ok single line: '210422912'

Test #29:

score: 0
Accepted
time: 47ms
memory: 38780kb

input:

54 2
3 118 1
6 160 0

output:

722223622

result:

ok single line: '722223622'

Test #30:

score: 0
Accepted
time: 39ms
memory: 39004kb

input:

50 13
104 23 0
87 36 1
14 78 1
110 57 1
13 142 0
134 73 1
145 69 1
105 86 1
122 114 1
86 123 1
15 41 0
144 66 1
46 79 1

output:

800600729

result:

ok single line: '800600729'

Test #31:

score: 0
Accepted
time: 31ms
memory: 38724kb

input:

20 17
3 5 0
30 52 1
55 47 0
9 58 0
3 39 1
36 31 0
12 48 1
1 12 1
4 59 0
3 54 1
4 10 0
37 39 0
13 30 0
11 1 1
9 16 1
55 17 0
6 3 0

output:

532913846

result:

ok single line: '532913846'

Test #32:

score: 0
Accepted
time: 23ms
memory: 38784kb

input:

62 14
5 169 1
7 61 0
54 128 0
74 96 0
33 145 1
169 34 0
71 125 1
132 76 1
176 35 1
29 75 1
147 185 0
158 84 1
10 66 0
88 95 0

output:

15600364

result:

ok single line: '15600364'

Test #33:

score: 0
Accepted
time: 46ms
memory: 39008kb

input:

69 3
125 59 0
71 170 1
148 49 1

output:

207994843

result:

ok single line: '207994843'

Test #34:

score: 0
Accepted
time: 43ms
memory: 38788kb

input:

49 13
93 136 0
39 101 1
112 89 1
80 99 1
53 57 1
14 130 1
22 43 1
20 117 0
54 21 1
57 125 1
130 112 0
125 86 0
44 39 0

output:

513487872

result:

ok single line: '513487872'

Test #35:

score: 0
Accepted
time: 35ms
memory: 39004kb

input:

82 5
154 133 1
166 170 0
224 191 1
135 166 1
166 239 1

output:

379719457

result:

ok single line: '379719457'

Test #36:

score: 0
Accepted
time: 49ms
memory: 49932kb

input:

994558 18
1796092 587398 1
1479799 279424 0
1718609 855290 0
716855 2476702 1
1803523 1339066 1
1405749 2496232 0
2258614 604349 1
2399647 22785 1
2962827 2605848 1
606895 604631 0
640125 1207612 1
1787407 1360846 1
2052919 1456481 1
1955938 1342314 1
1909718 104324 1
840288 198019 0
1916626 1279828...

output:

366294837

result:

ok single line: '366294837'

Test #37:

score: 0
Accepted
time: 23ms
memory: 49056kb

input:

906587 18
349120 2098376 1
1717631 1548064 1
2626682 2379384 1
1593536 1892459 1
1363599 1986256 0
2000096 170280 1
2045108 1315986 1
40768 198444 0
1628665 2327170 1
2102836 790082 1
378570 1445168 1
2176299 1599496 1
2614671 1345768 0
2206875 1697644 0
962196 180314 1
1050403 1620508 1
2241650 181...

output:

417688559

result:

ok single line: '417688559'

Test #38:

score: 0
Accepted
time: 35ms
memory: 49292kb

input:

931917 18
1145433 1394149 0
541131 365400 1
281017 1749211 0
109452 2354616 0
403777 2031343 0
2702444 2082718 1
2246313 2134589 0
1113982 1274726 1
2738629 598203 0
1805993 394021 1
2222590 342421 1
1062908 941509 0
830694 926258 1
67215 2685232 1
1377291 1692099 0
361461 238989 0
2760136 2062744 1...

output:

173576293

result:

ok single line: '173576293'

Test #39:

score: 0
Accepted
time: 42ms
memory: 49480kb

input:

946359 18
1938426 946502 0
1109421 499302 1
1152692 673006 1
494063 2178113 1
1201566 2507536 1
1692566 1553557 1
1310150 477740 1
792360 1806979 1
1759558 187475 1
84020 2032440 0
1506003 630626 1
189624 372553 0
2095586 1575607 1
2573918 356740 0
977824 1303539 0
1925265 1492081 1
1306651 766825 0...

output:

306792650

result:

ok single line: '306792650'

Test #40:

score: 0
Accepted
time: 50ms
memory: 49812kb

input:

990172 18
2581009 2438415 0
253618 1889815 1
2839714 2916704 1
1785448 1405857 0
427861 1808411 0
936198 2036833 1
316673 287152 0
346641 1964107 0
2917722 2096737 1
2382729 2655444 1
2617341 1200163 1
2220938 2696502 1
2545408 1989424 1
2222638 1350552 1
2540734 547602 1
1395790 1591832 1
1102893 1...

output:

892446470

result:

ok single line: '892446470'

Test #41:

score: 0
Accepted
time: 45ms
memory: 48872kb

input:

912866 18
418108 1173906 1
874077 705807 1
560738 2662334 1
351721 2312810 1
1824203 2188835 1
2725328 2293347 1
1799562 672033 0
887018 33608 0
821061 902289 1
494574 114600 0
2168412 202187 0
855113 1543558 1
1543026 72589 1
1187260 2098251 1
2101372 371109 0
2665519 2582992 0
228941 1928120 0
248...

output:

646025094

result:

ok single line: '646025094'

Test #42:

score: 0
Accepted
time: 48ms
memory: 49684kb

input:

977971 18
2503866 2913789 1
2431122 1169386 1
529864 205388 1
870291 1910721 1
1093060 1040933 1
2522659 1060483 1
621147 652353 1
574244 2492725 1
569 2905821 0
480999 218261 0
2731068 1006395 1
1570192 165095 1
2753333 1199546 1
2272891 2280629 0
2570942 2552487 1
2322755 2332098 1
327211 2612350 ...

output:

153762130

result:

ok single line: '153762130'

Test #43:

score: 0
Accepted
time: 49ms
memory: 49536kb

input:

957318 18
1940928 2465208 0
1054779 2801606 0
2395062 1374030 0
1533016 1956911 1
1310845 162035 0
2548018 159801 1
1107836 612425 1
441201 1636841 0
275318 1249835 1
431910 2013618 0
2365726 544615 0
441934 1036058 1
2257206 63694 1
399127 2831627 0
323756 171274 1
1937386 1959193 0
1193568 1170308...

output:

713306158

result:

ok single line: '713306158'

Test #44:

score: 0
Accepted
time: 26ms
memory: 49388kb

input:

945100 18
2245943 982433 0
1105002 129465 1
1836074 836964 0
1983721 2253530 0
2442375 2286358 1
2219019 2426485 1
2451825 721601 1
2330371 424268 0
2395896 2825566 1
197416 2703948 0
241847 707813 0
640430 1458369 0
1032237 1332968 0
2620875 2014440 0
2138413 1584093 1
1543548 2735369 1
701801 1286...

output:

998209075

result:

ok single line: '998209075'

Test #45:

score: 0
Accepted
time: 41ms
memory: 48948kb

input:

914434 18
2543142 2063691 0
1777073 1879866 1
931614 177922 1
713106 119714 1
20821 2354280 0
1165013 1274926 1
533560 2280523 0
1798977 809902 1
2324250 984840 1
2286181 997814 0
794348 742994 0
650199 925194 0
2057439 1565177 0
2029327 1588970 1
698072 2516089 0
2307798 1510283 0
2290388 832427 0
...

output:

576315374

result:

ok single line: '576315374'

Test #46:

score: 0
Accepted
time: 41ms
memory: 49556kb

input:

954712 18
96779 178918 0
2353019 1598971 0
1245847 415915 0
441620 2862655 1
918773 2368386 0
84031 525403 1
442160 976504 0
17438 2305645 0
1244623 2291787 1
2549996 318907 1
552563 1350192 1
884164 2465145 1
2468742 1477922 0
66861 626388 1
85624 1148387 0
1100892 990391 1
2600789 1548628 0
184918...

output:

377319839

result:

ok single line: '377319839'

Test #47:

score: 0
Accepted
time: 40ms
memory: 48692kb

input:

901070 18
2311620 577738 1
122545 2280160 1
2404400 1294964 1
1823660 1285767 0
2568881 1134562 1
1576608 199935 1
1242378 1744205 0
959261 2398065 1
141889 1988778 1
259687 2043014 1
2473845 1934539 0
1013327 647192 0
874258 533233 1
2262930 993430 0
2052433 1879436 1
287319 2237076 1
538767 192261...

output:

80160407

result:

ok single line: '80160407'

Test #48:

score: 0
Accepted
time: 46ms
memory: 48928kb

input:

909332 18
462675 1135617 1
2245921 2235601 0
2400071 143683 1
455747 1171847 1
1527656 1253030 1
2166097 1459350 1
70938 1649764 1
371009 2067923 1
1145077 2699923 0
1819716 395708 1
805681 1721408 1
2470544 190993 0
2323942 1401963 0
2553911 1533910 1
1298383 2079944 1
274562 1506498 1
1943016 3987...

output:

969041355

result:

ok single line: '969041355'

Test #49:

score: 0
Accepted
time: 30ms
memory: 49392kb

input:

953035 18
2640391 1031806 0
2352786 2688868 1
2855324 26689 1
64690 2024610 0
130640 918303 1
692849 2134473 1
174780 1273267 0
2347337 2012126 1
2019558 2005838 1
262223 589812 1
320475 1766253 1
1552255 701306 1
95643 2000484 0
1416658 256861 0
188247 2642303 0
2115928 1323995 1
2812456 2837343 0
...

output:

257818161

result:

ok single line: '257818161'

Test #50:

score: 0
Accepted
time: 45ms
memory: 49984kb

input:

995911 18
982864 2555986 0
1381903 2375594 1
2938087 1903654 1
2765794 2509988 1
1694932 164459 1
1947021 699638 0
2115125 2657716 0
1320779 1118482 0
2185880 1292070 1
193865 344615 1
2383968 357855 1
1511043 1840511 0
1586761 2116193 0
34747 2605994 0
1194932 2013560 0
1240408 2767780 0
450604 293...

output:

871079791

result:

ok single line: '871079791'

Test #51:

score: 0
Accepted
time: 86ms
memory: 49204kb

input:

913676 18
1452876 902227 1
2380396 2392918 1
194457 1839665 1
815525 1694828 1
507467 1325823 1
1470083 2609553 1
1926443 1037379 1
616732 753765 1
700332 2607542 1
683801 1707504 1
1679538 2622110 1
2285098 439017 1
2033493 1614919 1
2174412 113031 1
467206 2214933 1
1388787 2096348 1
2735283 25962...

output:

208252284

result:

ok single line: '208252284'

Test #52:

score: 0
Accepted
time: 74ms
memory: 49476kb

input:

967008 18
721413 2579985 1
2316325 1477802 1
289159 812120 1
2814068 2170046 1
131445 1711399 1
2117970 906974 1
344340 1102107 1
1425485 461879 1
1053375 1837873 1
1464762 2388610 1
121786 1313512 1
1457479 754040 1
1853402 1288252 1
330452 2013286 1
457024 2127438 1
2641119 1001780 1
1531634 1572 ...

output:

143597586

result:

ok single line: '143597586'

Test #53:

score: 0
Accepted
time: 86ms
memory: 49556kb

input:

963139 18
1957713 2661917 1
717569 561806 1
161722 1271316 1
1664694 905551 1
2044745 1868918 1
1981531 1660579 1
1026807 924743 1
716932 2786216 1
1183919 1867102 1
1957014 2339362 1
1105873 2520521 1
1245544 827541 1
703436 655441 1
1124123 1044117 1
2036009 868193 1
1325010 1492347 1
2820789 1075...

output:

739968860

result:

ok single line: '739968860'

Test #54:

score: 0
Accepted
time: 75ms
memory: 49816kb

input:

971358 18
2597800 2562740 1
2193342 2404158 1
1040170 719599 1
1199170 2745092 1
2266603 810786 1
2401966 2483572 1
599842 781811 1
2353067 251257 1
1279380 2723023 1
691674 431627 1
929635 2262771 1
1387879 1143527 1
719489 1002996 1
2065619 2803580 1
2860605 418178 1
671266 814595 1
2147557 188281...

output:

946021765

result:

ok single line: '946021765'

Test #55:

score: 0
Accepted
time: 80ms
memory: 49724kb

input:

983245 18
2856232 947985 1
2565741 199386 1
2416620 947413 1
48516 1064665 1
2715027 339790 1
347961 1118948 1
1699294 1236910 1
1216137 837380 1
2006467 2623362 1
1035952 2117931 1
2775476 2606631 1
1292093 744720 1
2716867 2786252 1
2309362 2713612 1
392628 200693 1
2377237 1357728 1
489031 545901...

output:

860949784

result:

ok single line: '860949784'

Test #56:

score: 0
Accepted
time: 85ms
memory: 49920kb

input:

999579 18
1631959 1568270 1
2248272 915055 1
1910600 2749147 1
2084901 1875211 1
1508636 1349309 1
540677 242678 1
36793 1469538 1
2634039 1656044 1
1479239 734205 1
1063643 2213919 1
2837742 2949372 1
282819 2247425 1
429934 1580071 1
851536 225511 1
762240 2736283 1
1264702 2077209 1
1744510 29899...

output:

695466835

result:

ok single line: '695466835'

Test #57:

score: 0
Accepted
time: 89ms
memory: 49180kb

input:

935581 18
1116715 1628430 1
1818046 845585 1
175446 1142036 1
1586147 1289262 1
97604 1700462 1
313620 915961 1
2753435 2806122 1
1507206 862267 1
1066632 1326493 1
2019505 1581234 1
510156 1781062 1
2559669 1460842 1
706917 1703940 1
2085862 924986 1
45839 727295 1
1509352 1412909 1
2507427 1285139...

output:

14613440

result:

ok single line: '14613440'

Test #58:

score: 0
Accepted
time: 80ms
memory: 49508kb

input:

958657 18
974551 1477229 1
2435746 1382880 1
919813 736216 1
2351099 2509416 1
2716066 549170 1
2215805 2253484 1
1146505 262604 1
1646536 2296974 1
2612875 1922892 1
748999 1514632 1
2270546 65680 1
2721838 2429840 1
2271375 1457282 1
2182273 349756 1
1406673 2635600 1
519017 144430 1
2276412 66272...

output:

103619849

result:

ok single line: '103619849'

Test #59:

score: 0
Accepted
time: 85ms
memory: 48884kb

input:

917209 18
610248 2043525 1
2702069 1464946 1
312630 362625 1
2700890 2741412 1
2465072 1772042 1
2084320 300152 1
273141 2366765 1
2617029 1959933 1
2185215 2221074 1
1526162 20893 1
1685288 1613750 1
847551 369971 1
2632377 2224830 1
742824 208449 1
853192 1212888 1
1836617 367770 1
426429 1856814 ...

output:

718230262

result:

ok single line: '718230262'

Test #60:

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

input:

936461 18
1094584 757821 1
17077 289960 1
814919 1206733 1
2433706 1900983 1
2282426 396399 1
2542999 163008 1
1300462 1417140 1
2705751 1834688 1
757000 1486464 1
2253706 1555279 1
1622420 2671826 1
2055891 279255 1
1210323 1283685 1
240047 863359 1
976173 1965027 1
2701563 524320 1
193812 1012711 ...

output:

71617820

result:

ok single line: '71617820'

Test #61:

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

input:

953664 18
1134320 1997830 1
338345 1328687 1
2121329 779655 1
1505913 963794 1
312782 900668 1
1140923 433445 1
452928 1802703 1
2677830 1780527 1
281575 2343523 1
20481 1153308 1
593316 41341 1
2190565 1845980 1
636606 554621 1
1897953 2295400 1
2204270 2721549 1
590129 163606 1
2455552 2099490 1
2...

output:

678938870

result:

ok single line: '678938870'

Test #62:

score: 0
Accepted
time: 87ms
memory: 49368kb

input:

946010 18
1448208 1338805 1
373958 1085646 1
1889052 1988706 1
676471 275736 1
2706131 987610 1
613375 1454740 1
463121 863328 1
458602 1974330 1
75106 23996 1
1479294 94558 1
1313538 2242444 1
222474 294004 1
155965 2640880 1
2674224 1410916 1
9610 2155324 1
1109474 33068 1
2582188 1668517 1
265867...

output:

304018405

result:

ok single line: '304018405'

Test #63:

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

input:

928695 18
2552081 754111 1
1200907 1827437 1
2257331 1668251 1
980275 1895098 1
1114245 2752735 1
1098105 1991140 1
2476785 1264937 1
1785478 1790763 1
1639636 686021 1
368388 2631997 1
1545176 1157955 1
154942 1999914 1
2306806 443884 1
168961 524390 1
2495045 533254 1
2084577 1894137 1
563360 5995...

output:

808810022

result:

ok single line: '808810022'

Test #64:

score: 0
Accepted
time: 81ms
memory: 49288kb

input:

933271 18
2269566 431427 1
2556156 2355762 1
318635 917541 1
2235204 507000 1
1149868 1919507 1
73789 152941 1
1881362 2779362 1
1430628 790420 1
1317005 2330753 1
1171796 482350 1
1908633 980516 1
790795 1303736 1
1518100 1870744 1
226487 1572594 1
2508867 2191288 1
667936 836852 1
571237 2226798 1...

output:

51066389

result:

ok single line: '51066389'

Test #65:

score: 0
Accepted
time: 81ms
memory: 49852kb

input:

986083 18
870454 794856 1
1800927 1495970 1
2447771 2195976 1
1940935 1201695 1
1171016 635037 1
823002 2821241 1
680973 2625690 1
1254290 1080273 1
255844 1742311 1
1511697 483843 1
2203321 612172 1
2691259 2045709 1
2343556 827578 1
627184 1748567 1
1253107 2805731 1
1042254 2109957 1
2589247 1067...

output:

495654584

result:

ok single line: '495654584'

Test #66:

score: 0
Accepted
time: 50ms
memory: 49768kb

input:

979514 18
979526 979522 1
979517 979524 0
979525 979524 1
979527 979515 1
979524 979519 0
979518 979527 1
979520 979515 1
979515 979524 0
979515 979514 1
979518 979519 1
979523 979522 0
979521 979529 1
979526 979514 0
979525 979527 1
979517 979521 1
979520 979519 1
979526 979524 1
979517 979518 1

output:

0

result:

ok single line: '0'

Test #67:

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

input:

988818 18
988822 988819 0
988820 988831 1
988832 988820 0
988832 988818 1
988833 988822 1
988818 988819 0
988823 988831 0
988830 988822 1
988830 988826 1
988833 988830 1
988830 988828 1
988828 988818 1
988826 988832 1
988824 988830 0
988831 988832 1
988821 988830 1
988829 988827 0
988831 988819 1

output:

701882653

result:

ok single line: '701882653'

Test #68:

score: 0
Accepted
time: 49ms
memory: 49560kb

input:

942378 18
942382 942386 1
942383 942380 0
942383 942388 1
942380 942379 0
942381 942384 1
942384 942386 0
942385 942381 1
942378 942385 0
942390 942387 0
942391 942379 1
942392 942385 1
942392 942382 0
942385 942390 0
942383 942392 1
942390 942392 0
942389 942393 1
942387 942393 0
942379 942381 1

output:

0

result:

ok single line: '0'

Test #69:

score: 0
Accepted
time: 50ms
memory: 49720kb

input:

978142 18
978157 978146 0
978148 978150 1
978156 978153 0
978148 978151 1
978157 978147 1
978155 978143 0
978152 978148 0
978156 978145 0
978142 978152 1
978146 978145 1
978155 978154 1
978157 978149 1
978149 978154 1
978146 978144 1
978142 978149 1
978147 978152 0
978155 978153 1
978144 978150 1

output:

119900766

result:

ok single line: '119900766'

Test #70:

score: 0
Accepted
time: 50ms
memory: 49528kb

input:

957106 18
957114 957110 1
957118 957106 1
957109 957111 0
957112 957107 1
957114 957113 1
957115 957119 1
957118 957120 1
957107 957109 1
957121 957114 0
957118 957107 0
957117 957108 1
957108 957121 1
957121 957112 1
957116 957115 1
957112 957106 1
957106 957110 0
957120 957121 1
957119 957113 0

output:

801599791

result:

ok single line: '801599791'

Test #71:

score: 0
Accepted
time: 46ms
memory: 49208kb

input:

921862 18
921874 921868 1
921864 921872 0
921875 921867 1
921869 921876 1
921865 921877 1
921868 921875 0
921870 921863 1
921874 921870 1
921866 921865 1
921868 921872 1
921877 921866 1
921863 921873 0
921864 921863 0
921866 921873 1
921869 921877 0
921872 921865 1
921873 921865 1
921874 921865 1

output:

0

result:

ok single line: '0'

Test #72:

score: 0
Accepted
time: 50ms
memory: 50004kb

input:

986599 18
986605 986600 1
986604 986602 0
986601 986614 1
986611 986599 1
986603 986602 1
986605 986613 1
986602 986614 1
986614 986603 1
986609 986614 1
986613 986599 1
986613 986603 1
986611 986609 0
986606 986605 1
986601 986606 1
986604 986611 1
986600 986612 1
986610 986612 0
986599 986612 1

output:

758632032

result:

ok single line: '758632032'

Test #73:

score: 0
Accepted
time: 51ms
memory: 49608kb

input:

954922 18
954934 954936 1
954928 954932 1
954925 954929 1
954933 954934 0
954933 954922 1
954928 954934 1
954922 954925 1
954935 954923 1
954937 954936 1
954936 954926 1
954924 954923 1
954937 954933 1
954937 954932 1
954934 954931 1
954925 954924 1
954937 954928 0
954935 954932 1
954922 954924 1

output:

718207285

result:

ok single line: '718207285'

Test #74:

score: 0
Accepted
time: 36ms
memory: 49404kb

input:

942436 18
942443 942437 0
942446 942444 0
942440 942441 0
942451 942442 1
942437 942441 1
942445 942448 1
942447 942450 1
942451 942438 1
942439 942440 0
942450 942444 1
942441 942448 1
942441 942449 1
942443 942445 1
942443 942436 0
942447 942449 1
942444 942451 0
942445 942436 0
942450 942449 0

output:

0

result:

ok single line: '0'

Test #75:

score: 0
Accepted
time: 41ms
memory: 49456kb

input:

946635 18
946637 946647 0
946647 946636 1
946646 946638 1
946637 946644 0
946649 946641 1
946650 946648 0
946638 946644 1
946637 946643 1
946650 946642 1
946636 946640 1
946635 946638 1
946638 946640 1
946649 946650 0
946638 946636 0
946648 946646 1
946642 946647 0
946643 946648 1
946641 946639 1

output:

0

result:

ok single line: '0'

Test #76:

score: 0
Accepted
time: 53ms
memory: 49108kb

input:

908911 18
908925 908911 0
908922 908915 1
908913 908912 1
908913 908917 1
908918 908915 1
908924 908920 1
908915 908924 1
908923 908924 1
908918 908916 1
908922 908920 1
908911 908922 1
908911 908915 0
908917 908916 0
908919 908912 1
908925 908914 1
908924 908911 1
908920 908921 1
908924 908925 1

output:

721415867

result:

ok single line: '721415867'

Test #77:

score: 0
Accepted
time: 43ms
memory: 49136kb

input:

922030 18
922042 922031 1
922036 922031 1
922043 922038 0
922036 922045 0
922032 922036 1
922039 922036 1
922042 922033 1
922030 922045 0
922045 922033 1
922031 922035 1
922038 922042 1
922043 922031 1
922030 922031 1
922039 922042 1
922033 922039 1
922032 922041 0
922040 922043 1
922043 922032 1

output:

756664885

result:

ok single line: '756664885'

Test #78:

score: 0
Accepted
time: 31ms
memory: 50024kb

input:

991153 18
991163 991153 1
991164 991157 1
991164 991168 1
991168 991157 1
991160 991154 1
991161 991164 1
991160 991159 0
991158 991167 1
991158 991160 1
991162 991161 0
991153 991167 1
991153 991162 1
991159 991161 1
991160 991166 0
991155 991168 0
991164 991154 1
991166 991158 0
991168 991154 1

output:

0

result:

ok single line: '0'

Test #79:

score: 0
Accepted
time: 52ms
memory: 49744kb

input:

977622 18
977626 977628 1
977626 977622 1
977637 977624 1
977623 977631 0
977625 977637 1
977625 977622 0
977623 977626 1
977628 977635 0
977629 977637 1
977629 977622 1
977631 977634 0
977636 977625 1
977635 977636 1
977630 977624 1
977631 977635 1
977624 977631 1
977628 977627 1
977633 977634 1

output:

199134475

result:

ok single line: '199134475'

Test #80:

score: 0
Accepted
time: 37ms
memory: 49656kb

input:

976787 18
976794 976800 1
976789 976799 1
976798 976792 0
976797 976800 0
976789 976792 0
976801 976788 0
976798 976795 1
976797 976791 0
976790 976800 1
976790 976799 0
976795 976792 1
976792 976802 0
976789 976801 1
976797 976802 0
976787 976788 1
976789 976795 1
976799 976800 0
976796 976789 1

output:

0

result:

ok single line: '0'

Test #81:

score: 0
Accepted
time: 43ms
memory: 39004kb

input:

11 18
26 31 0
4 2 0
14 25 1
22 17 0
6 1 0
19 5 1
20 21 1
30 9 1
18 23 0
16 15 1
10 33 0
3 27 1
24 8 1
13 12 1
23 27 1
17 2 1
13 21 1
9 19 0

output:

492512019

result:

ok single line: '492512019'

Test #82:

score: 0
Accepted
time: 43ms
memory: 39000kb

input:

10 18
16 21 1
14 2 1
15 22 1
26 1 0
28 13 1
19 8 0
3 27 1
24 25 1
12 9 1
20 17 1
4 18 0
23 10 1
29 5 1
7 6 1
27 7 1
1 28 1
26 17 1
21 18 1

output:

352823833

result:

ok single line: '352823833'

Test #83:

score: 0
Accepted
time: 35ms
memory: 38644kb

input:

12 18
20 29 1
1 23 1
10 16 1
3 13 0
32 26 1
6 22 0
18 31 1
24 2 0
35 7 1
25 21 0
34 33 1
30 28 1
14 11 0
36 5 1
15 27 1
28 33 0
8 21 1
14 25 0

output:

0

result:

ok single line: '0'

Test #84:

score: 0
Accepted
time: 35ms
memory: 38772kb

input:

12 18
2 1 1
29 6 1
30 19 1
17 22 1
35 25 0
21 9 0
12 20 1
23 15 1
33 5 1
3 18 1
36 11 0
27 16 1
32 4 0
26 24 1
12 9 0
4 17 0
6 17 1
8 36 1

output:

133844332

result:

ok single line: '133844332'

Test #85:

score: 0
Accepted
time: 39ms
memory: 38660kb

input:

13 18
29 16 0
9 10 0
15 3 1
37 25 1
8 1 1
23 36 0
22 33 0
21 17 0
6 31 1
34 38 0
11 12 1
4 18 1
32 13 1
20 5 1
6 3 0
21 36 1
14 39 0
24 13 1

output:

652203996

result:

ok single line: '652203996'

Test #86:

score: 0
Accepted
time: 40ms
memory: 39004kb

input:

13 18
2 26 1
22 3 1
36 18 1
34 9 0
13 4 0
30 31 1
6 17 1
35 5 1
20 38 0
1 15 1
32 27 1
33 14 1
23 24 1
19 39 0
4 31 1
28 11 1
8 35 1
6 32 0

output:

53814078

result:

ok single line: '53814078'

Test #87:

score: 0
Accepted
time: 34ms
memory: 39008kb

input:

12 18
32 16 0
4 6 0
31 36 1
5 14 0
9 34 1
3 25 1
2 35 0
29 8 1
18 26 0
21 33 1
17 19 0
1 24 1
22 7 1
12 30 0
15 24 0
18 5 1
30 7 1
20 22 1

output:

548943554

result:

ok single line: '548943554'

Test #88:

score: 0
Accepted
time: 43ms
memory: 39008kb

input:

13 18
12 11 0
27 13 0
24 32 0
34 7 1
38 1 1
22 21 1
36 33 1
31 16 0
15 29 1
19 25 1
35 17 1
20 26 1
10 6 1
14 3 1
35 30 0
9 1 1
27 16 0
38 30 1

output:

0

result:

ok single line: '0'

Test #89:

score: 0
Accepted
time: 32ms
memory: 38980kb

input:

12 18
10 6 0
23 25 0
11 32 1
17 12 1
16 35 1
26 3 1
36 2 1
27 4 1
18 29 1
19 20 1
21 8 1
15 13 1
34 14 1
24 9 1
35 20 0
9 25 1
6 13 0
19 6 1

output:

298088465

result:

ok single line: '298088465'

Test #90:

score: 0
Accepted
time: 50ms
memory: 38784kb

input:

11 18
21 19 0
15 7 1
17 11 1
16 8 1
30 6 1
32 18 1
27 33 1
3 5 1
2 13 1
24 22 1
26 1 1
23 28 1
4 31 1
25 9 1
11 21 0
25 6 1
16 31 1
1 8 0

output:

781689432

result:

ok single line: '781689432'

Test #91:

score: 0
Accepted
time: 38ms
memory: 38780kb

input:

12 18
11 22 1
3 29 0
32 23 1
36 28 0
10 12 1
27 26 1
25 17 1
16 31 1
33 14 0
6 13 1
34 18 1
20 7 1
19 8 0
1 21 1
27 15 1
12 5 0
17 33 0
12 9 1

output:

589038085

result:

ok single line: '589038085'

Test #92:

score: 0
Accepted
time: 52ms
memory: 39008kb

input:

12 18
29 7 1
18 12 1
22 10 1
25 30 1
36 24 1
3 31 1
32 6 1
27 5 1
34 1 1
28 2 1
13 35 0
16 8 1
14 20 1
11 19 1
29 10 1
27 9 0
13 1 1
29 15 1

output:

277483562

result:

ok single line: '277483562'

Test #93:

score: 0
Accepted
time: 43ms
memory: 38720kb

input:

10 18
25 26 0
5 22 1
2 15 0
1 20 1
29 13 0
16 4 1
11 23 0
14 12 0
30 3 1
9 18 1
19 17 1
8 27 1
10 6 1
21 24 0
26 28 1
4 26 1
23 7 1
7 27 0

output:

641715137

result:

ok single line: '641715137'

Test #94:

score: 0
Accepted
time: 44ms
memory: 38780kb

input:

10 18
26 14 0
18 7 1
24 29 1
15 30 0
2 3 1
17 27 1
5 11 1
13 19 0
10 23 0
12 1 1
28 20 1
22 6 1
4 8 1
16 9 1
13 16 1
25 13 1
6 14 1
25 28 1

output:

699418593

result:

ok single line: '699418593'

Test #95:

score: 0
Accepted
time: 40ms
memory: 38716kb

input:

13 18
4 8 1
1 33 1
38 31 0
20 34 1
35 25 1
17 39 1
18 11 1
6 27 0
15 7 0
30 12 1
16 10 1
21 14 0
24 28 1
13 19 1
39 7 1
32 24 1
20 13 1
28 37 1

output:

93443267

result:

ok single line: '93443267'

Extra Test:

score: 0
Extra Test Passed