#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
namespace{using namespace std;}
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=1e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
int n,m,pr;
vector<pii> G[MAX];
vector<pii> eg;
int dfn[MAX];
int tme=1;
int low[MAX];
int fa[MAX];
int st[MAX],ed[MAX];
bool vis[MAX];
vector<int> l,r;
void dfsid(int v,int p,int pid) {
fa[v]=pid;
dfn[v]=tme++;
for (auto [i,id]:G[v]) {
if (i==p) {
p=-1;
continue;
}
if (dfn[i]!=-1) continue;
if (vis[i]) continue;
dfsid(i,v,id);
st[v]+=st[i];
ed[v]+=ed[i];
}
vis[v]=true;
}
void dfslow(int v,int p) {
// cout<<v<<" "<<p<<" vp\n";
low[v]=v;
for (auto [i,id]:G[v]) {
if (i==p) {
p=-1;
continue;
}
if (dfn[i]<dfn[v]) {
// cout<<v<<" "<<i<<" vi\n";
if (dfn[i]<dfn[low[v]]) low[v]=i;
continue;
}
if (vis[i]) continue;
dfslow(i,v);
if (dfn[low[i]]<dfn[low[v]]) low[v]=low[i];
}
vis[v]=true;
}
void dfsans(int v,int p) {
if (low[v]==v and v!=1) {
// cout<<v<<" bg\n";
if (st[v]>ed[v]) {
auto [a,b]=eg[fa[v]];
if (v==a) r.push_back(fa[v]);
else l.push_back(fa[v]);
}
if (st[v]<ed[v]) {
auto [a,b]=eg[fa[v]];
if (v==b) r.push_back(fa[v]);
else l.push_back(fa[v]);
}
}
for (auto [i,id]:G[v]) {
if (i==p) {
p=-1;
continue;
}
if (dfn[i]<dfn[v]) continue;
if (vis[i]) continue;
dfsans(i,v);
}
vis[v]=true;
}
int main() {
speed;
cin>>n>>m;
eg.emplace_back(0,0);
for (int i=1;i<=m;i++) {
int a,b;
cin>>a>>b;
eg.emplace_back(a,b);
if (a==b) continue;
G[a].emplace_back(b,i);
G[b].emplace_back(a,i);
}
memset(st,0,sizeof(st));
memset(ed,0,sizeof(ed));
cin>>pr;
for (int i=0;i<pr;i++) {
int a,b;
cin>>a>>b;
st[a]++;
ed[b]++;
}
memset(dfn,-1,sizeof(dfn));
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++) {
if (!vis[i]) dfsid(i,0,0);
}
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++) {
if (!vis[i]) dfslow(i,0);
}
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++) {
if (!vis[i]) dfsans(i,0);
}
// for (int i=1;i<=n;i++) cout<<dfn[i]<<" ";
// cout<<" dfn\n";
// for (int i=1;i<=n;i++) cout<<low[i]<<" ";
// cout<<" low\n";
// for (int i:l) cout<<i<<" ";
// cout<<" l\n";
// for (int i:r) cout<<i<<" ";
// cout<<" r\n";
vector<pair<int,char> > ans;
for (int i:l) ans.emplace_back(i,'L');
for (int i:r) ans.emplace_back(i,'R');
int id=0;
sort(all(ans));
for (int i=1;i<=m;i++) {
if (id<ans.size() and ans[id].F==i) {
cout<<ans[id].S;
id++;
} else cout<<"B";
}
return 0;
}
/*
6 4
1 1
1 2
3 4
5 6
4
2 2
2 1
4 3
5 6
*/
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:143:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
143 | if (id<ans.size() and ans[id].F==i) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4712 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4712 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
30 ms |
10696 KB |
Output is correct |
12 |
Correct |
38 ms |
11568 KB |
Output is correct |
13 |
Correct |
38 ms |
12232 KB |
Output is correct |
14 |
Correct |
43 ms |
12496 KB |
Output is correct |
15 |
Correct |
41 ms |
12492 KB |
Output is correct |
16 |
Correct |
37 ms |
10612 KB |
Output is correct |
17 |
Correct |
39 ms |
13148 KB |
Output is correct |
18 |
Correct |
35 ms |
10436 KB |
Output is correct |
19 |
Correct |
38 ms |
14176 KB |
Output is correct |
20 |
Correct |
33 ms |
10900 KB |
Output is correct |
21 |
Correct |
30 ms |
10452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4712 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
30 ms |
10696 KB |
Output is correct |
12 |
Correct |
38 ms |
11568 KB |
Output is correct |
13 |
Correct |
38 ms |
12232 KB |
Output is correct |
14 |
Correct |
43 ms |
12496 KB |
Output is correct |
15 |
Correct |
41 ms |
12492 KB |
Output is correct |
16 |
Correct |
37 ms |
10612 KB |
Output is correct |
17 |
Correct |
39 ms |
13148 KB |
Output is correct |
18 |
Correct |
35 ms |
10436 KB |
Output is correct |
19 |
Correct |
38 ms |
14176 KB |
Output is correct |
20 |
Correct |
33 ms |
10900 KB |
Output is correct |
21 |
Correct |
30 ms |
10452 KB |
Output is correct |
22 |
Correct |
56 ms |
15556 KB |
Output is correct |
23 |
Correct |
54 ms |
13772 KB |
Output is correct |
24 |
Correct |
54 ms |
14312 KB |
Output is correct |
25 |
Correct |
72 ms |
18548 KB |
Output is correct |
26 |
Correct |
51 ms |
15116 KB |
Output is correct |
27 |
Correct |
52 ms |
14000 KB |
Output is correct |
28 |
Correct |
30 ms |
8912 KB |
Output is correct |
29 |
Correct |
45 ms |
11464 KB |
Output is correct |
30 |
Correct |
43 ms |
11712 KB |
Output is correct |
31 |
Correct |
45 ms |
11972 KB |
Output is correct |
32 |
Correct |
46 ms |
14272 KB |
Output is correct |