Submission #1096583

# Submission time Handle Problem Language Result Execution time Memory
1096583 2024-10-04T20:19:27 Z f0rizen One-Way Streets (CEOI17_oneway) C++17
100 / 100
70 ms 21048 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

struct Edge {
    int to, ind;
};

vector<vector<Edge>> g;
vector<bool> used;
vector<int> d, up;
vector<bool> br;

void dfs_bridges(int v, int depth = 0, int p = -1) {
    used[v] = 1;
    d[v] = up[v] = depth;
    for (auto [u, ind] : g[v]) {
        if (!used[u]) {
            dfs_bridges(u, depth + 1, ind);
            up[v] = min(up[v], up[u]);
            if (d[v] < up[u]) {
                br[ind] = true;
            }
        } else if (ind != p) {
            up[v] = min(up[v], d[u]);
        }
    }
}

vector<int> c;

void dfs_color(int v, int cl) {
    c[v] = cl;
    for (auto [u, ind] : g[v]) {
        if (c[u] == -1 && !br[ind]) {
            dfs_color(u, cl);
        }
    }
}

vector<vector<int>> t;
vector<int> sum;

void dfs_sum(int v, int p = -1) {
    used[v] = 1;
    for (auto u : t[v]) {
        if (u != p) {
            d[u] = d[v] + 1;
            dfs_sum(u, v);
            sum[v] += sum[u];
        }
    }
}

int32_t main() {
#ifdef LOCAL
    freopen("/tmp/input.txt", "r", stdin);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n, m;
    cin >> n >> m;
    g.resize(n);
    vector<pair<int, int>> edg(m);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
        edg[i] = {u, v};
    }
    used.resize(n);
    d.resize(n);
    up.resize(n);
    br.resize(m);
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            dfs_bridges(i);
        }
    }
    c.resize(n, -1);
    int cl = 0;
    for (int i = 0; i < n; ++i) {
        if (c[i] == -1) {
            dfs_color(i, cl++);
        }
    }
    t.resize(cl);
    for (int i = 0; i < m; ++i) {
        if (br[i]) {
            auto [u, v] = edg[i];
            t[c[u]].push_back(c[v]);
            t[c[v]].push_back(c[u]);
        }
    }
    int p;
    cin >> p;
    sum.resize(cl);
    for (int i = 0; i < p; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        ++sum[c[u]];
        --sum[c[v]];
    }
    used.clear();
    used.resize(cl);
    d.clear();
    d.resize(cl);
    for (int i = 0; i < cl; ++i) {
        if (!used[i]) {
            dfs_sum(i);
        }
    }
    for (auto [u, v] : edg) {
        int a = c[u], b = c[v];
        if (a == b) {
            cout << "B";
        } else if (d[a] > d[b]) {
            if (sum[a] > 0) {
                cout << "R";
            } else if (sum[a] < 0) {
                cout << "L";
            } else {
                cout << "B";
            }
        } else {
            if (sum[b] > 0) {
                cout << "L";
            } else if (sum[b] < 0) {
                cout << "R";
            } else {
                cout << "B";
            }
        }
    }
    cout << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 25 ms 6864 KB Output is correct
12 Correct 29 ms 8028 KB Output is correct
13 Correct 33 ms 9660 KB Output is correct
14 Correct 38 ms 12128 KB Output is correct
15 Correct 42 ms 13276 KB Output is correct
16 Correct 47 ms 15700 KB Output is correct
17 Correct 43 ms 16980 KB Output is correct
18 Correct 46 ms 15700 KB Output is correct
19 Correct 46 ms 18124 KB Output is correct
20 Correct 27 ms 8284 KB Output is correct
21 Correct 25 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 25 ms 6864 KB Output is correct
12 Correct 29 ms 8028 KB Output is correct
13 Correct 33 ms 9660 KB Output is correct
14 Correct 38 ms 12128 KB Output is correct
15 Correct 42 ms 13276 KB Output is correct
16 Correct 47 ms 15700 KB Output is correct
17 Correct 43 ms 16980 KB Output is correct
18 Correct 46 ms 15700 KB Output is correct
19 Correct 46 ms 18124 KB Output is correct
20 Correct 27 ms 8284 KB Output is correct
21 Correct 25 ms 8028 KB Output is correct
22 Correct 54 ms 18260 KB Output is correct
23 Correct 59 ms 16700 KB Output is correct
24 Correct 61 ms 16816 KB Output is correct
25 Correct 70 ms 21048 KB Output is correct
26 Correct 53 ms 17744 KB Output is correct
27 Correct 56 ms 16724 KB Output is correct
28 Correct 19 ms 4596 KB Output is correct
29 Correct 36 ms 8864 KB Output is correct
30 Correct 37 ms 8932 KB Output is correct
31 Correct 36 ms 9296 KB Output is correct
32 Correct 41 ms 13224 KB Output is correct