#include <iostream>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)
#define eb(x...) emplace_back(x)
template<class T> bool ckmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
constexpr int N = 1 << 20, M = 1 << 20;
int n, m;
vector<int> g[N];
char ans[M];
int tin[N], low[N], l[M], r[M], s[N], timer;
void dfs(int u, int p = -1) {
low[u] = tin[u] = ++timer;
trav(e, g[u]) {
if (e == p) continue;
int v = l[e] == u ? r[e] : l[e];
if (tin[v]) ckmin(low[u], tin[v]);
else {
dfs(v, e);
ckmin(low[u], low[v]);
if (tin[u] < low[v]) {
if (s[v] > 0) ans[e] = l[e] == u ? 'L' : 'R';
if (s[v] < 0) ans[e] = l[e] == v ? 'L' : 'R';
}
s[u] += s[v];
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
rep(e, 0, m) {
cin >> l[e] >> r[e]; --l[e]; --r[e];
g[l[e]].eb(e); g[r[e]].eb(e);
ans[e] = 'B';
}
int q; cin >> q;
while (q--) {
int u, v; cin >> u >> v; --u; --v;
++s[u]; --s[v];
}
rep(u, 0, n) if (!tin[u]) dfs(u);
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
24960 KB |
Output is correct |
2 |
Correct |
19 ms |
25088 KB |
Output is correct |
3 |
Correct |
20 ms |
25088 KB |
Output is correct |
4 |
Correct |
20 ms |
25028 KB |
Output is correct |
5 |
Correct |
19 ms |
25088 KB |
Output is correct |
6 |
Correct |
19 ms |
25088 KB |
Output is correct |
7 |
Correct |
19 ms |
25088 KB |
Output is correct |
8 |
Correct |
19 ms |
25088 KB |
Output is correct |
9 |
Correct |
20 ms |
25088 KB |
Output is correct |
10 |
Correct |
21 ms |
25088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
24960 KB |
Output is correct |
2 |
Correct |
19 ms |
25088 KB |
Output is correct |
3 |
Correct |
20 ms |
25088 KB |
Output is correct |
4 |
Correct |
20 ms |
25028 KB |
Output is correct |
5 |
Correct |
19 ms |
25088 KB |
Output is correct |
6 |
Correct |
19 ms |
25088 KB |
Output is correct |
7 |
Correct |
19 ms |
25088 KB |
Output is correct |
8 |
Correct |
19 ms |
25088 KB |
Output is correct |
9 |
Correct |
20 ms |
25088 KB |
Output is correct |
10 |
Correct |
21 ms |
25088 KB |
Output is correct |
11 |
Correct |
58 ms |
30072 KB |
Output is correct |
12 |
Correct |
62 ms |
31096 KB |
Output is correct |
13 |
Correct |
67 ms |
32120 KB |
Output is correct |
14 |
Correct |
79 ms |
32888 KB |
Output is correct |
15 |
Correct |
92 ms |
33144 KB |
Output is correct |
16 |
Correct |
85 ms |
31608 KB |
Output is correct |
17 |
Correct |
69 ms |
33144 KB |
Output is correct |
18 |
Correct |
74 ms |
31608 KB |
Output is correct |
19 |
Correct |
69 ms |
34296 KB |
Output is correct |
20 |
Correct |
63 ms |
30968 KB |
Output is correct |
21 |
Correct |
60 ms |
30584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
24960 KB |
Output is correct |
2 |
Correct |
19 ms |
25088 KB |
Output is correct |
3 |
Correct |
20 ms |
25088 KB |
Output is correct |
4 |
Correct |
20 ms |
25028 KB |
Output is correct |
5 |
Correct |
19 ms |
25088 KB |
Output is correct |
6 |
Correct |
19 ms |
25088 KB |
Output is correct |
7 |
Correct |
19 ms |
25088 KB |
Output is correct |
8 |
Correct |
19 ms |
25088 KB |
Output is correct |
9 |
Correct |
20 ms |
25088 KB |
Output is correct |
10 |
Correct |
21 ms |
25088 KB |
Output is correct |
11 |
Correct |
58 ms |
30072 KB |
Output is correct |
12 |
Correct |
62 ms |
31096 KB |
Output is correct |
13 |
Correct |
67 ms |
32120 KB |
Output is correct |
14 |
Correct |
79 ms |
32888 KB |
Output is correct |
15 |
Correct |
92 ms |
33144 KB |
Output is correct |
16 |
Correct |
85 ms |
31608 KB |
Output is correct |
17 |
Correct |
69 ms |
33144 KB |
Output is correct |
18 |
Correct |
74 ms |
31608 KB |
Output is correct |
19 |
Correct |
69 ms |
34296 KB |
Output is correct |
20 |
Correct |
63 ms |
30968 KB |
Output is correct |
21 |
Correct |
60 ms |
30584 KB |
Output is correct |
22 |
Correct |
97 ms |
34300 KB |
Output is correct |
23 |
Correct |
96 ms |
32760 KB |
Output is correct |
24 |
Correct |
100 ms |
32760 KB |
Output is correct |
25 |
Correct |
97 ms |
37368 KB |
Output is correct |
26 |
Correct |
91 ms |
33912 KB |
Output is correct |
27 |
Correct |
96 ms |
32888 KB |
Output is correct |
28 |
Correct |
52 ms |
28280 KB |
Output is correct |
29 |
Correct |
87 ms |
31608 KB |
Output is correct |
30 |
Correct |
88 ms |
31780 KB |
Output is correct |
31 |
Correct |
87 ms |
32120 KB |
Output is correct |
32 |
Correct |
85 ms |
34144 KB |
Output is correct |