Submission #985568

# Submission time Handle Problem Language Result Execution time Memory
985568 2024-05-18T08:19:10 Z parlimoos One-Way Streets (CEOI17_oneway) C++14
0 / 100
3 ms 9052 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int n , m , q;
vector<arr(2)> es;
vector<int> g[100000] , tr[100000];
int ecnt[100000] , tms[100000][2];
int bl[100000][20] , dir[100000];
int low[100000] , tin[100000];
bool ms[100000];

int timer = 0;
void tarjan(int v = 0 , int p = -1){
    ms[v] = 1;
    tin[v] = low[v] = timer++;
    for(int e : g[v]){
        int u = es[e][0] + es[e][1] - v;
        if(u == p) continue;
        if(ms[u]) low[v] = min(low[v] , tin[u]);
        else{
            tarjan(u , v);
            low[v] = min(low[v] , low[u]);
            if(low[u] > tin[v]) ecnt[e] = 0;
        }
    }
}
void dfs1(int v = 0 , int p = -1){
    if(v == 0) timer = -1;
    ms[v] = 1 , tms[v][0] = ++timer;
    for(int e : g[v]){
        int u = es[e][0] + es[e][1] - v;
        if(ms[u]) continue;
        tr[v].pb(u) , dfs1(u , v);
    }
    bl[v][0] = p , tms[v][1] = timer;
    for(int i = 1 ; i < 20 ; i++){
        if(bl[v][i - 1] == -1) bl[v][i] = -1;
        bl[v][i] = bl[bl[v][i - 1]][i - 1];
    }
}
int lca(int v1 , int v2){
    if(tms[v1][0] <= tms[v2][0] and tms[v1][1] >= tms[v2][0]) return v1;
    if(tms[v2][0] <= tms[v1][0] and tms[v2][1] >= tms[v1][0]) return v2;
    int u = v1;
    for(int i = 19 ; i >= 0 ; i--){
        if(bl[u][i] == -1) continue;
        if(tms[bl[u][i]][0] > tms[v2][0] or tms[bl[u][i]][1] < tms[v2][0]) u = bl[u][i];
    }
    return bl[u][0];
}
void dfs2(int v = 0){
    for(int u : tr[v]){
        dfs2(u) , dir[v] += dir[u];
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int v , u;
        cin >> v >> u;
        v-- , u--;
        es.pb({v , u}) , g[v].pb(i) , g[u].pb(i);
    }
    fill(&ecnt[0] , &ecnt[m] , 2) , tarjan();
    fill(&ms[0] , &ms[n] , 0) , dfs1();
    cin >> q;
    for(int i = 0 ; i < q ; i++){
        int v , u;
        cin >> v >> u;
        int a = lca(v , u);
        if(a == v) dir[u]-- , dir[v]++;
        else if(a == u) dir[u]++ , dir[v]--;
        else dir[v]++ , dir[u]--;
    }
    dfs2();
    for(int e = 0 ; e < m ; e++){
        if(ecnt[e] > 1) cout << 'B';
        else{
            int v = es[e][0] , u = es[e][1];
            if(tms[u][0] < tms[v][0]){
                if(dir[v] == 0) cout << 'B';
                else if(dir[v] < 0) cout << 'R';
                else cout << 'L';
            }else{
                if(dir[u] == 0) cout << 'B';
                else if(dir[u] < 0) cout << 'R';
                else cout << 'L';
            }
        }
    }
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -