This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e5 + 5;
const int MAXL = 20;
 
int n, m, q, tim;
int tin[MAXN], low[MAXN], com[MAXN], u[MAXN], v[MAXN], dp[MAXN];
bool Vis[MAXN];
char ans[MAXN];
vector <pair <int, int> > Adj[MAXN];
bool Bridge[MAXN];
 
void Build(int node, int p = -1)
{
    tim++;
    tin[node] = tim;
    low[node] = tim;
    Vis[node] = true;
    for(auto x : Adj[node])
    {
        if(x.second == p)
        {
            continue;
        }
        if(Vis[x.first])
        {
            low[node] = min(low[node], tin[x.first]);
        }
        else
        {
            Build(x.first, x.second);
            if(low[x.first] > tin[node])
            {
                Bridge[x.second] = true;
            }
            low[node] = min(low[node], low[x.first]);
        }
    }
}
 
void BuildNew(int node, int c)
{
    com[node] = c;
    for(auto x : Adj[node])
    {
        if(Bridge[x.second])
        {
            continue;
        }
        ans[x.second] = 'B';
        if(com[x.first])
        {
            continue;
        }
        BuildNew(x.first, c);
    }
}
 
void DFS(int node, int p = -1)
{
    Vis[node] = true;
    for(auto x : Adj[node])
    {
        if(x.first == p)
        {
            continue;
        }
        DFS(x.first, node);
    }
}
 
void DFS2(int node, int p = -1)
{
    Vis[node] = true;
    for(auto x : Adj[node])
    {
        if(x.first == p)
        {
            continue;
        }
        DFS2(x.first, node);
        if(dp[x.first] < 0)
        {
            ans[x.second] = (u[x.second] == node ? 'R' : 'L');
        }
        else if(dp[x.first] > 0)
        {
            ans[x.second] = (v[x.second] == node ? 'R' : 'L');
        }
        else
        {
            ans[x.second] = 'B';
        }
        dp[node] += dp[x.first];
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        cin >> u[i] >> v[i];
        Adj[u[i]].emplace_back(v[i], i);
        Adj[v[i]].emplace_back(u[i], i);
    }
    for(int i = 1; i <= n; i++)
    {
        if(!Vis[i])
        {
            Build(i);
        }
    }
    tim = 0;
    for(int i = 1; i <= n; i++)
    {
        if(!com[i])
        {
            tim++;
            BuildNew(i, tim);
        }
    }
    for(int i = 1; i <= n; i++)
    {
        Adj[i].clear();
        Vis[i] = false;
    }
    for(int i = 1; i <= m; i++)
    {
        u[i] = com[u[i]], v[i] = com[v[i]];
        if(u[i] != v[i])
        {
            Adj[u[i]].emplace_back(v[i], i);
            Adj[v[i]].emplace_back(u[i], i);
        }
    }
    for(int i = 1; i <= tim; i++)
    {
        if(!Vis[i])
        {
            DFS(i);
        }
    }
    cin >> q;
    while(q--)
    {
        int x, y;
        cin >> x >> y;
        x = com[x];
        y = com[y];
        dp[x]++;
        dp[y]--;
    }
    for(int i = 1; i <= tim; i++)
    {
        Vis[i] = false;
    }
    for(int i = 1; i <= tim; i++)
    {
        if(!Vis[i])
        {
            DFS2(i);
        }
    }
    for(int i = 1; i <= m; i++)
    {
        cout << ans[i];
    }
    cout << '\n';
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |