QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#68262#2760. SimurghLenstar0 1805ms15216kbC++146.1kb2022-12-15 15:37:162022-12-15 15:37:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-15 15:37:18]
  • 评测
  • 测评结果:0
  • 用时:1805ms
  • 内存:15216kb
  • [2022-12-15 15:37:16]
  • 提交

answer

#include <bits/stdc++.h>
#include "simurgh.h"

using pii = std::pair<int, int>;
#define mkp(a, b) std::make_pair(a, b)

const int N = 5e2 + 10, M = N * N;

std::vector<int> Gold_Roads, Spanning_Tree;
int tot = 1, fir[N], nex[M], got[M], idx[M], Map[N][N], n;

inline void AddEdge(int u, int v, int I) {
    nex[++tot] = fir[u], fir[u] = tot, got[tot] = v, idx[tot] = I;
    nex[++tot] = fir[v], fir[v] = tot, got[tot] = u, idx[tot] = I;
}

int par[N], vis[M], dep[N], Vis[M], par_edge[N], TYPE[M], w[N], f[N], U[M], V[M], d[N];

inline void dfs(int u) {
    vis[u] = true;

    for (int i = fir[u]; i; i = nex[i])
        if (!vis[got[i]])
            Spanning_Tree.push_back(idx[i]), dfs(got[i]);
}

inline int find(int u) {
    return f[u] == u ? u : f[u] = find(f[u]);
}

inline int count(std::vector<int> E) {
    if (E.size() == n - 1)
        return count_common_roads(E);

    // assert(E.size() < n);
    int s = 0, sum = 0;

    for (int i = 0; i < n; ++i)
        f[i] = i;

    for (int i = 0; i < E.size(); ++i) {
        int u = U[E[i]], v = V[E[i]];
        // assert(find(u) != find(v));
        f[find(u)] = find(v);
    }

    // printf("E.size() = %d\n", E.size());
    // for (int i = 0; i < n; ++i) if (find(i) == i) ++sum;
    // printf("%d\n", sum);
    for (auto i : Spanning_Tree) {
        int u = find(U[i]), v = find(V[i]);

        if (u != v)
            f[u] = v, s += TYPE[i], E.push_back(i);
    }

    // assert(E.size() < n);
    return count_common_roads(E) - s;
}

inline std::vector<int> ring(std::vector<int> bas, int ban) {
    std::vector<int> res;

    for (auto dat : bas)
        if (dat != ban)
            res.push_back(dat);

    return res;
}

inline void solve(int u, int v, int edg_num) {
    int flg = 0, edg = 0, cont = 1;
    std::vector<int> query;
    memset(Vis, 0, sizeof(Vis));

    for (int U = u; U != v; U = par[U]) {
        Vis[par_edge[U]] = true;

        if (TYPE[par_edge[U]] == -1)
            cont = false;

        if (TYPE[par_edge[U]] != -1)
            flg = true, edg = par_edge[U];
    }

    if (cont) {
        return;
    }

    if (flg) {
        std::vector<int> bas = Spanning_Tree;
        bas.push_back(edg_num);
        int sum = count(ring(bas, edg));

        for (int U = u; U != v; U = par[U]) {
            int e = par_edge[U];

            if (TYPE[e] == -1) {
                std::vector<int> query = ring(bas, e);
                int s = count(query);
                TYPE[e] = TYPE[edg] + s - sum;

                if (TYPE[e] == -1) {
                    // puts("");
                }

                // assert(TYPE[e] != -1);
            }
        }
    } else {
        std::vector<int> bas = Spanning_Tree;
        int Min = count(bas), flg = true;

        for (int U = u; U != v; U = par[U]) {
            int e = par_edge[U];
            std::vector<int> query = ring(bas, e);
            query.push_back(edg_num);
            w[U] = count(query), flg &= w[U] == Min, Min = std::min(Min, w[U]);
        }

        for (int U = u; U != v; U = par[U])
            TYPE[par_edge[U]] = flg ? 0 : 1 - w[U] + Min;
    }

    // for (int i = 0; i < 6; ++i) printf("%d ", TYPE[i]); puts("");
    // std::cout << lxndanfdiadsfnslkjGrader::q << std::endl;
}

inline void dfs(int u, int fa) {
    par[u] = fa, vis[u] = true;

    if (fa != -1)
        dep[u] = dep[fa] + 1;

    for (int i = fir[u]; i; i = nex[i])
        if (got[i] != fa) {
            if (!vis[got[i]])
                par_edge[got[i]] = idx[i], dfs(got[i], u);
            else if (dep[u] > dep[got[i]])
                solve(u, got[i], idx[i]);
        }
}

inline int solve(int u, std::vector<int> vec) {
    if (vec.size() == 1)
        return vec[0];

    int mid = vec.size() / 2;
    std::vector<int> E;

    for (int i = 0; i < mid; ++i)
        E.push_back(Map[u][vec[i]]);

    if (count(E)) {
        std::vector<int> v;

        for (int i = 0; i < mid; ++i)
            v.push_back(vec[i]);

        return solve(u, v);
    } else {
        std::vector<int> v;

        for (int i = mid; i < vec.size(); ++i)
            v.push_back(vec[i]);

        return solve(u, v);
    }
}

inline int solve(int u) {
    std::vector<int> vec;

    for (int i = fir[u]; i; i = nex[i])
        if (TYPE[idx[i]] == -1)
            vec.push_back(got[i]);

    return solve(u, vec);
}

std::vector<int> find_roads(int N, std::vector<int> U, std::vector<int> V) {
    // freopen("3173.out", "w", stdout);
    int m = U.size();
    n = N;

    for (int i = 0; i < m; ++i) {
        int u = U[i], v = V[i];
        AddEdge(u, v, i);
        Map[u][v] = Map[v][u] = i;
        ::U[i] = u, ::V[i] = v;
    }

    memset(TYPE, -1, sizeof(TYPE));
    dfs(0), memset(vis, 0, sizeof(vis)), dfs(0, -1);

    // std::cerr << lxndanfdiadsfnslkjGrader::q << std::endl;
    for (auto i : Spanning_Tree)
        if (TYPE[i] == -1)
            TYPE[i] = 1;

    // for (int i = 0; i < m; ++i) printf("%d ", TYPE[i]); puts("");
    // for (int i = 0; i < n; ++i) printf("%d ", par[i]); puts("");
    // std::cout << "Spanning_Tree.size() = " << Spanning_Tree.size() << std::endl;
    // for (int i: Spanning_Tree) printf("%d %d %d\n", U[i], V[i], TYPE[i]);
    // for (int i: Spanning_Tree) if (lxndanfdiadsfnslkjGrader::Gold[i] != TYPE[i])
    // std::cerr << U[i] << ' ' << V[i] << ' ' << i << std::endl;
    // return Spanning_Tree;
    for (int u = 0; u < n; ++u) {
        std::vector<int> E;

        for (int i = fir[u]; i; i = nex[i])
            E.push_back(idx[i]);

        d[u] = count(E);
    }

    for (auto i : Spanning_Tree)
        if (TYPE[i] == 1) {
            Gold_Roads.push_back(i), --d[U[i]], --d[V[i]];
        }

    for (int i = 0; i < n - 1; ++i) {
        for (int u = 0; u < n; ++u)
            if (d[u]) {
                int v = solve(u);
                Gold_Roads.push_back(Map[u][v]), --d[u], --d[v];
                TYPE[Map[u][v]] = 1;
                break;
            }
    }

    // fclose(stdout);
    return Gold_Roads;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 13
Accepted
time: 2ms
memory: 11704kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
7 21 30000
2 0
0 1
5 2
2 6
1 3
3 0
6 0
4 5
3 2
4 0
1 4
0 5
4 3
4 6
6 1
2 1
5 3
2 4
5 6
5 1
6 3
7 10 9 13 12 17

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
17 13 9 10 12 7

result:

ok correct

Test #2:

score: 0
Accepted
time: 4ms
memory: 11864kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
7 21 30000
4 6
1 6
2 3
0 3
2 1
2 6
5 6
6 3
0 2
1 0
4 2
1 3
5 2
5 0
0 6
5 3
4 5
5 1
3 4
1 4
4 0
4 16 10 0 20 18

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
20 4 10 18 16 0

result:

ok correct

Test #3:

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

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
7 21 30000
2 5
0 4
4 5
4 3
5 3
1 3
3 6
4 1
6 0
5 6
6 2
6 1
6 4
3 2
2 1
1 0
0 2
5 0
5 1
4 2
0 3
20 17 15 9 2 19

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
20 19 17 15 2 9

result:

ok correct

Test #4:

score: -13
Wrong Answer
time: 4ms
memory: 15216kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
7 13 30000
2 4
4 3
3 2
0 3
0 4
6 3
6 1
4 5
6 2
1 3
5 6
6 0
6 4
3 9 12 7 0 4

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
WA
NO

result:

wrong answer WA in grader: NO

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #58:

score: 19
Accepted
time: 4ms
memory: 9652kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
2 1 12000
1 0
0

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
0

result:

ok correct

Test #59:

score: 0
Accepted
time: 5ms
memory: 9656kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
10 45 12000
4 8
0 5
2 0
5 8
8 0
3 8
6 4
4 1
2 3
2 1
6 2
1 7
3 7
8 1
7 0
8 6
0 6
9 5
9 6
7 4
7 6
7 9
1 6
3 5
2 5
7 5
3 9
0 3
3 6
2 9
1 5
0 4
7 8
5 4
9 4
5 6
3 1
2 8
7 2
2 4
1 0
9 8
4 3
1 9
9 0
22 41 3 16 7 25 28 11 39

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
39 16 22 11 7 28 25 3 41

result:

ok correct

Test #60:

score: 0
Accepted
time: 1805ms
memory: 13056kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
400 79800 12000
32 64
96 254
115 203
7 171
112 81
124 143
336 175
217 328
152 133
124 331
19 91
92 232
152 43
215 169
4 341
363 18
83 99
52 46
248 66
242 187
150 319
335 158
172 150
3 49
126 256
60 153
165 230
265 68
119 380
171 22
35 169
3...

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
OK
79725 48509 24079 12882 76239 11706 26447 71679 45025 31044 39140 60011 26925 71860 5562 58728 37559 19404 40013 39248 29169 75263 74712 57996 51049 40217 32787 7231 73826 20602 46662 39613 19004 70475 39400 1641 32188 61064 37257 40510 ...

result:

ok correct

Test #61:

score: -19
Wrong Answer
time: 367ms
memory: 13728kb

input:

wrslcnopzlckvxbnair_input_simurgh_lmncvpisadngpiqdfngslcnvd
500 124750 12000
81 373
318 76
428 363
341 147
361 355
210 392
305 286
311 54
101 386
387 55
233 144
275 414
328 304
360 389
471 417
152 385
65 468
53 127
376 100
498 472
241 462
259 452
62 224
139 280
42 454
353 455
289 191
5 376
479 277
2...

output:

lxndanfdiadsfnslkj_output_simurgh_faifnbsidjvnsidjbgsidjgbs
WA
NO

result:

wrong answer WA in grader: NO

Subtask #5:

score: 0
Skipped

Dependency #1:

0%