This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=3e5+5;
vector<pair<int,pii>>g[mxn],gr[mxn];
pii rd[mxn];
int ans[mxn]{0};
int di[mxn]{0},lo[mxn]{0},cur=0;
bool vis[mxn]{0};
int id[mxn]{0},cc=1;
stack<int>st;
vector<int>qr[mxn];
void dfs(int u,int rd){
di[u]=lo[u]=++cur;vis[u]=1;
st.push(u);
for(auto [v,w]:g[u]){
if(w.f==rd)continue;
if(!di[v])dfs(v,w.f);
if(vis[v])lo[u]=min(lo[u],lo[v]);
}
if(lo[u]==di[u]){
while(st.top()!=u){
int v=st.top();st.pop();
id[v]=cc;vis[v]=0;
}id[u]=cc;cc++;st.pop();vis[u]=0;
}
}
int cn1=0,cn2=0;
bool vv[mxn]{0};
void solve(int u,int rd,int xo){
vis[u]=1;
for(auto [v,w]:gr[u]){
if(vis[v])continue;
solve(v,w.f,w.s);
}
for(auto it : qr[u]){
if(it<0){
if(vv[-it])cn1--,vv[-it]=0;
else cn2++,vv[-it]=1;
}
else {
if(vv[it])cn2--,vv[it]=0;
else cn1++,vv[it]=1;
}
}
if(rd==-1)return;
if(cn1==0&&cn2==0)ans[rd]=2;
else if(cn1>0)ans[rd]=xo;
else if(cn2>0)ans[rd]=xo^1;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
for(int i=0;i<m;i++){
cin>>rd[i].f>>rd[i].s;
if(rd[i].f==rd[i].s){ans[i]=2;continue;}
g[rd[i].f].pb({rd[i].s,{i,0}});g[rd[i].s].pb({rd[i].f,{i,1}});
}
for(int i=1;i<=n;i++){
if(!di[i])dfs(i,-1);
}
for(int i=1;i<=n;i++){
for(auto [v,w]:g[i]){
if(id[i]==id[v])ans[w.f]=2;
else gr[id[i]].pb({id[v],{w.f,w.s}}),gr[id[v]].pb({id[i],{w.f,w.s^1}});
}
}
int p;cin>>p;
for(int i=0;i<p;i++){
int x,y;cin>>x>>y;
if(id[x]==id[y])continue;
qr[id[x]].pb(i+1);
qr[id[y]].pb(-i-1);
}memset(vis,0,sizeof vis);
for(int i=1;i<cc;i++){
if(!vis[i])solve(i,-1,-1);
}
for(int i=0;i<m;i++){
if(ans[i]==2)cout<<'B';
if(ans[i]==1)cout<<'R';
if(ans[i]==0)cout<<'L';
}
}
Compilation message (stderr)
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto [v,w]:g[u]){
| ^
oneway.cpp: In function 'void solve(int, int, int)':
oneway.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(auto [v,w]:gr[u]){
| ^
oneway.cpp: In function 'int main()':
oneway.cpp:76:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
76 | for(auto [v,w]:g[i]){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |