QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132400#6329. Colorful GraphUrgantTeam#WA 6073ms16772kbC++233.5kb2023-07-29 20:01:182023-07-29 20:01:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-29 20:01:21]
  • 评测
  • 测评结果:WA
  • 用时:6073ms
  • 内存:16772kb
  • [2023-07-29 20:01:18]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(time(0));
int const maxn = 7005;
vector < int > g[maxn], G[maxn], ts, go[maxn], res[2 * maxn];
int used[2 * maxn], cmp, numb[maxn], bad;
vector < int > in[maxn];
bitset < maxn > Gz[maxn];
int one[maxn], two[maxn], out[maxn];
bitset < maxn > free_righ, USED;

void answer(int v, int mx, int cmp) {
    used[v] = bad;
    if (v <= cmp) {
        for (auto key : in[v]) out[key] = mx;
    }
    for (auto key : res[v]) {
        if (used[key] != bad) answer(key, mx, cmp);
    }
}

void dfs1(int v) {
    used[v] = 2, numb[v] = cmp, in[cmp].push_back(v);
    for (auto u : g[v]) {
        if (used[u] == 1) {
            dfs1(u);
        } else if (numb[u] != cmp) {
            go[cmp].push_back(numb[u]);
        }
    }
}

void dfs(int v) {
    used[v] = 1;
    for (auto u : G[v]) if (!used[u]) dfs(u);
    ts.push_back(v);
}

void dfs2(int v, int start) {
    used[v] = bad;
    if (v != start) Gz[start][v] = 1;
    for (auto u : go[v]) {
        if (used[u] != bad) dfs2(u, start);
    }
}

bool calc(int v) {
    used[v] = bad;
    int pos = (Gz[v]&free_righ)._Find_first();
    if (pos <= cmp) {
        one[v] = pos, two[pos] = v, free_righ[pos] = 0;
        return true;
    }
    for (int u = Gz[v]._Find_first(); u <= cmp; u = Gz[v]._Find_next(u)) {
        if (used[two[u]] != bad && calc(two[u])) {
            one[v] = u, two[u] = v;
            return true;
        }
    }
    return false;
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> u >> v;
        g[u].push_back(v);
        G[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) if (!used[i]) dfs(i);
    reverse(ts.begin(), ts.end());
    for (auto key : ts) {
        if (used[key] != 2) {
            cmp++;
            dfs1(key);
        }
    }
    bad = 2;
    for (int i = 1; i <= cmp; i++) {
        bad++;
        dfs2(i, i);
    }
    int find = 1;
    for (int i = 1; i <= cmp; i++) free_righ[i] = 1;
    vector < int > Q;
    for (int i = 1; i <= cmp; i++) {
        int ok = 0;
        for (int j = 1; j <= cmp; j++) {
            if (Gz[i][j] || Gz[j][i]) {
                ok = 1;
                break;
            }
        }
        if (ok) Q.push_back(i);
    }
    shuffle(Q.begin(), Q.end(), rnd);
    for (auto i : Q) {
        for (auto j : Q) {
            if (Gz[i][j] && !one[i] && !two[j]) {
                one[i] = j, two[j] = i, free_righ[j] = 0;
            }
        }
    }
    while (find) {
        if (1.0 * clock() / CLOCKS_PER_SEC > 6) break;
        find = 0;
        bad++;
        for (auto i : Q) {
            if (used[i] != bad && !one[i] && calc(i)) {
                find = 1;
            }
        }
    }
    int mx = 0;
    bad++;
    for (int i = 1; i <= cmp; i++) {
        if (one[i]) res[i].push_back(one[i] + cmp), res[one[i] + cmp].push_back(i);
        res[i].push_back(i + cmp), res[i + cmp].push_back(i);
    }
    for (int i = 1; i <= cmp; i++) {
        if (used[i] != bad) {
            mx++;
            answer(i, mx, cmp);
        }
    }
    for (int i = 1; i <= n; i++) cout << out[i] << " ";
    cout << '\n';
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 6212kb

input:

5 5
1 4
2 3
1 3
2 5
5 1

output:

2 2 2 1 2 

result:

ok AC

Test #2:

score: 0
Accepted
time: 2ms
memory: 5848kb

input:

5 7
1 2
2 1
4 3
5 1
5 4
4 1
4 5

output:

2 2 1 2 2 

result:

ok AC

Test #3:

score: 0
Accepted
time: 2ms
memory: 6580kb

input:

8 6
6 1
3 4
3 6
2 3
4 1
6 4

output:

4 4 4 4 3 4 2 1 

result:

ok AC

Test #4:

score: 0
Accepted
time: 519ms
memory: 16772kb

input:

7000 6999
4365 4296
2980 3141
6820 4995
4781 24
2416 5844
2940 2675
3293 2163
3853 5356
262 6706
1985 1497
5241 3803
353 1624
5838 4708
5452 3019
2029 6161
3849 4219
1095 1453
4268 4567
1184 1857
2911 3977
1662 2751
6353 6496
2002 6628
1407 4623
425 1331
4445 4277
1259 3165
4994 1044
2756 5788
5496 ...

output:

615 20 1528 1504 1543 1648 1030 949 1034 1750 1490 28 1696 1312 1429 165 1749 1533 359 1748 818 1747 1489 920 1353 643 419 940 1574 410 1746 459 163 1519 314 625 1745 333 464 1261 1744 1358 378 1743 255 1742 267 252 464 86 646 1483 1741 261 1730 1740 431 49 1739 1243 437 1233 1179 1529 1738 424 177 ...

result:

ok AC

Test #5:

score: 0
Accepted
time: 374ms
memory: 15840kb

input:

7000 6999
4832 1603
5984 6985
5355 3687
6007 2170
5984 3486
3267 2189
538 2123
4343 4553
5855 6168
5984 257
4239 2304
5984 2063
3298 1869
5984 6353
5984 2018
5984 5387
5984 3382
3164 3978
2690 2816
4810 2638
5984 3773
5984 1634
5984 2786
5984 3671
5984 5140
2943 5721
5984 414
1105 4060
3093 796
5984...

output:

1703 2070 2333 2332 2331 1358 2330 2329 1614 1371 1736 1010 55 2328 1611 1258 864 1110 634 2327 1476 2326 2325 2324 513 2212 2323 2322 2321 2320 2319 1154 10 1048 1249 339 2318 1303 2317 2316 1033 2315 2314 176 2313 1539 2312 1223 675 2311 2310 2309 2308 2307 2306 283 1071 2250 892 1036 1733 118 988...

result:

ok AC

Test #6:

score: 0
Accepted
time: 177ms
memory: 11700kb

input:

7000 6999
1649 5337
1701 3344
4394 2172
3330 39
5932 1141
5381 5340
5453 3300
125 2172
6810 5263
804 2172
6635 2172
676 4740
3015 1183
1710 5769
611 5915
3419 1581
2094 2172
4508 2172
6604 2433
6113 1466
1604 696
1518 1123
1287 2940
4825 2172
5130 4524
2693 2172
106 2172
5157 2172
3693 2172
5198 217...

output:

670 936 2333 2332 1899 149 2331 2330 2329 1214 225 551 658 1222 905 2328 2295 2327 2326 2325 1034 1887 1707 2324 1846 2323 533 2322 1956 571 2321 2137 2320 805 2319 2249 334 2318 2317 1706 587 2316 2315 1674 486 1827 1926 2314 834 2200 2313 1796 2312 2311 101 2310 809 1286 2309 587 2271 350 1200 230...

result:

ok AC

Test #7:

score: 0
Accepted
time: 193ms
memory: 12136kb

input:

7000 6999
2896 6321
881 2623
5058 2623
4833 2623
4669 2623
4781 5007
1447 2623
4781 4768
4781 3834
2758 4792
797 5055
3784 2623
4781 5510
6606 3040
597 3459
4136 2037
1291 3989
4781 837
4781 4379
5637 2053
1642 2665
4781 4664
4781 952
4924 2511
4781 4201
4781 2352
4781 5362
3901 197
137 2623
2706 19...

output:

1625 1307 315 121 805 326 459 1440 1750 1704 233 971 698 137 283 1749 1748 372 1348 1033 1747 1695 1746 1745 1744 1743 1742 1741 31 1649 1747 933 933 758 368 1347 1740 1739 1685 1738 1151 1573 1737 1446 307 1328 1000 1088 4 518 1638 432 1519 729 712 1130 1363 850 1736 1188 1508 1004 88 1735 1573 160...

result:

ok AC

Test #8:

score: 0
Accepted
time: 65ms
memory: 9324kb

input:

6999 6998
1269 3969
1269 2429
1269 2609
1269 2515
1269 6166
1269 6614
3108 1269
2105 1269
4670 1269
578 1269
4661 1269
1421 1269
2576 1269
6152 1269
1269 6636
3011 1269
305 1269
5189 1269
1683 1269
6861 1269
1269 5798
1499 1269
282 1269
914 1269
80 1269
677 1269
701 1269
1269 359
6521 1269
1269 1754...

output:

3026 1229 2494 2851 3499 1128 2840 3498 3497 3496 3495 3494 2005 3493 2969 1727 2273 3492 3348 799 3491 1032 801 3490 1265 2700 3217 2539 2698 3489 2343 3488 2069 3141 3487 3427 3486 3485 2114 3484 3483 2284 1782 3482 3481 1242 568 3338 1650 171 3480 3479 3478 2212 3477 3476 935 242 2487 594 2541 34...

result:

ok AC

Test #9:

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

input:

7000 0

output:

7000 6999 6998 6997 6996 6995 6994 6993 6992 6991 6990 6989 6988 6987 6986 6985 6984 6983 6982 6981 6980 6979 6978 6977 6976 6975 6974 6973 6972 6971 6970 6969 6968 6967 6966 6965 6964 6963 6962 6961 6960 6959 6958 6957 6956 6955 6954 6953 6952 6951 6950 6949 6948 6947 6946 6945 6944 6943 6942 6941 ...

result:

ok AC

Test #10:

score: -100
Wrong Answer
time: 6073ms
memory: 15920kb

input:

7000 6999
3138 1903
3285 5919
6182 1430
1164 961
1577 6445
1390 3384
935 5723
6614 6387
4799 2877
3915 5128
5366 5455
2287 3941
2053 2326
4022 6993
488 2922
4327 4701
4674 3221
1666 4773
4356 3232
3888 937
4318 6942
577 1299
4491 1938
5154 1254
790 5532
4286 5478
2918 6725
2853 304
2554 5207
5140 77...

output:

20 31 33 101 17 46 103 40 8 9 31 91 87 128 37 23 64 77 21 15 101 100 53 82 21 4 130 14 44 90 80 103 65 47 65 75 33 83 43 16 73 39 36 7 96 84 129 55 69 26 38 126 30 45 21 11 8 22 26 25 61 18 94 44 131 42 114 68 66 9 93 22 8 8 96 45 24 132 38 124 92 8 123 10 107 67 119 16 116 78 79 83 5 42 8 16 69 74 ...

result:

wrong answer Integer 20 violates the range [1, 1]