#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
const int N=1e5+5;
int n,m,p;
int val[N],val2[N];
char ans[N];
vector<pair<int,int>> adj[N];
bool vis[N],used[N];
void dfs(int u,int p){
vis[u]=true;
for(auto [v,i]:adj[u]){
if(used[abs(i)])continue;
used[abs(i)]=true;
if(!vis[v]){
dfs(v,i);
if(val2[v]>0||val[v]==0)ans[abs(i)]='B';
else ans[abs(i)]=((val[v]<0)^(i>0))?'L':'R';
val[u]+=val[v];
val2[u]+=val2[v];
}else{
ans[abs(i)]='B';
val2[u]++;
val2[v]--;
}
}
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=m;i++){
int u,v;
cin >> u >> v;
adj[u].emplace_back(v,i);
adj[v].emplace_back(u,-i);
}
cin >> p;
for(int i=1;i<=p;i++){
int u,v;
cin >> u >> v;
val[u]++;
val[v]--;
}
for(int i=1;i<=n;i++)if(!vis[i])dfs(i,0);
for(int i=1;i<=m;i++)cout << ans[i];
}
Compilation message
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for(auto [v,i]:adj[u]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2720 KB |
Output is correct |
11 |
Correct |
24 ms |
7028 KB |
Output is correct |
12 |
Correct |
28 ms |
7824 KB |
Output is correct |
13 |
Correct |
33 ms |
8780 KB |
Output is correct |
14 |
Correct |
45 ms |
9420 KB |
Output is correct |
15 |
Correct |
35 ms |
9420 KB |
Output is correct |
16 |
Correct |
27 ms |
7488 KB |
Output is correct |
17 |
Correct |
26 ms |
9012 KB |
Output is correct |
18 |
Correct |
35 ms |
7448 KB |
Output is correct |
19 |
Correct |
27 ms |
10156 KB |
Output is correct |
20 |
Correct |
26 ms |
7368 KB |
Output is correct |
21 |
Correct |
28 ms |
7168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2680 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2720 KB |
Output is correct |
11 |
Correct |
24 ms |
7028 KB |
Output is correct |
12 |
Correct |
28 ms |
7824 KB |
Output is correct |
13 |
Correct |
33 ms |
8780 KB |
Output is correct |
14 |
Correct |
45 ms |
9420 KB |
Output is correct |
15 |
Correct |
35 ms |
9420 KB |
Output is correct |
16 |
Correct |
27 ms |
7488 KB |
Output is correct |
17 |
Correct |
26 ms |
9012 KB |
Output is correct |
18 |
Correct |
35 ms |
7448 KB |
Output is correct |
19 |
Correct |
27 ms |
10156 KB |
Output is correct |
20 |
Correct |
26 ms |
7368 KB |
Output is correct |
21 |
Correct |
28 ms |
7168 KB |
Output is correct |
22 |
Correct |
42 ms |
9020 KB |
Output is correct |
23 |
Correct |
37 ms |
7432 KB |
Output is correct |
24 |
Correct |
39 ms |
7500 KB |
Output is correct |
25 |
Correct |
41 ms |
11964 KB |
Output is correct |
26 |
Correct |
39 ms |
8692 KB |
Output is correct |
27 |
Correct |
37 ms |
7548 KB |
Output is correct |
28 |
Correct |
22 ms |
5072 KB |
Output is correct |
29 |
Correct |
45 ms |
6960 KB |
Output is correct |
30 |
Correct |
39 ms |
7116 KB |
Output is correct |
31 |
Correct |
37 ms |
7404 KB |
Output is correct |
32 |
Correct |
36 ms |
9300 KB |
Output is correct |