#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
int n, m, p, Redge[N];
vector<pp> e[N], newE[N];
int num[N], low[N], cnt, mark[N], nBico;
stack<int> st;
char res[N];
void dfs(int u, int p) {
num[u] = low[u] = ++cnt;
st.push(u);
for(pp x : e[u]) if (x.second != p) {
int v = x.first;
if (num[v] == 0) {
dfs(v, x.second);
low[u] = min(low[v], low[u]);
if (low[v] >= num[v]) {
++nBico;
while (true) {
int z = st.top(); st.pop();
mark[z] = nBico;
if (z == v) break;
}
}
} else low[u] = min(low[u], num[v]);
}
if (p == -1) {
++nBico;
while (true) {
int z = st.top(); st.pop();
mark[z] = nBico;
if (z == u) break;
}
}
}
void NewGraph() {
FOR(u, 1, n) {
for (pp x : e[u]) if (mark[u] != mark[x.first]) {
newE[mark[u]].push_back(pp(mark[x.first], x.second));
}
}
}
int w[N];
int visited[N];
void dfs2(int u, int p) {
visited[u] = 1;
for (pp x : newE[u]) if (x.second != p) {
dfs2(x.first, x.second);
w[u] += w[x.first];
if (w[x.first] == 0) res[x.second] == 'B';
else {
if (w[x.first] > 0) {
if (mark[Redge[x.second]] == u) res[x.second] = 'R';
else res[x.second] = 'L';
}
else {
if (mark[Redge[x.second]] == u) res[x.second] = 'L';
else res[x.second] = 'R';
}
}
}
}
void Solve() {
cin >> p;
REP(i, p) {
int u, v;
cin >> u >> v;
if (mark[u] == mark[v]) continue;
w[mark[u]]++;
w[mark[v]]--;
}
FOR(i, 1, m) res[i] = 'B';
FOR(i, 1, nBico) if (!visited[i]) dfs2(i, -1);
FOR(i, 1, m) cout << res[i];
}
int main() {
#ifdef NERO
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
double stime = clock();
#else
//freopen(taskname".inp","r",stdin);
//freopen(taskname".out","w",stdout);
#endif //NERO
IO;
cin >> n >> m;
FOR(i, 1, m) {
int u, v;
cin >> u >> v;
e[u].push_back(pp(v, i));
e[v].push_back(pp(u, i));
Redge[i] = v;
}
FOR(i, 1, n) if (num[i] == 0) dfs(i, -1);
NewGraph();
//FOR(i, 1, n) cout << i << ' ' << mark[i] << '\n';
Solve();
#ifdef NERO
double etime = clock();
cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.\n";
#endif // NERO
}
Compilation message
oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:64:44: warning: statement has no effect [-Wunused-value]
if (w[x.first] == 0) res[x.second] == 'B';
~~~~~~~~~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
2 |
Correct |
41 ms |
47460 KB |
Output is correct |
3 |
Correct |
42 ms |
47664 KB |
Output is correct |
4 |
Correct |
41 ms |
47728 KB |
Output is correct |
5 |
Correct |
41 ms |
47728 KB |
Output is correct |
6 |
Correct |
41 ms |
47728 KB |
Output is correct |
7 |
Correct |
41 ms |
47728 KB |
Output is correct |
8 |
Correct |
41 ms |
47728 KB |
Output is correct |
9 |
Correct |
51 ms |
47728 KB |
Output is correct |
10 |
Correct |
47 ms |
47728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
2 |
Correct |
41 ms |
47460 KB |
Output is correct |
3 |
Correct |
42 ms |
47664 KB |
Output is correct |
4 |
Correct |
41 ms |
47728 KB |
Output is correct |
5 |
Correct |
41 ms |
47728 KB |
Output is correct |
6 |
Correct |
41 ms |
47728 KB |
Output is correct |
7 |
Correct |
41 ms |
47728 KB |
Output is correct |
8 |
Correct |
41 ms |
47728 KB |
Output is correct |
9 |
Correct |
51 ms |
47728 KB |
Output is correct |
10 |
Correct |
47 ms |
47728 KB |
Output is correct |
11 |
Correct |
96 ms |
52444 KB |
Output is correct |
12 |
Correct |
97 ms |
53332 KB |
Output is correct |
13 |
Correct |
112 ms |
54496 KB |
Output is correct |
14 |
Correct |
125 ms |
55808 KB |
Output is correct |
15 |
Correct |
140 ms |
56300 KB |
Output is correct |
16 |
Correct |
149 ms |
57764 KB |
Output is correct |
17 |
Correct |
154 ms |
59140 KB |
Output is correct |
18 |
Correct |
157 ms |
59140 KB |
Output is correct |
19 |
Correct |
156 ms |
60476 KB |
Output is correct |
20 |
Correct |
99 ms |
60476 KB |
Output is correct |
21 |
Correct |
93 ms |
60476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
2 |
Correct |
41 ms |
47460 KB |
Output is correct |
3 |
Correct |
42 ms |
47664 KB |
Output is correct |
4 |
Correct |
41 ms |
47728 KB |
Output is correct |
5 |
Correct |
41 ms |
47728 KB |
Output is correct |
6 |
Correct |
41 ms |
47728 KB |
Output is correct |
7 |
Correct |
41 ms |
47728 KB |
Output is correct |
8 |
Correct |
41 ms |
47728 KB |
Output is correct |
9 |
Correct |
51 ms |
47728 KB |
Output is correct |
10 |
Correct |
47 ms |
47728 KB |
Output is correct |
11 |
Correct |
96 ms |
52444 KB |
Output is correct |
12 |
Correct |
97 ms |
53332 KB |
Output is correct |
13 |
Correct |
112 ms |
54496 KB |
Output is correct |
14 |
Correct |
125 ms |
55808 KB |
Output is correct |
15 |
Correct |
140 ms |
56300 KB |
Output is correct |
16 |
Correct |
149 ms |
57764 KB |
Output is correct |
17 |
Correct |
154 ms |
59140 KB |
Output is correct |
18 |
Correct |
157 ms |
59140 KB |
Output is correct |
19 |
Correct |
156 ms |
60476 KB |
Output is correct |
20 |
Correct |
99 ms |
60476 KB |
Output is correct |
21 |
Correct |
93 ms |
60476 KB |
Output is correct |
22 |
Correct |
178 ms |
60476 KB |
Output is correct |
23 |
Correct |
166 ms |
60476 KB |
Output is correct |
24 |
Correct |
206 ms |
60476 KB |
Output is correct |
25 |
Correct |
177 ms |
62668 KB |
Output is correct |
26 |
Correct |
166 ms |
62668 KB |
Output is correct |
27 |
Correct |
172 ms |
62668 KB |
Output is correct |
28 |
Correct |
86 ms |
62668 KB |
Output is correct |
29 |
Correct |
120 ms |
62668 KB |
Output is correct |
30 |
Correct |
120 ms |
62668 KB |
Output is correct |
31 |
Correct |
123 ms |
62668 KB |
Output is correct |
32 |
Correct |
130 ms |
62668 KB |
Output is correct |