#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, M, Q;
cin>>N>>M;
int E[M*2+2], F[M*2+2], G[N]{};
for(int i=1; i<=M; i++) {
int a, b;
cin>>a>>b; --a, --b;
E[i*2]=b, F[i*2]=G[a], G[a]=i*2;
E[i*2+1]=a, F[i*2+1]=G[b], G[b]=i*2+1;
}
int A[N]{}, T[N], P[N], t=0;
char V[max(N, M)+1]{};
function<int(int)> root=[&](int i) {
return P[i]>=0 ? P[i]=root(P[i]) : i;
};
auto up=[&](int&i) { i=P[i]=root(~P[i]); };
function<void(int, int)> bcc=[&](int i, int p) {
A[i]=T[i]=++t;
for(int e=G[i]; e; e=F[e]) if(e!=p) {
int&j=E[e];
if(A[j]) { T[i]=min(T[i], A[j]); continue; }
V[e>>1]=e&1, P[j]=~i;
bcc(j, e^1);
T[i]=min(T[i], T[j]);
if(A[i]<T[j]) V[e>>1]|=2;
}
};
for(int i=0; i<N; i++) if(!A[i]) P[i]=~i, bcc(i, 0);
cin>>Q;
while(Q--) {
int i, j, a=4, b=8;
cin>>i>>j; --i, --j;
if(A[i]<A[j]) swap(i, j), swap(a, b);
for(i=root(i); A[i]>A[j]; up(i)) V[i]|=a;
for(j=root(j); A[j]>A[i]; up(j)) V[j]|=b;
}
for(int i=1; i<=M; i++) {
int v=V[i], u=v&1, t=V[E[i*2^u]]>>2;
cout<<((v&2) && t ? (t^u)&1 ? 'L' : 'R' : 'B');
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
38 ms |
4748 KB |
Output is correct |
12 |
Correct |
32 ms |
5684 KB |
Output is correct |
13 |
Correct |
36 ms |
6660 KB |
Output is correct |
14 |
Correct |
35 ms |
7288 KB |
Output is correct |
15 |
Correct |
36 ms |
7324 KB |
Output is correct |
16 |
Correct |
30 ms |
4684 KB |
Output is correct |
17 |
Correct |
34 ms |
6724 KB |
Output is correct |
18 |
Correct |
34 ms |
4776 KB |
Output is correct |
19 |
Correct |
34 ms |
8196 KB |
Output is correct |
20 |
Correct |
34 ms |
6344 KB |
Output is correct |
21 |
Correct |
26 ms |
5580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
38 ms |
4748 KB |
Output is correct |
12 |
Correct |
32 ms |
5684 KB |
Output is correct |
13 |
Correct |
36 ms |
6660 KB |
Output is correct |
14 |
Correct |
35 ms |
7288 KB |
Output is correct |
15 |
Correct |
36 ms |
7324 KB |
Output is correct |
16 |
Correct |
30 ms |
4684 KB |
Output is correct |
17 |
Correct |
34 ms |
6724 KB |
Output is correct |
18 |
Correct |
34 ms |
4776 KB |
Output is correct |
19 |
Correct |
34 ms |
8196 KB |
Output is correct |
20 |
Correct |
34 ms |
6344 KB |
Output is correct |
21 |
Correct |
26 ms |
5580 KB |
Output is correct |
22 |
Correct |
55 ms |
7860 KB |
Output is correct |
23 |
Correct |
54 ms |
5916 KB |
Output is correct |
24 |
Correct |
57 ms |
5988 KB |
Output is correct |
25 |
Correct |
60 ms |
11588 KB |
Output is correct |
26 |
Correct |
62 ms |
7364 KB |
Output is correct |
27 |
Correct |
64 ms |
6072 KB |
Output is correct |
28 |
Correct |
34 ms |
3112 KB |
Output is correct |
29 |
Correct |
53 ms |
7224 KB |
Output is correct |
30 |
Correct |
55 ms |
6772 KB |
Output is correct |
31 |
Correct |
54 ms |
8436 KB |
Output is correct |
32 |
Correct |
51 ms |
8864 KB |
Output is correct |