#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){
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(fix[v]==0){
dfs(v);
}
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;
B[v].push_back({u,{V[u][i].second.first,V[u][i].second.second}});
B[u].push_back({v,{V[u][i].second.first,1-V[u][i].second.second}});
}
}
// cout<<u<<"++"<<mn[u]<<endl;
}
void dfs1(int u,int p){
fix[u]=2;
ind[u]=p;
for(int i=0;i<V[u].size();i++){
if(fix[V[u][i].first]!=2 && bridge[V[u][i].second.first]==0){
dfs1(V[u][i].first,p);
}
}
}
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(V[u][i].second.second==1){
ans[V[u][i].second.first]='L';
}
else ans[V[u][i].second.first]='R';
}
if(sum[v]<0){
if(V[u][i].second.second==1){
ans[V[u][i].second.first]='R';
}
else ans[V[u][i].second.first]='L';
}
}
}
}
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);
for(k=1;k<=n;k++){
if(F[k])dfs1(k,k);
}
cin>>q;
while(q--){
cin>>u>>v;
sum[ind[u]]++; sum[ind[v]]--;
}
for(k=1;k<=n;k++){
if(fix[k]!=3)
dfs2(k,0);}
for(k=1;k<=m;k++){
cout<<ans[k];
}
}
Compilation message
oneway.cpp: In function 'void dfs(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)':
oneway.cpp:31: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:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<B[u].size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
9728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |