QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100080 | #6329. Colorful Graph | tikhon# | TL | 1655ms | 10964kb | C++17 | 2.8kb | 2023-04-24 16:55:49 | 2023-04-24 16:55:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
const int MAXN = 7070;
vector<int> G[MAXN];
vector<int> GT[MAXN];
vector<int> order;
bool used[MAXN];
void dfs1(int v) {
used[v] = true;
for (int u : G[v]) {
if (!used[u])
dfs1(u);
}
order.emplace_back(v);
}
int id[MAXN];
void dfs2(int v, int c) {
id[v] = c;
for (int u : GT[v]) {
if (id[u] == -1)
dfs2(u, c);
}
}
vector<int> GG[MAXN];
bitset<MAXN> real_g[MAXN];
int was[MAXN];
int couple[MAXN];
bool khun(int v, int c) {
if (was[v] == c)
return false;
was[v] = c;
for (int i = real_g[v]._Find_first(); i < real_g[v].size(); i = real_g[v]._Find_next(i)) {
if (couple[i] == -1) {
couple[i] = v;
return true;
}
}
for (int i = real_g[v]._Find_first(); i < real_g[v].size(); i = real_g[v]._Find_next(i)) {
if (khun(couple[i], c)) {
couple[i] = v;
return true;
}
}
return false;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
G[a - 1].emplace_back(b - 1);
GT[b - 1].emplace_back(a - 1);
}
fill(used, used + n, false);
for (int i = 0; i < n; ++i) {
if (!used[i])
dfs1(i);
}
reverse(order.begin(), order.end());
fill(id, id + n, -1);
int cnt = 0;
for (int v : order) {
if (id[v] != -1)
continue;
dfs2(v, cnt);
++cnt;
}
for (int v = 0; v < n; ++v) {
for (int u : G[v]) {
if (id[u] == id[v])
continue;
GG[id[v]].emplace_back(id[u]);
}
}
for (int i = cnt - 1; i >= 0; --i) {
for (int u : GG[i])
real_g[i] |= real_g[u];
real_g[i][i] = true;
}
for (int i = 0; i < cnt; ++i)
real_g[i][i] = false;
fill(was, was + cnt, -1);
fill(couple, couple + cnt, -1);
for (int i = 0; i < cnt; ++i)
khun(i, i);
vector<int> real_color(cnt, -1);
int ans = 0;
for (int i = 0; i < cnt; ++i) {
if (real_color[i] != -1)
continue;
int j = i;
while (couple[j] != -1 && real_color[j] == -1) {
j = couple[j];
}
if (real_color[j] == -1) {
real_color[j] = ans;
++ans;
}
int cur = i;
while (real_color[cur] == -1) {
real_color[cur] = real_color[j];
cur = couple[cur];
}
}
for (int i = 0; i < n; ++i)
cout << 1 + real_color[id[i]] << ' ';
cout << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3964kb
input:
5 5 1 4 2 3 1 3 2 5 5 1
output:
1 1 1 2 1
result:
ok AC
Test #2:
score: 0
Accepted
time: 0ms
memory: 3920kb
input:
5 7 1 2 2 1 4 3 5 1 5 4 4 1 4 5
output:
2 2 1 1 1
result:
ok AC
Test #3:
score: 0
Accepted
time: 0ms
memory: 4004kb
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: 40ms
memory: 10684kb
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:
1750 569 1623 1022 1383 1749 1748 1072 1747 714 1342 373 1747 157 730 1746 596 1745 120 622 1690 1247 135 1227 1184 1744 1743 996 1500 1742 153 325 1741 1740 257 1241 1235 1739 111 1738 1427 1736 1737 252 1736 1625 1735 1060 1734 1733 1286 1732 1018 355 1546 476 850 1731 141 1730 72 564 1484 1205 16...
result:
ok AC
Test #5:
score: 0
Accepted
time: 29ms
memory: 10648kb
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:
2088 2098 827 544 469 1973 1566 1831 162 2236 2252 862 346 1945 1305 2333 1649 1371 1117 572 2332 1366 1951 1980 1550 242 706 2246 1570 1162 647 1564 1369 737 2331 2330 1887 983 332 994 2329 1624 2160 2328 1269 2327 528 2326 2325 2211 1616 2181 926 1863 502 593 2324 2323 2322 2321 204 113 2320 2202 ...
result:
ok AC
Test #6:
score: 0
Accepted
time: 52ms
memory: 10640kb
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:
2333 2332 681 997 258 2331 1343 1853 1885 2330 1564 2329 2328 471 1789 534 2327 857 1737 1986 2002 2326 2325 516 1538 1109 2112 796 2324 2323 1682 2322 1010 2177 670 2321 1138 781 1499 2320 652 811 1827 2319 1055 1701 1942 1030 2318 116 872 2317 2037 118 1971 990 904 2316 414 14 2315 165 2314 479 15...
result:
ok AC
Test #7:
score: 0
Accepted
time: 41ms
memory: 10912kb
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:
1750 1406 1664 23 1501 1680 1522 1749 1397 1748 1576 155 56 712 1347 308 203 31 872 1747 406 1220 956 1144 384 247 323 744 1746 1745 1024 1744 885 233 1561 1434 215 1525 378 1052 1113 282 872 925 1743 1453 1742 1275 1741 1354 105 1188 1740 1739 970 1738 256 709 968 807 1737 1673 987 1638 792 1736 14...
result:
ok AC
Test #8:
score: 0
Accepted
time: 27ms
memory: 10560kb
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:
3499 3498 3497 3496 2428 3495 3494 834 2456 256 197 555 3493 3067 3492 3491 3490 2525 3489 3488 3376 3487 3486 809 3485 3484 3483 3482 3481 1826 3480 2434 3479 3478 307 3477 1887 3042 3476 2986 2530 3475 3474 2297 413 3473 3472 3471 3470 3469 979 1949 8 3468 3238 1106 3467 3466 3465 3464 3463 2924 3...
result:
ok AC
Test #9:
score: 0
Accepted
time: 1ms
memory: 10236kb
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: 0
Accepted
time: 7ms
memory: 10876kb
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:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok AC
Test #11:
score: 0
Accepted
time: 1006ms
memory: 10964kb
input:
7000 6999 33 3147 5877 4807 3116 4168 1651 2456 624 1740 6440 3058 6414 489 1023 2523 706 93 5523 598 4211 6063 3570 6840 6566 2971 6614 1907 5893 4389 4022 2527 5096 2345 4682 2134 188 5597 695 4285 1344 3832 3534 879 6574 6252 3759 3444 2167 85 5630 6600 3158 4404 6389 689 4871 6719 4295 6008 3437...
output:
60 24 2 2 60 44 2 52 2 2 2 2 2 71 2 65 2 22 2 2 22 2 22 2 2 2 2 2 2 2 2 2 70 2 2 56 24 24 2 2 2 39 41 2 69 2 24 2 2 48 2 2 2 2 2 61 2 2 2 24 11 24 65 2 2 2 2 4 24 2 22 22 2 2 21 2 21 22 10 2 60 32 2 2 12 53 2 2 45 2 65 2 2 2 2 19 68 2 5 2 2 2 2 65 2 2 60 2 2 24 2 2 2 31 65 2 44 2 2 2 2 10 41 2 44 2 ...
result:
ok AC
Test #12:
score: 0
Accepted
time: 1655ms
memory: 8368kb
input:
7000 6999 1247 5150 3318 2013 5686 1615 6145 6521 5717 94 2787 3443 2648 4875 5332 5934 1897 1651 4640 2183 1750 6964 148 5228 745 2814 474 1165 496 6735 180 3412 2723 3374 6200 4361 497 5328 1928 5998 5648 1261 5090 4723 1715 706 2499 897 6569 6204 6039 2787 2882 5044 5767 4256 975 1877 1857 4453 6...
output:
1 274 1 130 1 1 130 1 57 1 171 191 57 1 1 227 1 1 1 1 1 1 1 1 1 1 222 1 64 273 1 1 1 1 1 1 209 1 57 1 1 1 259 1 1 211 1 1 1 145 43 272 1 1 1 1 1 146 143 1 203 160 1 1 1 236 1 1 193 145 1 7 160 1 1 1 1 1 271 43 1 1 1 1 1 229 1 1 1 1 24 1 1 1 266 1 1 1 1 1 61 1 1 83 80 1 1 7 1 255 16 1 1 201 1 47 1 1 ...
result:
ok AC
Test #13:
score: -100
Time Limit Exceeded
input:
7000 6999 2349 199 5295 2831 6143 2006 3212 3198 6956 3807 732 4838 5069 1027 5744 3479 6 5301 5687 4452 4201 1151 1353 4884 548 3506 6094 4799 4950 6939 5234 817 652 1314 979 6984 5771 1851 398 1322 2294 4298 847 3929 6833 183 2904 6745 4797 3874 94 315 4282 582 6591 5037 962 147 799 908 2593 5547 ...