#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, cnt, q;
vector <int> e[N], stk;
vector <pair <int, int> > g[N];
int num[N], low[N], ti, comp[N], w[N];
void dfs(int u, int p) {
stk.push_back(u);
low[u] = num[u] = ++ti;
for (int i = 0; i < g[u].size(); ++i) {
int v = g[u][i].first;
int id = g[u][i].second;
if (id == p) continue;
if (comp[v]) continue;
if (!num[v]) {
dfs(v, id);
low[u] = min(low[u], low[v]);
} else low[u] = min(low[u], num[v]);
}
if (low[u] == num[u]) {
++m;
while (stk.size()) {
int v = stk.back();
stk.pop_back();
comp[v] = m;
for (auto w: g[v]) {
if (comp[w.first] && m != comp[w.first]) e[m].push_back(comp[w.first]);
}
if (v == u) break;
}
}
}
void pull(int u) {
num[u] = 1;
for (auto v: e[u]) {
if (!num[v]) pull(v);
w[u] += w[v];
}
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
vector <pair <int, int> > edges;
for (int i = 1; i <= m; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back({v, i});
g[v].push_back({u, i});
edges.push_back({u, v});
}
m = 0;
for (int i = 1; i <= n; ++i) {
if (num[i]) continue;
dfs(i, 0);
}
cin >> q;
while (q--) {
int u, v;
cin >> u >> v;
u = comp[u], v = comp[v];
if (u == v) continue;
++w[u], --w[v];
}
memset(num, 0, sizeof(num));
for (int i = 1; i <= m; ++i) {
if (num[i]) continue;
pull(i);
}
for (int i = 0; i < edges.size(); ++i) {
int u = edges[i].first;
int v = edges[i].second;
u = comp[u], v = comp[v];
if (u == v) {
cout << 'B';
continue;
}
if (u > v) {
if (w[v] < 0) cout << 'R';
if (w[v] > 0) cout << 'L';
if (w[v] == 0) cout << 'B';
} else {
if (w[u] < 0) cout << 'L';
if (w[u] > 0) cout << 'R';
if (w[u] == 0) cout << 'B';
}
}
}
Compilation message
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int i = 0; i < g[u].size(); ++i) {
| ~~^~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:76:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int i = 0; i < edges.size(); ++i) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5412 KB |
Output is correct |
3 |
Correct |
3 ms |
5460 KB |
Output is correct |
4 |
Correct |
3 ms |
5460 KB |
Output is correct |
5 |
Correct |
3 ms |
5516 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
4 ms |
5416 KB |
Output is correct |
10 |
Correct |
4 ms |
5408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5412 KB |
Output is correct |
3 |
Correct |
3 ms |
5460 KB |
Output is correct |
4 |
Correct |
3 ms |
5460 KB |
Output is correct |
5 |
Correct |
3 ms |
5516 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
4 ms |
5416 KB |
Output is correct |
10 |
Correct |
4 ms |
5408 KB |
Output is correct |
11 |
Correct |
41 ms |
11584 KB |
Output is correct |
12 |
Correct |
46 ms |
12460 KB |
Output is correct |
13 |
Correct |
49 ms |
13680 KB |
Output is correct |
14 |
Correct |
54 ms |
14364 KB |
Output is correct |
15 |
Correct |
62 ms |
14400 KB |
Output is correct |
16 |
Correct |
60 ms |
13928 KB |
Output is correct |
17 |
Correct |
56 ms |
16092 KB |
Output is correct |
18 |
Correct |
72 ms |
13952 KB |
Output is correct |
19 |
Correct |
55 ms |
17204 KB |
Output is correct |
20 |
Correct |
43 ms |
12280 KB |
Output is correct |
21 |
Correct |
42 ms |
11928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5332 KB |
Output is correct |
2 |
Correct |
3 ms |
5412 KB |
Output is correct |
3 |
Correct |
3 ms |
5460 KB |
Output is correct |
4 |
Correct |
3 ms |
5460 KB |
Output is correct |
5 |
Correct |
3 ms |
5516 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5460 KB |
Output is correct |
8 |
Correct |
4 ms |
5460 KB |
Output is correct |
9 |
Correct |
4 ms |
5416 KB |
Output is correct |
10 |
Correct |
4 ms |
5408 KB |
Output is correct |
11 |
Correct |
41 ms |
11584 KB |
Output is correct |
12 |
Correct |
46 ms |
12460 KB |
Output is correct |
13 |
Correct |
49 ms |
13680 KB |
Output is correct |
14 |
Correct |
54 ms |
14364 KB |
Output is correct |
15 |
Correct |
62 ms |
14400 KB |
Output is correct |
16 |
Correct |
60 ms |
13928 KB |
Output is correct |
17 |
Correct |
56 ms |
16092 KB |
Output is correct |
18 |
Correct |
72 ms |
13952 KB |
Output is correct |
19 |
Correct |
55 ms |
17204 KB |
Output is correct |
20 |
Correct |
43 ms |
12280 KB |
Output is correct |
21 |
Correct |
42 ms |
11928 KB |
Output is correct |
22 |
Correct |
76 ms |
17276 KB |
Output is correct |
23 |
Correct |
80 ms |
15452 KB |
Output is correct |
24 |
Correct |
77 ms |
15104 KB |
Output is correct |
25 |
Correct |
72 ms |
20544 KB |
Output is correct |
26 |
Correct |
71 ms |
16636 KB |
Output is correct |
27 |
Correct |
69 ms |
15420 KB |
Output is correct |
28 |
Correct |
30 ms |
9448 KB |
Output is correct |
29 |
Correct |
60 ms |
12848 KB |
Output is correct |
30 |
Correct |
57 ms |
13112 KB |
Output is correct |
31 |
Correct |
57 ms |
13396 KB |
Output is correct |
32 |
Correct |
59 ms |
16060 KB |
Output is correct |