Submission #1027247

# Submission time Handle Problem Language Result Execution time Memory
1027247 2024-07-19T02:44:56 Z coldbr3w One-Way Streets (CEOI17_oneway) C++17
0 / 100
2 ms 15964 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()

const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 480;
ll n,m,p,timer=0;
vector<pll>adj[N];
struct ccjv{ll v, prv, nxt;};
vector<ccjv>g[N];
ll cmp[N], low[N], num[N], b[N], pa[N], up[N][20], dep[N], d[N];
pll edge[N];
ll cur = 0;
vector<pll>order;
map<pll,ll>dir;
void pre_dfs(ll u, ll par){
    low[u] = num[u] = ++timer;
    for(auto x : adj[u]){
        ll v = x.F, idx = x.S;
        if(idx == par) continue;
        if(num[v]) low[u] = min(low[u], num[v]);
        else{
            pre_dfs(v, idx);
            low[u] = min(low[u], low[v]);
            if(low[v] == num[v]) {
                //cout << "bridge" << ' ' << u << ' ' << v << '\n';
                b[idx] = 1;
            }
        }
    }
}
void dfs_cmp(ll u, ll par){
    cmp[u] = cur;
    for(auto x : adj[u]){
        ll v = x.F, idx = x.S;
        if(idx == par) continue;
        if(b[idx]){
            if(cmp[v]) g[cmp[u]].pb({cmp[v], u, v}), g[cmp[v]].pb({cmp[u], v, u});
        }
        else if(!cmp[v]) dfs_cmp(v, idx);
    }
}
ll lca(ll u, ll v){
    if(dep[u] != dep[v]){
        if(dep[u] < dep[v]) swap(u, v);
        ll k = dep[u] - dep[v];
        for(int i = 19; i >= 0;i--){
            if(k & (1 << i)) u = up[u][i];
        }
    }
    if(u == v) return u;
    for(int i = 19; i >= 0;i--){
        if(up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
    }
    return up[u][0];
}
void dfs_build(ll u, ll par){
    for(auto x : g[u]){
        ll v = x.v;
        if(v == par) continue;
        up[v][0] = u;
        for(int i = 1; i <= 19;i++) up[v][i] = up[up[v][i-1]][i-1];
        dep[v] = dep[u] + 1;
        dfs_build(v, u);
    }
}
void dfs(ll u, ll par){
    for(auto x : g[u]){
        ll v = x.v;
        if(v == par) continue;
        dfs(v, u);
        d[u] += d[v];
    }
    for(auto x : g[u]){
        ll v = x.v;
        if(v == par) continue;
        if(d[v] < 0) dir[{x.nxt, x.prv}] = 1, dir[{x.prv, x.nxt}] = -1;
        else if(d[v] > 0) dir[{x.nxt, x.prv}] = -1, dir[{x.prv, x.nxt}] = 1;
    }
}
void to_thic_cau(){  
    cin >> n >> m;
    for(int i = 1; i <= m;i++){
        ll u,v; cin >> u >> v;
        edge[i] = {u, v};
        adj[u].pb({v, i});
        adj[v].pb({u, i});
    }
    for(int i = 1; i <= n;i++) if(!num[i]) pre_dfs(i, 0);
    for(int i = 1; i <= n;i++){
        if(!cmp[i]){
            ++cur;
            dfs_cmp(i, 0);
        }
    }
    dfs_build(cmp[1], 0);
    cin >> p;
    for(int i = 1; i <= p;i++){
        ll a,b; cin >> a >> b;
        a = cmp[a], b = cmp[b];
        ll x = lca(a, b);
        if(x != a && x != b){
            d[a]--, d[x]++;
            d[b]++, d[x]--;
        }
        else if(x == a){
            d[b]--, d[a]++;
        }
        else if(x == b) d[a]--, d[b]++;
    }
    dfs(cmp[1], 0);
    for(int i = 1; i <= m;i++){
        if(!b[i]){
            cout << 'B';
        }
        else{
            if(!dir[{edge[i].F, edge[i].S}]) cout << 'B';
            else if(dir[{edge[i].F, edge[i].S}] == 1) cout << 'R';
            else cout << 'L';
        }
    }
    cout << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tc = 1;
    //cin >> tc;
    while(tc--) to_thic_cau();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 15964 KB Output isn't correct
2 Halted 0 ms 0 KB -