#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
const int mxn=1e5+5;
vector<int>adj[mxn];
unordered_set<int>nw[mxn];
int val[mxn];
int d[mxn];
struct edge{
int v,u;
};
vector<edge>e;
bitset<mxn>vis;
int dfn[mxn],low[mxn];
int timer=0;
stack<int>st;
int bccnt=0;
bool ins[mxn];
vector<int>id(mxn);
void tarjan(int v,int pa=-1){
dfn[v]=low[v]=++timer;
st.push(v);
ins[v]=1;
for(auto u:adj[v]){
if(u==pa){
pa=-1;
continue;
}
if(!dfn[u]){
tarjan(u,v);
chmin(low[v],low[u]);
}
else if(ins[u]){
chmin(low[v],dfn[u]);
}
}
if(dfn[v]==low[v]){
while(st.top()!=v){
id[st.top()]=bccnt;
ins[st.top()]=0;
st.pop();
}
id[st.top()]=bccnt;
ins[st.top()]=0;
st.pop();
bccnt++;
}
}
void dfs2(int v,int pa=-1){
for(auto u:nw[v]){
if(u==pa)continue;
d[u]=d[v]+1;
dfs2(u,v);
val[v]+=val[u];
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
e.pb({a,b});
adj[a].pb(b);
adj[b].pb(a);
}
for(int i=1;i<=n;i++){
if(!dfn[i])tarjan(i,-1);
}
for(int i=0;i<m;i++){
int a=e[i].v;
int b=e[i].u;
int x=id[a];
int y=id[b];
if(x!=y){
nw[x].insert(y);
nw[y].insert(x);
}
}
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;
val[id[a]]++;
val[id[b]]--;
}
for(int i=0;i<bccnt;i++){
if(!d[i])dfs2(i);
}
for(int i=0;i<m;i++){
int x=id[e[i].v];
int y=id[e[i].u];
if(x==y){
cout<<"B";
}
else{
if(d[x]>d[y]){
if(val[x]==0)cout<<"B";
else if(val[x]>0)cout<<"R";
else cout<<"L";
}
else{
if(val[y]==0)cout<<"B";
else if(val[y]<0)cout<<"R";
else cout<<"L";
}
}
}
}
/*
input:
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8916 KB |
Output is correct |
2 |
Correct |
5 ms |
8868 KB |
Output is correct |
3 |
Correct |
5 ms |
9044 KB |
Output is correct |
4 |
Correct |
5 ms |
9172 KB |
Output is correct |
5 |
Correct |
6 ms |
9172 KB |
Output is correct |
6 |
Correct |
5 ms |
9044 KB |
Output is correct |
7 |
Correct |
4 ms |
9172 KB |
Output is correct |
8 |
Correct |
4 ms |
9228 KB |
Output is correct |
9 |
Correct |
5 ms |
8968 KB |
Output is correct |
10 |
Correct |
4 ms |
9044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8916 KB |
Output is correct |
2 |
Correct |
5 ms |
8868 KB |
Output is correct |
3 |
Correct |
5 ms |
9044 KB |
Output is correct |
4 |
Correct |
5 ms |
9172 KB |
Output is correct |
5 |
Correct |
6 ms |
9172 KB |
Output is correct |
6 |
Correct |
5 ms |
9044 KB |
Output is correct |
7 |
Correct |
4 ms |
9172 KB |
Output is correct |
8 |
Correct |
4 ms |
9228 KB |
Output is correct |
9 |
Correct |
5 ms |
8968 KB |
Output is correct |
10 |
Correct |
4 ms |
9044 KB |
Output is correct |
11 |
Correct |
30 ms |
15468 KB |
Output is correct |
12 |
Correct |
38 ms |
16472 KB |
Output is correct |
13 |
Correct |
52 ms |
17940 KB |
Output is correct |
14 |
Correct |
50 ms |
22232 KB |
Output is correct |
15 |
Correct |
53 ms |
23876 KB |
Output is correct |
16 |
Correct |
112 ms |
35296 KB |
Output is correct |
17 |
Correct |
98 ms |
36820 KB |
Output is correct |
18 |
Correct |
126 ms |
35232 KB |
Output is correct |
19 |
Correct |
74 ms |
37892 KB |
Output is correct |
20 |
Correct |
35 ms |
16272 KB |
Output is correct |
21 |
Correct |
39 ms |
16120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8916 KB |
Output is correct |
2 |
Correct |
5 ms |
8868 KB |
Output is correct |
3 |
Correct |
5 ms |
9044 KB |
Output is correct |
4 |
Correct |
5 ms |
9172 KB |
Output is correct |
5 |
Correct |
6 ms |
9172 KB |
Output is correct |
6 |
Correct |
5 ms |
9044 KB |
Output is correct |
7 |
Correct |
4 ms |
9172 KB |
Output is correct |
8 |
Correct |
4 ms |
9228 KB |
Output is correct |
9 |
Correct |
5 ms |
8968 KB |
Output is correct |
10 |
Correct |
4 ms |
9044 KB |
Output is correct |
11 |
Correct |
30 ms |
15468 KB |
Output is correct |
12 |
Correct |
38 ms |
16472 KB |
Output is correct |
13 |
Correct |
52 ms |
17940 KB |
Output is correct |
14 |
Correct |
50 ms |
22232 KB |
Output is correct |
15 |
Correct |
53 ms |
23876 KB |
Output is correct |
16 |
Correct |
112 ms |
35296 KB |
Output is correct |
17 |
Correct |
98 ms |
36820 KB |
Output is correct |
18 |
Correct |
126 ms |
35232 KB |
Output is correct |
19 |
Correct |
74 ms |
37892 KB |
Output is correct |
20 |
Correct |
35 ms |
16272 KB |
Output is correct |
21 |
Correct |
39 ms |
16120 KB |
Output is correct |
22 |
Correct |
97 ms |
36760 KB |
Output is correct |
23 |
Correct |
91 ms |
35268 KB |
Output is correct |
24 |
Correct |
115 ms |
35268 KB |
Output is correct |
25 |
Correct |
83 ms |
39728 KB |
Output is correct |
26 |
Correct |
108 ms |
36356 KB |
Output is correct |
27 |
Correct |
101 ms |
35240 KB |
Output is correct |
28 |
Correct |
29 ms |
13156 KB |
Output is correct |
29 |
Correct |
55 ms |
15772 KB |
Output is correct |
30 |
Correct |
45 ms |
16016 KB |
Output is correct |
31 |
Correct |
57 ms |
16436 KB |
Output is correct |
32 |
Correct |
55 ms |
23612 KB |
Output is correct |