Submission #42961

# Submission time Handle Problem Language Result Execution time Memory
42961 2018-03-07T05:16:53 Z krauch One-Way Streets (CEOI17_oneway) C++14
100 / 100
133 ms 55920 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > PII;

#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekek
#define left(v) v << 1
#define right(v) v << 1 | 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)

const ll ool = 1e18 + 9;
const int N = 2e5 + 6, oo = 1e9 + 9, base = 1e9 + 7;

int n, m, Q, cnt, timer, tin[N], d[N], col[N], val[N], dp[N], a[N], b[N];
char ans[N];
bool u[N], bridge[N];
vector < PII > g[N], g2[N];
vector < int > vec;

void dfs(int v, int par) {
    u[v] = 1;
    tin[v] = ++timer;
    d[v] = tin[v];
    for (auto it : g[v]) {
        int to = it.F;
        if (it.S == par) continue;
        if (u[to]) {
            d[v] = min(d[v], tin[to]);
        }
        else {
            int cur = sz(vec);
            dfs(to, it.S);
            d[v] = min(d[v], d[to]);
            if (d[to] > tin[v]) {
                bridge[it.S] = 1;
                ++cnt;
                while (sz(vec) != cur) {
                    col[vec.back()] = cnt;
                    vec.pop_back();
                }
            }
        }
    }
    vec.eb(v);
}

void calc(int v) {
    u[v] = 1;
    for (auto it : g2[v]) {
        int to = it.F;
        if (u[to]) continue;
        calc(to);
        dp[v] += dp[to];
        if (dp[to] < 0) ans[it.S] = (col[a[it.S]] == v ? 'R' : 'L');
        if (dp[to] == 0) ans[it.S] = 'B';
        if (dp[to] > 0) ans[it.S] = (col[a[it.S]] == v ? 'L' : 'R');
    }
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n >> m;
    forn(i, 1, m) {
        int x, y;
        cin >> x >> y;
        g[x].eb(y, i);
        g[y].eb(x, i);
        a[i] = x;
        b[i] = y;
    }

    cin >> Q;
    forn(i, 1, Q) {
        int x, y;
        cin >> x >> y;
        val[x]++;
        val[y]--;
    }

    forn(i, 1, n) {
        if (!u[i]) {
            dfs(i, 0);
            ++cnt;
            while (sz(vec)) {
                col[vec.back()] = cnt;
                vec.pop_back();
            }
        }
    }

    forn(i, 1, m) {
        if (!bridge[i]) {
            ans[i] = 'B';
            continue;
        }
        g2[col[a[i]]].eb(col[b[i]], i);
        g2[col[b[i]]].eb(col[a[i]], i);
    }

    forn(i, 1, n) {
        u[i] = 0;
        dp[col[i]] += val[i];
    }

    forn(i, 1, cnt) {
        if (!u[i]) calc(i);
    }

    forn(i, 1, m) cout << ans[i];
    cout << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 9 ms 9936 KB Output is correct
4 Correct 9 ms 10088 KB Output is correct
5 Correct 9 ms 10148 KB Output is correct
6 Correct 11 ms 10180 KB Output is correct
7 Correct 9 ms 10180 KB Output is correct
8 Correct 9 ms 10180 KB Output is correct
9 Correct 11 ms 10316 KB Output is correct
10 Correct 9 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 9 ms 9936 KB Output is correct
4 Correct 9 ms 10088 KB Output is correct
5 Correct 9 ms 10148 KB Output is correct
6 Correct 11 ms 10180 KB Output is correct
7 Correct 9 ms 10180 KB Output is correct
8 Correct 9 ms 10180 KB Output is correct
9 Correct 11 ms 10316 KB Output is correct
10 Correct 9 ms 10320 KB Output is correct
11 Correct 52 ms 16728 KB Output is correct
12 Correct 58 ms 18952 KB Output is correct
13 Correct 62 ms 21196 KB Output is correct
14 Correct 70 ms 23728 KB Output is correct
15 Correct 77 ms 25324 KB Output is correct
16 Correct 102 ms 27328 KB Output is correct
17 Correct 94 ms 30020 KB Output is correct
18 Correct 101 ms 30024 KB Output is correct
19 Correct 81 ms 33484 KB Output is correct
20 Correct 59 ms 33484 KB Output is correct
21 Correct 60 ms 33484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 9 ms 9936 KB Output is correct
4 Correct 9 ms 10088 KB Output is correct
5 Correct 9 ms 10148 KB Output is correct
6 Correct 11 ms 10180 KB Output is correct
7 Correct 9 ms 10180 KB Output is correct
8 Correct 9 ms 10180 KB Output is correct
9 Correct 11 ms 10316 KB Output is correct
10 Correct 9 ms 10320 KB Output is correct
11 Correct 52 ms 16728 KB Output is correct
12 Correct 58 ms 18952 KB Output is correct
13 Correct 62 ms 21196 KB Output is correct
14 Correct 70 ms 23728 KB Output is correct
15 Correct 77 ms 25324 KB Output is correct
16 Correct 102 ms 27328 KB Output is correct
17 Correct 94 ms 30020 KB Output is correct
18 Correct 101 ms 30024 KB Output is correct
19 Correct 81 ms 33484 KB Output is correct
20 Correct 59 ms 33484 KB Output is correct
21 Correct 60 ms 33484 KB Output is correct
22 Correct 117 ms 37032 KB Output is correct
23 Correct 133 ms 37800 KB Output is correct
24 Correct 117 ms 40312 KB Output is correct
25 Correct 116 ms 46904 KB Output is correct
26 Correct 119 ms 46904 KB Output is correct
27 Correct 123 ms 47084 KB Output is correct
28 Correct 44 ms 47084 KB Output is correct
29 Correct 79 ms 47084 KB Output is correct
30 Correct 88 ms 48152 KB Output is correct
31 Correct 80 ms 50788 KB Output is correct
32 Correct 86 ms 55920 KB Output is correct