Submission #1037583

# Submission time Handle Problem Language Result Execution time Memory
1037583 2024-07-29T05:11:00 Z Forested Simurgh (IOI17_simurgh) C++17
51 / 100
84 ms 3488 KB
#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<VV<T>>;
template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32) size(x)
#define ALL(x) begin(x), end(x)

void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T, typename U>
void dbg(pair<T, U> p) {
    cerr << "(";
    dbg(p.first);
    cerr << ", ";
    dbg(p.second);
    cerr << ")";
}
template <typename T>
void dbg(V<T> arr) {
    cerr << "[";
    REP(i, LEN(arr)) {
        if (i) {
            cerr << ", ";
        }
        dbg(arr[i]);
    }
    cerr << "]";
}
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
    dbg(head);
    cerr << ", ";
    debug(tail...);
}
#ifdef DEBUGF
#define DBG(...)                       \
    do {                               \
        cerr << #__VA_ARGS__ << " : "; \
        debug(__VA_ARGS__);            \
    } while (false)
#else
#define DBG(...) (void)0
#endif

#include "simurgh.h"

V<i32> subtask_3(i32 n, V<i32> u, V<i32> v) {
    struct Edge {
        i32 to, id;
    };
    i32 m = LEN(u);
    VV<Edge> g(n);
    REP(i, m) {
        g[u[i]].emplace_back(Edge{v[i], i});
        g[v[i]].emplace_back(Edge{u[i], i});
    }
    i32 root = 0;
    V<i32> par(n, -1), pid(n, -1), dep(n, -1);
    {
        queue<i32> que;
        que.push(root);
        dep[root] = 0;
        while (!que.empty()) {
            i32 v = que.front();
            que.pop();
            for (const Edge &e : g[v]) {
                if (dep[e.to] == -1) {
                    par[e.to] = v;
                    pid[e.to] = e.id;
                    dep[e.to] = dep[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    V<i32> tree;
    REP(i, n) {
        if (pid[i] != -1) {
            tree.push_back(pid[i]);
        }
    }
    i32 base = count_common_roads(tree);
    V<i32> con(m, -1);
    REP(i, m) {
        if (count(ALL(tree), i)) {
            continue;
        }
        V<i32> loop;
        {
            i32 x = u[i], y = v[i];
            while (x != y) {
                if (dep[x] < dep[y]) {
                    swap(x, y);
                }
                loop.push_back(pid[x]);
                x = par[x];
            }
        }
        const i32 nil = 998;
        V<i32> diffs(LEN(loop), nil);
        REP(j, LEN(loop)) {
            i32 e = loop[j];
            if (con[e] != -1) {
                continue;
            }
            V<i32> ask = tree;
            ask.erase(find(ALL(ask), e));
            ask.push_back(i);
            diffs[j] = count_common_roads(ask) - base;
        }
        if (auto itr = find(ALL(diffs), nil); itr != end(diffs)) {
            {
                i32 e = loop[itr - begin(diffs)];
                V<i32> ask = tree;
                ask.erase(find(ALL(ask), e));
                ask.push_back(i);
                i32 di = count_common_roads(ask) - base;
                con[i] = di + con[e];
            }
            REP(j, LEN(loop)) {
                i32 e = loop[j];
                if (con[e] != -1) {
                    continue;
                }
                // diffs[j] = con[i] - con[e]
                con[e] = con[i] - diffs[j];
            }
        } else if (count(ALL(diffs), 0) == LEN(diffs)) {
            con[i] = 0;
            REP(j, LEN(diffs)) { con[loop[j]] = 0; }
        } else {
            REP(j, LEN(loop)) {
                if (diffs[j] == 1) {
                    con[i] = 1;
                }
                if (diffs[j] == -1) {
                    con[i] = 0;
                }
            }
            REP(j, LEN(loop)) {
                i32 e = loop[j];
                con[e] = con[i] - diffs[j];
            }
        }
    }
    REP(i, m) {
        if (con[i] == -1) {
            con[i] = 1;
        }
    }
    V<i32> ans;
    REP(i, m) {
        if (con[i] == 1) {
            ans.push_back(i);
        }
    }
    return ans;
}

V<i32> find_roads(i32 n, V<i32> u, V<i32> v) {
    if (n <= 240) {
        return subtask_3(n, u, v);
    }
    assert(false);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 344 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 344 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 408 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 496 KB correct
22 Correct 1 ms 444 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 344 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 408 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 496 KB correct
22 Correct 1 ms 444 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 84 ms 1884 KB correct
35 Correct 76 ms 1944 KB correct
36 Correct 54 ms 1624 KB correct
37 Correct 4 ms 344 KB correct
38 Correct 81 ms 1976 KB correct
39 Correct 67 ms 1824 KB correct
40 Correct 51 ms 1628 KB correct
41 Correct 79 ms 1884 KB correct
42 Correct 80 ms 1884 KB correct
43 Correct 38 ms 1420 KB correct
44 Correct 32 ms 1116 KB correct
45 Correct 37 ms 1112 KB correct
46 Correct 29 ms 860 KB correct
47 Correct 12 ms 604 KB correct
48 Correct 2 ms 348 KB correct
49 Correct 4 ms 348 KB correct
50 Correct 12 ms 604 KB correct
51 Correct 40 ms 1212 KB correct
52 Correct 35 ms 1116 KB correct
53 Correct 30 ms 860 KB correct
54 Correct 42 ms 1368 KB correct
55 Correct 37 ms 1116 KB correct
56 Correct 39 ms 1112 KB correct
57 Correct 46 ms 1116 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Runtime error 10 ms 3488 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 344 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 348 KB correct
17 Correct 1 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 1 ms 408 KB correct
20 Correct 1 ms 348 KB correct
21 Correct 1 ms 496 KB correct
22 Correct 1 ms 444 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 1 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 0 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 1 ms 348 KB correct
32 Correct 1 ms 348 KB correct
33 Correct 1 ms 348 KB correct
34 Correct 84 ms 1884 KB correct
35 Correct 76 ms 1944 KB correct
36 Correct 54 ms 1624 KB correct
37 Correct 4 ms 344 KB correct
38 Correct 81 ms 1976 KB correct
39 Correct 67 ms 1824 KB correct
40 Correct 51 ms 1628 KB correct
41 Correct 79 ms 1884 KB correct
42 Correct 80 ms 1884 KB correct
43 Correct 38 ms 1420 KB correct
44 Correct 32 ms 1116 KB correct
45 Correct 37 ms 1112 KB correct
46 Correct 29 ms 860 KB correct
47 Correct 12 ms 604 KB correct
48 Correct 2 ms 348 KB correct
49 Correct 4 ms 348 KB correct
50 Correct 12 ms 604 KB correct
51 Correct 40 ms 1212 KB correct
52 Correct 35 ms 1116 KB correct
53 Correct 30 ms 860 KB correct
54 Correct 42 ms 1368 KB correct
55 Correct 37 ms 1116 KB correct
56 Correct 39 ms 1112 KB correct
57 Correct 46 ms 1116 KB correct
58 Correct 0 ms 348 KB correct
59 Correct 0 ms 348 KB correct
60 Runtime error 10 ms 3488 KB Execution killed with signal 6
61 Halted 0 ms 0 KB -