#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
typedef long long ll;
using namespace std;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > stablo[MAXN];
int n,m,p;
bool most[MAXN],obidjen[MAXN];
int ulaz[MAXN],dub[MAXN];
int predak[MAXN][21];
int grupa[MAXN];
int vreme;
int dokle[MAXN],smer[MAXN];
int leva[MAXN];
char s[MAXN];
int dfsM(int t,int o){
vreme++;
ulaz[t]=vreme;
obidjen[t]=true;
int minv=vreme;
for(auto x:niz[t]){
if(x.F==o)continue;
int tv;
if(obidjen[x.F])tv=ulaz[x.F];
else tv=dfsM(x.F,t);
if(tv>ulaz[t])most[x.S]=true;
minv=min(minv,tv);
}
return minv;
}
void dfsS(int t,int kad,int h){
grupa[t]=kad;
obidjen[t]=true;
dub[kad]=h;
for(auto x:niz[t]){
if(obidjen[x.F])continue;
if(most[x.S]){
vreme++;
stablo[kad].pb(mp(vreme,x.S));
predak[vreme][0]=kad;
dfsS(x.F,vreme,h+1);
}
else dfsS(x.F,kad,h);
}
}
int lca(int a,int b){
if(dub[b]>dub[a])swap(a,b);
for(int j=20;j>=0;j--)
if(dub[predak[a][j]]>=dub[b])
a=predak[a][j];
if(a==b)return a;
for(int j=20;j>=0;j--){
if(predak[a][j]!=predak[b][j]){
a=predak[a][j];
b=predak[b][j];
}
}
return predak[a][0];
}
void dfs(int t,int o,int caleg){
//printf("%d %d\n",t,caleg);
for(auto x:stablo[t]){
if(x.F==o)continue;
dfs(x.F,t,x.S);
}
if(o==0 || dokle[t]==0)return;
if(smer[t]==1){
if(t==leva[caleg-1])s[caleg-1]='R';
else s[caleg-1]='L';
}else{
if(t==leva[caleg-1])s[caleg-1]='L';
else s[caleg-1]='R';
}
if(dokle[t]==o)return;
if(dokle[o]==0 || dokle[o]>dokle[t])dokle[o]=dokle[t];
smer[o]=smer[t];
}
int main()
{
scanf("%d %d", &n, &m);
for(int i=1;i<=m;i++){
int t1,t2;
scanf("%d %d", &t1, &t2);
niz[t1].pb(mp(t2,i));
niz[t2].pb(mp(t1,i));
leva[i]=t1;
}
dfsM(1,0);
vreme=1;
memset(obidjen,0,sizeof(obidjen));
dfsS(1,1,1);
for(int j=1;j<21;j++){
for(int i=1;i<=vreme;i++){
predak[i][j]=predak[predak[i][j-1]][j-1];
}
}
scanf("%d", &p);
while(p--){
int a,b;
scanf("%d %d", &a, &b);
a=grupa[a];
b=grupa[b];
int najnizi=lca(a,b);
dokle[a]=dokle[b]=najnizi;
smer[a]=-1;
smer[b]=1;
}
for(int i=0;i<m;i++)s[i]='B';
s[m]=0;
dfs(1,0,0);
printf("%s",s);
return 0;
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:100:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &t1, &t2);
~~~~~^~~~~~~~~~~~~~~~~~~
oneway.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &p);
~~~~~^~~~~~~~~~
oneway.cpp:120:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |