#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
vector<tuple<int, int, int>> edges;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
--x; --y;
g[x].emplace_back(y, i);
g[y].emplace_back(x, i);
edges.emplace_back(x, y, i);
}
int p;
cin >> p;
vector<int> f(n);
while (p--) {
int x, y;
cin >> x >> y;
--x; --y;
f[x] += 1;
f[y] -= 1;
}
vector<bool> was(n, false);
vector<bool> bridge(m);
vector<int> col(m);
vector<int> tin(n);
vector<int> low(n);
int t = 0;
function<void(int, int)> Dfs = [&](int v, int id) {
was[v] = true;
tin[v] = ++t;
low[v] = t;
for (auto& e : g[v]) {
int to = e.first;
int i = e.second;
if (i == id) {
continue;
}
if (was[to]) {
low[v] = min(low[v], tin[to]);
} else {
Dfs(to, i);
if (low[to] > tin[v]) {
bridge[i] = true;
}
low[v] = min(low[v], low[to]);
int cx = (get<0>(edges[i]) == v ? 1 : -1);
int cy = (f[to] == 0 ? 0 : (f[to] > 0 ? 1 : -1));
col[i] = cx * cy;
f[v] += f[to];
}
}
};
for (int i = 0; i < n; i++) {
if (!was[i]) {
Dfs(i, -1);
}
}
for (int i = 0; i < m; i++) {
if (!bridge[i] || col[i] == 0) {
cout << 'B';
} else {
cout << (col[i] == 1 ? 'L' : 'R');
}
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
44 ms |
7768 KB |
Output is correct |
12 |
Correct |
42 ms |
9112 KB |
Output is correct |
13 |
Correct |
72 ms |
10760 KB |
Output is correct |
14 |
Correct |
70 ms |
12140 KB |
Output is correct |
15 |
Correct |
63 ms |
12372 KB |
Output is correct |
16 |
Correct |
62 ms |
10332 KB |
Output is correct |
17 |
Correct |
54 ms |
12200 KB |
Output is correct |
18 |
Correct |
67 ms |
10348 KB |
Output is correct |
19 |
Correct |
49 ms |
13652 KB |
Output is correct |
20 |
Correct |
43 ms |
9156 KB |
Output is correct |
21 |
Correct |
49 ms |
8764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
44 ms |
7768 KB |
Output is correct |
12 |
Correct |
42 ms |
9112 KB |
Output is correct |
13 |
Correct |
72 ms |
10760 KB |
Output is correct |
14 |
Correct |
70 ms |
12140 KB |
Output is correct |
15 |
Correct |
63 ms |
12372 KB |
Output is correct |
16 |
Correct |
62 ms |
10332 KB |
Output is correct |
17 |
Correct |
54 ms |
12200 KB |
Output is correct |
18 |
Correct |
67 ms |
10348 KB |
Output is correct |
19 |
Correct |
49 ms |
13652 KB |
Output is correct |
20 |
Correct |
43 ms |
9156 KB |
Output is correct |
21 |
Correct |
49 ms |
8764 KB |
Output is correct |
22 |
Correct |
66 ms |
13444 KB |
Output is correct |
23 |
Correct |
66 ms |
11448 KB |
Output is correct |
24 |
Correct |
76 ms |
11488 KB |
Output is correct |
25 |
Correct |
74 ms |
16988 KB |
Output is correct |
26 |
Correct |
69 ms |
12928 KB |
Output is correct |
27 |
Correct |
86 ms |
11640 KB |
Output is correct |
28 |
Correct |
48 ms |
5180 KB |
Output is correct |
29 |
Correct |
67 ms |
9788 KB |
Output is correct |
30 |
Correct |
60 ms |
10012 KB |
Output is correct |
31 |
Correct |
66 ms |
10420 KB |
Output is correct |
32 |
Correct |
59 ms |
12804 KB |
Output is correct |