#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5;
int n, m, p;
int low[N], num[N], lab[N], a[N], ind[N];
vector<int> g[N];
vector<array<int, 2>> tr[N];
int timer;
vector<int> st;
void dfs(int u, int p) {
low[u] = num[u] = ++timer;
st.push_back(u);
bool rep = 0;
for (int v : g[u]) {
if (v == p && !rep) {
rep = 1;
continue;
}
if (!low[v]) {
dfs(v, u);
low[u] = min(low[u], low[v]);
} else {
low[u] = min(low[u], num[v]);
}
}
if (low[u] == num[u]) {
while (1) {
int v = st.back(); st.pop_back();
lab[v] = u;
if (v == u) {
break;
}
}
}
}
void DFS(int u, int p) {
for (auto [v, id] : tr[u]) {
if (v ^ p) {
ind[v] = id;
DFS(v, u);
a[u] += a[v];
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
string res(m, 'B');
vector<array<int, 2>> e(m);
for (int i = 0; i < m; ++i) {
int u, v; cin >> u >> v;
e[i] = {u, v};
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 1; i <= n; ++i) {
if (!num[i]) {
dfs(i, i);
}
}
for (int i = 0; i < m; ++i) {
auto [u, v] = e[i];
tie(u, v) = tie(lab[u], lab[v]);
if (u ^ v) {
tr[u].push_back({v, -1 - i});
tr[v].push_back({u, i + 1});
}
}
cin >> p;
while (p--) {
int x, y; cin >> x >> y;
++a[lab[x]], --a[lab[y]];
}
for (int i = 1; i <= n; ++i) {
if (!ind[i]) {
DFS(i, i);
}
}
for (int i = 2; i <= n; ++i) {
if (a[i]) {
bool r = (a[i] > 0) ^ (ind[i] < 0);
int id = abs(ind[i]) - 1;
res[id] = r ? 'R' : 'L';
}
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6796 KB |
Output is correct |
6 |
Correct |
2 ms |
6804 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6800 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6796 KB |
Output is correct |
6 |
Correct |
2 ms |
6804 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6800 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
11612 KB |
Output is correct |
12 |
Correct |
24 ms |
12656 KB |
Output is correct |
13 |
Correct |
28 ms |
13776 KB |
Output is correct |
14 |
Correct |
32 ms |
14740 KB |
Output is correct |
15 |
Correct |
32 ms |
15320 KB |
Output is correct |
16 |
Correct |
38 ms |
16212 KB |
Output is correct |
17 |
Correct |
39 ms |
17760 KB |
Output is correct |
18 |
Correct |
35 ms |
16208 KB |
Output is correct |
19 |
Correct |
36 ms |
18892 KB |
Output is correct |
20 |
Correct |
24 ms |
12508 KB |
Output is correct |
21 |
Correct |
21 ms |
12124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6796 KB |
Output is correct |
6 |
Correct |
2 ms |
6804 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6800 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6748 KB |
Output is correct |
11 |
Correct |
21 ms |
11612 KB |
Output is correct |
12 |
Correct |
24 ms |
12656 KB |
Output is correct |
13 |
Correct |
28 ms |
13776 KB |
Output is correct |
14 |
Correct |
32 ms |
14740 KB |
Output is correct |
15 |
Correct |
32 ms |
15320 KB |
Output is correct |
16 |
Correct |
38 ms |
16212 KB |
Output is correct |
17 |
Correct |
39 ms |
17760 KB |
Output is correct |
18 |
Correct |
35 ms |
16208 KB |
Output is correct |
19 |
Correct |
36 ms |
18892 KB |
Output is correct |
20 |
Correct |
24 ms |
12508 KB |
Output is correct |
21 |
Correct |
21 ms |
12124 KB |
Output is correct |
22 |
Correct |
47 ms |
18768 KB |
Output is correct |
23 |
Correct |
48 ms |
17236 KB |
Output is correct |
24 |
Correct |
54 ms |
17232 KB |
Output is correct |
25 |
Correct |
52 ms |
21948 KB |
Output is correct |
26 |
Correct |
50 ms |
18372 KB |
Output is correct |
27 |
Correct |
53 ms |
17236 KB |
Output is correct |
28 |
Correct |
22 ms |
10076 KB |
Output is correct |
29 |
Correct |
32 ms |
13172 KB |
Output is correct |
30 |
Correct |
33 ms |
13272 KB |
Output is correct |
31 |
Correct |
35 ms |
13520 KB |
Output is correct |
32 |
Correct |
38 ms |
16340 KB |
Output is correct |