QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132395#6329. Colorful GraphUrgantTeam#RE 1ms4664kbC++143.0kb2023-07-29 19:53:162023-07-29 19:53:20

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 19:53:20]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4664kb
  • [2023-07-29 19:53:16]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

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;

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;
    for (int i = 1; i <= cmp; i++) {
        for (int j = 1; j <= cmp; j++) {
            if (Gz[i][j] && !one[i] && !two[j]) {
                one[i] = j, two[j] = i, free_righ[j] = 0;
            }
        }
    }
    assert(cmp <= 1000);
    while (find) {
        find = 0;
        bad++;
        for (int i = 1; i <= cmp; i++) {
            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;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4444kb

input:

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

output:

1 1 2 1 2 

result:

ok AC

Test #2:

score: 0
Accepted
time: 1ms
memory: 4664kb

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: 1ms
memory: 4496kb

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: -100
Dangerous Syscalls

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:


result: