#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
37 ms |
5444 KB |
Output is correct |
12 |
Correct |
48 ms |
6872 KB |
Output is correct |
13 |
Correct |
50 ms |
8704 KB |
Output is correct |
14 |
Correct |
62 ms |
10144 KB |
Output is correct |
15 |
Correct |
55 ms |
10448 KB |
Output is correct |
16 |
Correct |
52 ms |
8340 KB |
Output is correct |
17 |
Correct |
49 ms |
10692 KB |
Output is correct |
18 |
Correct |
62 ms |
8412 KB |
Output is correct |
19 |
Correct |
49 ms |
12224 KB |
Output is correct |
20 |
Correct |
57 ms |
7172 KB |
Output is correct |
21 |
Correct |
40 ms |
6648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
37 ms |
5444 KB |
Output is correct |
12 |
Correct |
48 ms |
6872 KB |
Output is correct |
13 |
Correct |
50 ms |
8704 KB |
Output is correct |
14 |
Correct |
62 ms |
10144 KB |
Output is correct |
15 |
Correct |
55 ms |
10448 KB |
Output is correct |
16 |
Correct |
52 ms |
8340 KB |
Output is correct |
17 |
Correct |
49 ms |
10692 KB |
Output is correct |
18 |
Correct |
62 ms |
8412 KB |
Output is correct |
19 |
Correct |
49 ms |
12224 KB |
Output is correct |
20 |
Correct |
57 ms |
7172 KB |
Output is correct |
21 |
Correct |
40 ms |
6648 KB |
Output is correct |
22 |
Correct |
76 ms |
11236 KB |
Output is correct |
23 |
Correct |
72 ms |
8944 KB |
Output is correct |
24 |
Correct |
77 ms |
8988 KB |
Output is correct |
25 |
Correct |
69 ms |
15424 KB |
Output is correct |
26 |
Correct |
69 ms |
10656 KB |
Output is correct |
27 |
Correct |
68 ms |
9084 KB |
Output is correct |
28 |
Correct |
36 ms |
2760 KB |
Output is correct |
29 |
Correct |
63 ms |
6992 KB |
Output is correct |
30 |
Correct |
76 ms |
7176 KB |
Output is correct |
31 |
Correct |
66 ms |
7640 KB |
Output is correct |
32 |
Correct |
64 ms |
10704 KB |
Output is correct |