Submission #1093030

# Submission time Handle Problem Language Result Execution time Memory
1093030 2024-09-25T17:56:45 Z BF001 One-Way Streets (CEOI17_oneway) C++17
100 / 100
85 ms 30848 KB
#include<bits/stdc++.h>
using namespace std;
 
#define N 100005
#define fi first
#define se second  

typedef pair<int, int> ii;

int low[N], id[N], cnt, ncc, val[N], typ[N], n, m, dep[N];
vector<int> adj[N];
set<int> adj2[N];
stack<int> st;
vector<ii> eg;
 
void dfs(int u, int p){
    low[u] = id[u] = ++cnt;
    st.push(u);

    for (auto x : adj[u]){
        if (x == p){
            p = -1;
            continue;
        }
        if (id[x]){
            low[u] = min(low[u], id[x]);
        }
        else{
            dfs(x, u);
            low[u] = min(low[u], low[x]);
        }
    }

    if (id[u] == low[u]){
        ncc++;
        int s = -1;
        while (s != u){
            s = st.top();
            st.pop();
            typ[s] = ncc;
            low[s] = id[s] = n + 1;
        }
    }

} 

void getdep(int u, int p){
    for (auto x : adj2[u]){
        if (x == p) continue;
        dep[x] = dep[u] + 1;
        getdep(x, u);
        val[u] += val[x];
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
 
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        eg.push_back({u, v});
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    for (int i = 1; i <= n; i++){
        if (!id[i]) dfs(i, 0);
        for (auto x : adj[i]){
            if (typ[x] != typ[i]){
                adj2[typ[x]].insert(typ[i]);
                adj2[typ[i]].insert(typ[x]);
            }
        }
    }

    int q;
    cin >> q;
    while (q--){
        int a, b;
        cin >> a >> b;
        val[typ[a]]++;
        val[typ[b]]--;
    }

    for (int i = 1; i <= ncc; i++){
        if (!dep[i]){
            dep[i] = 1;
            getdep(i, 0);
        }
    }

    for (auto x : eg){
        int a = typ[x.fi], b = typ[x.se];
        if (a == b){
            cout << "B";
            continue;
        }
        if (dep[a] > dep[b]){
            if (val[a] == 0){
                cout << "B";
            }
            if (val[a] > 0){
                cout << "R";
            }
            if (val[a] < 0){
                cout << "L";
            }
        }
        if (dep[a] < dep[b]){
            if (val[b] == 0){
                cout << "B";
            }
            if (val[b] > 0){
                cout << "L";
            }
            if (val[b] < 0){
                cout << "R";
            }
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 4 ms 7448 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7516 KB Output is correct
6 Correct 4 ms 7620 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 4 ms 7448 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7516 KB Output is correct
6 Correct 4 ms 7620 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 28 ms 12740 KB Output is correct
12 Correct 36 ms 13764 KB Output is correct
13 Correct 37 ms 15296 KB Output is correct
14 Correct 46 ms 17864 KB Output is correct
15 Correct 50 ms 18652 KB Output is correct
16 Correct 74 ms 24260 KB Output is correct
17 Correct 66 ms 26056 KB Output is correct
18 Correct 65 ms 24080 KB Output is correct
19 Correct 63 ms 27396 KB Output is correct
20 Correct 30 ms 13768 KB Output is correct
21 Correct 35 ms 13264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 4 ms 7448 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 4 ms 7516 KB Output is correct
6 Correct 4 ms 7620 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 3 ms 7516 KB Output is correct
11 Correct 28 ms 12740 KB Output is correct
12 Correct 36 ms 13764 KB Output is correct
13 Correct 37 ms 15296 KB Output is correct
14 Correct 46 ms 17864 KB Output is correct
15 Correct 50 ms 18652 KB Output is correct
16 Correct 74 ms 24260 KB Output is correct
17 Correct 66 ms 26056 KB Output is correct
18 Correct 65 ms 24080 KB Output is correct
19 Correct 63 ms 27396 KB Output is correct
20 Correct 30 ms 13768 KB Output is correct
21 Correct 35 ms 13264 KB Output is correct
22 Correct 84 ms 27072 KB Output is correct
23 Correct 85 ms 25280 KB Output is correct
24 Correct 79 ms 25284 KB Output is correct
25 Correct 82 ms 30848 KB Output is correct
26 Correct 74 ms 26564 KB Output is correct
27 Correct 83 ms 25284 KB Output is correct
28 Correct 23 ms 10692 KB Output is correct
29 Correct 39 ms 14364 KB Output is correct
30 Correct 42 ms 14528 KB Output is correct
31 Correct 41 ms 14800 KB Output is correct
32 Correct 54 ms 20164 KB Output is correct