QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#426373#6329. Colorful Graphjames1BadCreeperWA 1ms3732kbC++171.9kb2024-05-31 09:17:232024-05-31 09:17:24

Judging History

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

  • [2024-05-31 09:17:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3732kb
  • [2024-05-31 09:17:23]
  • 提交

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; 
// bool vis[N]; 
int mch[N], c[N]; 

inline bool dfs(int x) {
    auto tmp = E[x] & vis; 
    // if (vis[x]) return 0; vis[x] = 1; 
    for (int y = tmp._Find_first(); y != tmp.size(); y = tmp._Find_next(y)) {
        if (!mch[y] || (vis.reset(mch[y]), dfs(mch[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.reset(0); 
    for (int i = 1; i <= cnt; ++i)
        if (vis.reset(i), dfs(i)) {
            vis.set(); vis.reset(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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3732kb

input:

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

output:

3 5 2 1 4

result:

wrong answer Integer 3 violates the range [1, 2]