QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426355 | #6329. Colorful Graph | james1BadCreeper | WA | 845ms | 9668kb | C++17 | 1.8kb | 2024-05-31 08:36:32 | 2024-05-31 08:36:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 7e3 + 5;
int n, m;
int A[N], B[N];
vector<int> G[N];
int dfn[N], low[N], num, col[N], cnt, st[N], tot, ins[N];
void tarjan(int x) {
dfn[x] = low[x] = ++num; ins[st[++tot] = x] = 1;
for (int y : G[x])
if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
else if (ins[y]) low[x] = min(low[x], dfn[y]);
if (dfn[x] == low[x]) {
++cnt; int y;
do ins[y = st[tot--]] = 0, col[y] = cnt; while (y != x);
}
}
bitset<N> E[N], vis;
int mch[N], c[N];
inline bool dfs(int x) {
auto tmp = E[x] & vis;
for (int y = tmp._Find_first(); y != tmp.size(); y = tmp._Find_next(y)) {
vis.set(y, 0);
if (!mch[y] || dfs(y)) return mch[y] = x, 1;
}
return 0;
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> A[i] >> B[i];
G[A[i]].emplace_back(B[i]);
}
for (int i = 1; i <= n; ++i)
if (!dfn[i]) tarjan(i);
for (int i = 1; i <= m; ++i) if (col[A[i]] != col[B[i]])
E[col[A[i]]][col[B[i]]] = 1;
for (int k = 1; k <= cnt; ++k)
for (int i = 1; i <= cnt; ++i)
if (E[i][k]) E[i] |= E[k];
int ans = cnt;
vis.set(); vis.set(0, 0);
for (int i = 1; i <= cnt; ++i) if (dfs(i)) {
vis.set(); vis.set(0, 0);
--ans;
}
int res = 0;
vector<int> son(cnt + 1);
for (int i = 1; i <= cnt; ++i) son[mch[i]] = i;
for (int i = 1; i <= cnt; ++i)
if (mch[i] == 0) {
c[i] = ++res;
int x = i; while (son[x]) c[x = son[x]] = res;
}
for (int i = 1; i <= n; ++i) cout << c[col[i]] << " \n"[i == n];
// cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3784kb
input:
5 5 1 4 2 3 1 3 2 5 5 1
output:
2 2 1 2 1
result:
ok AC
Test #2:
score: 0
Accepted
time: 1ms
memory: 3780kb
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: 1ms
memory: 5888kb
input:
8 6 6 1 3 4 3 6 2 3 4 1 6 4
output:
1 1 1 1 2 1 3 4
result:
ok AC
Test #4:
score: -100
Wrong Answer
time: 845ms
memory: 9668kb
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:
1 350 1208 68 136 137 372 1376 74 2141 985 718 373 898 2250 489 868 569 1651 588 924 658 1377 2081 365 570 571 557 1564 572 641 725 573 574 1343 1345 1823 575 1179 576 2291 486 577 823 578 1854 579 1243 580 581 1000 582 1058 328 315 106 1085 583 1186 584 703 218 323 1824 193 585 1955 1767 2158 586 5...
result:
wrong answer Integer 2141 violates the range [1, 1750]