답안 #708186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708186 2023-03-11T09:17:37 Z Cyanmond Simurgh (IOI17_simurgh) C++17
51 / 100
384 ms 4056 KB
#include "simurgh.h"
/*
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

static int MAXQ = 30000;

static int n, m, q = 0;
static vector<int> u, v;
static vector<bool> goal;

static void wrong_answer() {
    printf("NO\n");
    exit(0);
}

static bool is_valid(const vector<int> &r) {
    if (int(r.size()) != n - 1) return false;

    for (int i = 0; i < n - 1; i++)
        if (r[i] < 0 || r[i] >= m) return false;

    return true;
}

static int _count_common_roads_internal(const vector<int> &r) {
    if (!is_valid(r)) wrong_answer();

    int common = 0;
    for (int i = 0; i < n - 1; i++) {
        bool is_common = goal[r[i]];
        if (is_common) common++;
    }

    return common;
}

int count_common_roads(const vector<int> &r) {
    q++;
    if (q > MAXQ) wrong_answer();

    return _count_common_roads_internal(r);
}
*/
#include <bits/stdc++.h>

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
    const int m = (int)u.size();
    std::vector<int> edgeType(m, -1);
    for (int i = 0; i < n; ++i) {
        std::vector<int> e1, e2;
        for (int j = 0; j < m; ++j) {
            if (u[j] == i or v[j] == i) {
                e1.push_back(j);
            } else {
                e2.push_back(j);
            }
        }
        std::vector<std::vector<std::pair<int, int>>> graph(n);
        for (const int x : e2) {
            graph[u[x]].push_back({v[x], x});
            graph[v[x]].push_back({u[x], x});
        }
        std::vector<bool> isSeen(n);
        int cnt = 0;
        std::vector<int> id(n), treeEdges;
        for (int f = 0; f < n; ++f) {
            if (isSeen[f]) continue;
            if (f == i) continue;
            std::queue<int> que;
            que.push(f);
            isSeen[f] = true;
            while (not que.empty()) {
                const int x = que.front();
                que.pop();
                id[x] = cnt;
                for (const auto &[t, y] : graph[x]) {
                    if (not isSeen[t]) {
                        treeEdges.push_back(y);
                        que.push(t);
                        isSeen[t] = true;
                    }
                }
            }
            ++cnt;
        }
        const int R = cnt;
        std::vector<std::vector<int>> eDivided(R);
        for (const int x : e1) {
            if (u[x] == i) {
                eDivided[id[v[x]]].push_back(x);
            } else {
                eDivided[id[u[x]]].push_back(x);
            }
        }

        for (int f = 0; f < R; ++f) {
            auto &vec = eDivided[f];
            const int T = (int)vec.size();
            for (int j = 0; j < R; ++j) {
                if (j != f) {
                    treeEdges.push_back(eDivided[j][0]);
                }
            }
            std::vector<int> vals(T);
            for (int j = 0; j < T; ++j) {
                if (edgeType[vec[j]] != -1) {
                    std::swap(vec[j], vec[0]);
                }
            }
            if (edgeType[vec[0]] == -1) {
                for (int j = 0; j < T; ++j) {
                    treeEdges.push_back(vec[j]);
                    vals[j] = count_common_roads(treeEdges);
                    treeEdges.pop_back();
                }
                const int ma = *std::max_element(vals.begin(), vals.end());
                for (int j = 0; j < T; ++j) {
                    if (vals[j] == ma) {
                        edgeType[vec[j]] = 1;
                    } else {
                        edgeType[vec[j]] = 0;
                    }
                }
            } else {
                treeEdges.push_back(vec[0]);
                int ma = count_common_roads(treeEdges);
                treeEdges.pop_back();
                if (edgeType[vec[0]] == 0) {
                    ++ma;
                }
                for (int j = 0; j < T; ++j) {
                    if (edgeType[vec[j]] != -1) {
                        continue;
                    }
                    treeEdges.push_back(vec[j]);
                    const int val = count_common_roads(treeEdges);
                    if (ma == val) {
                        edgeType[vec[j]] = 1;
                    } else {
                        edgeType[vec[j]] = 0;
                    }
                    treeEdges.pop_back();
                }
            }
            for (int j = 0; j < R - 1; ++j) {
                treeEdges.pop_back();
            }
        }
    }
    std::vector<int> ret;
    for (int i = 0; i < m; ++i) {
        if (edgeType[i] == 1) {
            ret.push_back(i);
        }
    }
    return ret;
}
/*
int main() {
    assert(2 == scanf("%d %d", &n, &m));

    u.resize(m);
    v.resize(m);

    for (int i = 0; i < m; i++) assert(2 == scanf("%d %d", &u[i], &v[i]));

    goal.resize(m, false);

    for (int i = 0; i < n - 1; i++) {
        int id;
        assert(1 == scanf("%d", &id));
        goal[id] = true;
    }

    vector<int> res = find_roads(n, u, v);

    if (_count_common_roads_internal(res) != n - 1) wrong_answer();

    printf("YES\n");

    return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 1 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 5 ms 340 KB correct
15 Correct 5 ms 340 KB correct
16 Correct 4 ms 340 KB correct
17 Correct 4 ms 340 KB correct
18 Correct 2 ms 212 KB correct
19 Correct 4 ms 340 KB correct
20 Correct 4 ms 340 KB correct
21 Correct 4 ms 340 KB correct
22 Correct 3 ms 340 KB correct
23 Correct 3 ms 340 KB correct
24 Correct 3 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 3 ms 340 KB correct
27 Correct 3 ms 340 KB correct
28 Correct 2 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 3 ms 340 KB correct
31 Correct 3 ms 340 KB correct
32 Correct 4 ms 348 KB correct
33 Correct 3 ms 340 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 5 ms 340 KB correct
15 Correct 5 ms 340 KB correct
16 Correct 4 ms 340 KB correct
17 Correct 4 ms 340 KB correct
18 Correct 2 ms 212 KB correct
19 Correct 4 ms 340 KB correct
20 Correct 4 ms 340 KB correct
21 Correct 4 ms 340 KB correct
22 Correct 3 ms 340 KB correct
23 Correct 3 ms 340 KB correct
24 Correct 3 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 3 ms 340 KB correct
27 Correct 3 ms 340 KB correct
28 Correct 2 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 3 ms 340 KB correct
31 Correct 3 ms 340 KB correct
32 Correct 4 ms 348 KB correct
33 Correct 3 ms 340 KB correct
34 Correct 384 ms 1692 KB correct
35 Correct 372 ms 1760 KB correct
36 Correct 271 ms 1644 KB correct
37 Correct 29 ms 340 KB correct
38 Correct 379 ms 1864 KB correct
39 Correct 340 ms 1720 KB correct
40 Correct 273 ms 1524 KB correct
41 Correct 373 ms 1964 KB correct
42 Correct 372 ms 1780 KB correct
43 Correct 221 ms 1428 KB correct
44 Correct 171 ms 980 KB correct
45 Correct 192 ms 1052 KB correct
46 Correct 152 ms 928 KB correct
47 Correct 81 ms 628 KB correct
48 Correct 15 ms 344 KB correct
49 Correct 32 ms 340 KB correct
50 Correct 82 ms 648 KB correct
51 Correct 189 ms 1100 KB correct
52 Correct 170 ms 1112 KB correct
53 Correct 146 ms 956 KB correct
54 Correct 211 ms 1256 KB correct
55 Correct 191 ms 1084 KB correct
56 Correct 190 ms 1060 KB correct
57 Correct 192 ms 1104 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Incorrect 219 ms 4056 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 0 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 5 ms 340 KB correct
15 Correct 5 ms 340 KB correct
16 Correct 4 ms 340 KB correct
17 Correct 4 ms 340 KB correct
18 Correct 2 ms 212 KB correct
19 Correct 4 ms 340 KB correct
20 Correct 4 ms 340 KB correct
21 Correct 4 ms 340 KB correct
22 Correct 3 ms 340 KB correct
23 Correct 3 ms 340 KB correct
24 Correct 3 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 3 ms 340 KB correct
27 Correct 3 ms 340 KB correct
28 Correct 2 ms 212 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 3 ms 340 KB correct
31 Correct 3 ms 340 KB correct
32 Correct 4 ms 348 KB correct
33 Correct 3 ms 340 KB correct
34 Correct 384 ms 1692 KB correct
35 Correct 372 ms 1760 KB correct
36 Correct 271 ms 1644 KB correct
37 Correct 29 ms 340 KB correct
38 Correct 379 ms 1864 KB correct
39 Correct 340 ms 1720 KB correct
40 Correct 273 ms 1524 KB correct
41 Correct 373 ms 1964 KB correct
42 Correct 372 ms 1780 KB correct
43 Correct 221 ms 1428 KB correct
44 Correct 171 ms 980 KB correct
45 Correct 192 ms 1052 KB correct
46 Correct 152 ms 928 KB correct
47 Correct 81 ms 628 KB correct
48 Correct 15 ms 344 KB correct
49 Correct 32 ms 340 KB correct
50 Correct 82 ms 648 KB correct
51 Correct 189 ms 1100 KB correct
52 Correct 170 ms 1112 KB correct
53 Correct 146 ms 956 KB correct
54 Correct 211 ms 1256 KB correct
55 Correct 191 ms 1084 KB correct
56 Correct 190 ms 1060 KB correct
57 Correct 192 ms 1104 KB correct
58 Correct 0 ms 212 KB correct
59 Correct 1 ms 212 KB correct
60 Incorrect 219 ms 4056 KB WA in grader: NO
61 Halted 0 ms 0 KB -