Submission #760352

# Submission time Handle Problem Language Result Execution time Memory
760352 2023-06-17T13:28:19 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
100 / 100
83 ms 14756 KB
#include <bits/stdc++.h>

            using namespace std;

            int N, M, Q, X[100005], Y[100005], P[100005];
            int timer, E[100005], tin[100005], low[100005];
            int S[100005], dep[100005];
            bool isBridge[100005];
            vector<int> adj[100005];

            int findSet(int v) {
                if(P[v] == v) return v;
                return P[v] = findSet(P[v]);
            }
            void unionSet(int u, int v) {
                u = findSet(u), v = findSet(v);
                if(u == v) return;
                P[u] = v;
            }
            void dfs(int v, int p) {
                tin[v] = low[v] = timer++;
                for(auto e : adj[v]) {
                    int u = v ^ E[e];
                    if(tin[u] != -1 && e != p) low[v] = min(low[v], tin[u]);
                    else if(tin[u] == -1) {
                        dfs(u, e);
                        low[v] = min(low[v], low[u]);
                        if(low[u] > tin[v]) isBridge[e] = 1;
                    }
                }
            }
            void solve(int v, int p) {
                for(auto e : adj[v]) {
                    int u = v ^ E[e];
                    if(u == p) continue;
                    dep[u] = dep[v] + 1;
                    solve(u, v); S[v] += S[u];
                }
            }

            int32_t main() {
                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                cin >> N >> M;
                for(int l = 1; l <= N; l++) P[l] = l;
                for(int l = 1; l <= M; l++) {
                    cin >> X[l] >> Y[l];
                    E[l] = X[l] ^ Y[l];
                    adj[X[l]].push_back(l);
                    adj[Y[l]].push_back(l);
                }
                memset(tin, -1, sizeof tin);
                for(int l = 1; l <= N; l++)
                    if(tin[l] == -1) dfs(l, -1);
                for(int l = 1; l <= M; l++) {
                    if(!isBridge[l]) unionSet(X[l], Y[l]);
                }
                for(int l = 1; l <= N; l++) adj[l].clear();
                for(int l = 1; l <= M; l++) {
                    if(!isBridge[l]) continue;
                    X[l] = findSet(X[l]);
                    Y[l] = findSet(Y[l]);
                    E[l] = X[l] ^ Y[l];
                    adj[X[l]].push_back(l);
                    adj[Y[l]].push_back(l);
                }
                cin >> Q;
                while(Q--) {
                    int U, V; cin >> U >> V;
                    U = findSet(U), V = findSet(V);
                    S[U]++, S[V]--;
                }
                for(int l = 1; l <= N; l++) {
                    if(P[l] == l && !dep[l]) {
                        dep[l] = 1; solve(l, l);
                    }
                }
                for(int l = 1; l <= M; l++) {
                    if(!isBridge[l]) { cout << 'B'; continue; }
                    int U = X[l], V = Y[l];
                    if(dep[U] < dep[V]) swap(U, V);
                    if(S[U]) cout << (((S[U] > 0) == (U == X[l])) ? 'R' : 'L');
                    else cout << 'B';
                }
                return 0;
            }


# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 1 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 3 ms 3028 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3156 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 1 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 3 ms 3028 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3156 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 27 ms 7388 KB Output is correct
12 Correct 29 ms 8660 KB Output is correct
13 Correct 34 ms 10136 KB Output is correct
14 Correct 53 ms 11136 KB Output is correct
15 Correct 55 ms 11216 KB Output is correct
16 Correct 48 ms 9212 KB Output is correct
17 Correct 38 ms 11084 KB Output is correct
18 Correct 41 ms 9104 KB Output is correct
19 Correct 38 ms 12512 KB Output is correct
20 Correct 32 ms 8124 KB Output is correct
21 Correct 38 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 1 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 3 ms 3028 KB Output is correct
5 Correct 2 ms 3156 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3156 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 27 ms 7388 KB Output is correct
12 Correct 29 ms 8660 KB Output is correct
13 Correct 34 ms 10136 KB Output is correct
14 Correct 53 ms 11136 KB Output is correct
15 Correct 55 ms 11216 KB Output is correct
16 Correct 48 ms 9212 KB Output is correct
17 Correct 38 ms 11084 KB Output is correct
18 Correct 41 ms 9104 KB Output is correct
19 Correct 38 ms 12512 KB Output is correct
20 Correct 32 ms 8124 KB Output is correct
21 Correct 38 ms 8320 KB Output is correct
22 Correct 61 ms 11168 KB Output is correct
23 Correct 83 ms 9260 KB Output is correct
24 Correct 83 ms 9120 KB Output is correct
25 Correct 54 ms 14756 KB Output is correct
26 Correct 57 ms 10576 KB Output is correct
27 Correct 48 ms 9232 KB Output is correct
28 Correct 33 ms 5512 KB Output is correct
29 Correct 49 ms 7796 KB Output is correct
30 Correct 62 ms 8268 KB Output is correct
31 Correct 60 ms 8144 KB Output is correct
32 Correct 58 ms 11132 KB Output is correct