#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
if (!name.empty())
{
freopen((name + ".INP").c_str(), "r", stdin);
freopen((name + ".OUT").c_str(), "w", stdout);
}
#endif
}
// START OF DEBUG
#define db(val) "["#val" = "<<(val)<<"] "
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
// for printing std::pair
template<class U, class V> print_op(pair<U, V>) {
return out << "(" << u.first << ", " << u.second << ")";
}
// for printing collection
template<class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream&>::type
operator<<(ostream& out, const Con& con) {
out << "{";
for (auto beg = con.begin(), it = beg; it != con.end(); ++it)
out << (it == beg ? "" : ", ") << *it;
return out << "}";
}
// for printing std::tuple
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
if constexpr(i == tuple_size<T>::value) return out << ")";
else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U> print_op(tuple<U...>) {
return print_tuple_utils<0, tuple<U...>>(out, u);
}
// END OF DEBUG
const int MAXN = 1e5;
int n, m;
vector<pii> g[MAXN + 5];
vector<pii> tree[MAXN + 5];
int low[MAXN + 5];
int num[MAXN + 5];
int id[MAXN + 5];
vi nodes;
int sccCount = 0;
int timerDfs = 0;
void dfs(int u, int par) {
low[u] = num[u] = ++timerDfs;
nodes.push_back(u);
bool skip = false;
for(auto [v, id] : g[u]) {
if(v == par && !skip) {
skip = true;
continue;
}
if(num[v] == 0) {
dfs(v, u);
low[u] = min(low[u], low[v]);
}
else {
low[u] = min(low[u], num[v]);
}
}
if(low[u] == num[u]) {
sccCount++;
int v;
do {
v = nodes.back();
id[v] = sccCount;
nodes.pop_back();
}
while(v != u);
}
}
int val[MAXN + 5];
int ans[MAXN + 5];
// ans[i] : (-1, L) ; (0 : B) ; (1; R)
void dfs_ans(int u, int par) {
for(auto [v, index] : tree[u]) {
if(v == par) continue;
dfs_ans(v, u);
if(val[v] > 0) {
if(index > 0) ans[index] = -1;
else ans[-index] = 1;
}
else if (val[v] < 0){
if(index > 0) ans[index] = 1;
else ans[-index] = -1;
}
val[u] += val[v];
}
}
void solve()
{
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
if(u == v) continue;
g[u].push_back({v, i});
g[v].push_back({u, -i});
}
for(int i = 1; i <= n; i++) if(num[i] == 0) dfs(i, -1);
for(int u = 1; u <= n; u++) {
for(auto [v, i] : g[u]) {
if(id[u] != id[v]) {
tree[id[u]].push_back({id[v], i});
}
}
}
int q; cin >> q;
while(q--) {
int u, v; cin >> u >> v;
u = id[u];
v = id[v];
val[u]++;
val[v]--;
}
dfs_ans(id[1], id[1]);
// for(int i = 1; i <= sccCount; i++) cout << i << ' ' << ans[i] << '\n';
for(int i = 1; i <= m; i++) {
if(ans[i] == 0) cout << 'B';
else if(ans[i] == -1) cout << 'L';
else if(ans[i] == 1) cout << 'R';
}
}
signed main()
{
setIO();
int t = 1;
// cin >> t;
while (t--)
solve();
}
Compilation message (stderr)
oneway.cpp: In function 'void setIO(std::string)':
oneway.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".INP").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen((name + ".OUT").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |