#include<bits/stdc++.h>
using namespace std;
int n,m,k,u,v,mn[200005],ind[200005],fix[200005],bridge[200005],F[200005],sum[200005],timer,tmin[200005],q;
char ans[200005];
vector<pair<int,pair<int,int> > >V[200005],B[200005];
void dfs(int u,int p){
fix[u]=1;
timer++;
tmin[u]=mn[u]=timer;
for(int i=0;i<V[u].size();i++){
int v=V[u][i].first;
if(v==p) continue;
if(fix[v]==0){
dfs(v,u);
mn[u]=min(mn[u],mn[v]);
if(mn[v]>tmin[u]){
bridge[V[u][i].second.first]=1;
F[v]=1;
F[u]=1;
}
}
else mn[u]=min(mn[u],tmin[v]);
}
// cout<<u<<"++"<<mn[u]<<endl;
}
void dfs1(int u,int p,int nm){
if(nm==1)fix[u]=2;
else fix[u]=4;
if(nm==1)ind[u]=p;
for(int i=0;i<V[u].size();i++){
int c=0;
if(nm==2) c=4;else c=2;
if(nm==2)if(bridge[V[u][i].second.first]!=0 &&fix[V[u][i].first]!=c){
int v=V[u][i].first;
B[ind[v]].push_back({p,{V[u][i].second.first,V[u][i].second.second}});
B[p].push_back({ind[v],{V[u][i].second.first,1-V[u][i].second.second}});
}
if(fix[V[u][i].first]!=c && bridge[V[u][i].second.first]==0){
dfs1(V[u][i].first,p,nm);
}
}
}
void dfs2(int u,int p){
fix[u]=3;
for(int i=0;i<B[u].size();i++){
int v=B[u][i].first;
if(v!=p ){
dfs2(v,u); sum[u]+=sum[v];
if(sum[v]>0){
if(B[u][i].second.second==1){
ans[B[u][i].second.first]='R';
}
else ans[B[u][i].second.first]='L';
}
if(sum[v]<0){
if(B[u][i].second.second==1){
ans[B[u][i].second.first]='L';
}
else ans[B[u][i].second.first]='R';
}
}
}
}
int main(){
cin>>n>>m;
for(k=1;k<=m;k++){
cin>>u>>v;
V[u].push_back({v,{k,1}});
V[v].push_back({u,{k,0}});
ans[k]='B';
}
for(k=1;k<=n;k++)
if(!fix[k])
dfs(k,0);
for(k=1;k<=n;k++){
if(F[k] && fix[k]!=2)dfs1(k,k,1);
}
for(k=1;k<=n;k++){
if(F[k] && fix[k]!=4)dfs1(k,k,2);
}
cin>>q;
while(q--){
cin>>u>>v;
sum[ind[u]]++; sum[ind[v]]--;
}
for(k=1;k<=n;k++){
if(fix[ind[k]]!=3 ){
dfs2(ind[k],0);}}
for(k=1;k<=m;k++){
cout<<ans[k];
}
}
Compilation message
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<V[u].size();i++){
~^~~~~~~~~~~~
oneway.cpp: In function 'void dfs1(int, int, int)':
oneway.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<V[u].size();i++){
~^~~~~~~~~~~~
oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:50:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<B[u].size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Output is correct |
2 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |