#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 1e18;
typedef pair<int, int> pii;
int low[maxn], num[maxn], tds, scc;
int lab[maxn], n, m, d[maxn], q;
char s[maxn];
stack<int> st;
vector<int> adj[maxn], g[maxn];
pii canh[maxn];
bool check[maxn];
void dfs(int u, int par)
{
low[u] = num[u] = ++tds;
st.push(u);
int tds = 0;
for(int v : adj[u]){
if(v != par || tds == 1){
if(num[v] != 0)
low[u] = min(low[u], num[v]);
else{
dfs(v, u);
low[u] = min(low[u], low[v]);
}
}
else{
tds++;
}
}
if(low[u] >= num[u]){
scc++;
int tmp;
do
{
tmp = st.top();
st.pop();
lab[tmp] = scc;
// for (int w: adj[tmp]) {
// if (lab[w] && scc != lab[w])
// g[scc].push_back(lab[w]);
// }
low[tmp] = num[tmp] = inf;
}while(tmp != u);
}
}
void dfs_work(int u)
{
check[u] = true;
for(int v : g[u]){
if(!check[v])
dfs_work(v);
d[u] += d[v];
}
}
signed main()
{
// freopen("oneway.inp" , "r" , stdin);
// freopen("oneway.out" , "w" , stdout);
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for(int i=1 ; i<=m ; ++i){
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
canh[i] = {u, v};
}
for(int i=1 ; i<=n ; ++i){
if(!num[i]){
dfs(i, 0);
}
}
for(int i=1 ; i<=m ; ++i){
auto [u, v] = canh[i];
int x = lab[u];
int y = lab[v];
if(x > y){
g[x].push_back(y);
}
}
cin >> q;
for(int i=1 ; i<=q ; ++i){
int u, v; cin >> u >> v;
u = lab[u]; v = lab[v];
d[v]--; d[u]++;
}
for(int i=1 ; i<=scc ; ++i){
if(!check[i]){
dfs_work(i);
}
}
for(int i=1 ; i<=m ; ++i){
auto [u, v] = canh[i];
int x = lab[u]; int y = lab[v];
if(x == y){
s[i] = 'B';
}
if(x > y)
{
if(d[y] > 0) s[i] = 'L';
if(d[y] < 0) s[i] = 'R';
if(d[y] == 0) s[i] = 'B';
}
if(x < y)
{
if(d[x] > 0) s[i] = 'R';
if(d[x] < 0) s[i] = 'L';
if(d[x] == 0) s[i] = 'B';
}
}
for(int i=1 ; i<=m ; ++i){
cout << s[i];
}
}
/// code by yourlove ///
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:88:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
88 | auto [u, v] = canh[i];
| ^
oneway.cpp:110:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
110 | auto [u, v] = canh[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |