#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
vector <pair <int,int> > gg[N];
int vis[N],tin[N],low[N],gr[N],from[N],To[N];
char ans[N];
map <pair <int,int>,int> edg,ind,brg;
int tt=0,Cnt=0;
void dfs_brg(int v,int p){
vis[v]=1;
tt++;
tin[v]=tt;low[v]=tt;
for(auto to : g[v]){
if(to!=p){
if(vis[to])low[v]=min(low[v],tin[to]);
else{
dfs_brg(to,v);
low[v]=min(low[v],low[to]);
if(low[to]>tin[v]){
brg[{to,v}]++;
brg[{v,to}]++;
}
}
}
}
}
void groups(int v){
gr[v]=Cnt;
for(auto to : g[v]){
if(!gr[to] && (!brg[{v,to}] or edg[{v,to}]!=1))groups(to);
}
}
void calc(int v,int p){
vis[v]=1;
for(auto to : gg[v]){
if(to.ff!=p){
calc(to.ff,v);
from[v]=from[to.ff];
To[v]=To[to.ff];
}
}
for(auto to : gg[v]){
if(to.ff!=p){
if(from[to.ff]<To[to.ff]){
if(to.ss<0)ans[abs(to.ss)]='L';
else ans[to.ss]='R';
}
else if(from[to.ff]>To[to.ss]){
if(to.ss<0)ans[abs(to.ss)]='R';
else ans[to.ss]='L';
}
}
}
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> a(m+1),b(m+1);
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
edg[{a[i],b[i]}]++;
edg[{b[i],a[i]}]++;
ind[{a[i],b[i]}]=i;
ind[{b[i],a[i]}]=-i;
g[a[i]].pb(b[i]);
g[b[i]].pb(a[i]);
}
for(int i=1;i<=n;i++){
if(!vis[i])dfs_brg(i,0);
}
for(int i=1;i<=n;i++){
if(!gr[i]){
Cnt++;
groups(i);
}
}
for(int i=1;i<=m;i++){
if(gr[a[i]]!=gr[b[i]]){
gg[gr[a[i]]].pb({gr[b[i]],ind[{a[i],b[i]}]});
gg[gr[b[i]]].pb({gr[a[i]],ind[{b[i],a[i]}]});
}
}
int qq;
cin>>qq;
while(qq--){
int s,t;
cin>>s>>t;
from[gr[s]]++;
To[gr[t]]++;
}
for(int i=1;i<=m;i++)ans[i]='B';
for(int i=1;i<=n;i++)vis[i]=0;
for(int i=1;i<=Cnt;i++){
if(!vis[i])calc(i,0);
}
for(int i=1;i<=m;i++)cout<<ans[i];
}
/*
5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |