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;
template<class T> bool uin(T& a, const T& b) { return a > b ? a = b, true : false; }
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m; cin >> n >> m;
vector<vector<int>> g(n);
vector<int> l(m), r(m), in(n), low(n), s(n);
for (int e = 0; e < m; ++e) {
cin >> l[e] >> r[e]; --l[e]; --r[e];
g[l[e]].push_back(e);
g[r[e]].push_back(e);
}
int q; cin >> q;
while (q--) {
int u, v; cin >> u >> v; --u; --v;
++s[u]; --s[v];
}
string ans(m, 'B');
int timer = 0;
constexpr char dir[2] = {'L', 'R'};
auto dfs = [&](const auto &self, int u, int p) -> void {
low[u] = in[u] = ++timer;
for (auto e : g[u]) {
if (e == p) continue;
int v = l[e] ^ r[e] ^ u;
if (in[v] != 0) uin(low[u], in[v]);
else {
self(self, v, e);
uin(low[u], low[v]);
if (s[v] != 0 && in[u] < low[v])
ans[e] = dir[(l[e] != v) ^ (s[v] > 0)];
s[u] += s[v];
}
}
};
for (int u = 0; u < n; ++u)
if (in[u] == 0)
dfs(dfs, u, -1);
cout << ans << '\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... |