#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){
vis[u]=true;
for(auto [v,i]:adj[u]){
if(used[i>>1])continue;
used[i>>1]=true;
if(!vis[v]){
dfs(v);
ans[i>>1]=(val2[v]>0||!val[v])?'B':((val[v]>0)^(i&1))?'L':'R';
val[u]+=val[v];
val2[u]+=val2[v];
}else{
ans[i>>1]='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<<1);
adj[v].emplace_back(u,i<<1|1);
}
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);
for(int i=1;i<=m;i++)cout << ans[i];
}
Compilation message
oneway.cpp: In function 'void dfs(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]){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
25 ms |
7296 KB |
Output is correct |
12 |
Correct |
27 ms |
8212 KB |
Output is correct |
13 |
Correct |
31 ms |
9228 KB |
Output is correct |
14 |
Correct |
34 ms |
9872 KB |
Output is correct |
15 |
Correct |
33 ms |
9832 KB |
Output is correct |
16 |
Correct |
28 ms |
7508 KB |
Output is correct |
17 |
Correct |
27 ms |
9384 KB |
Output is correct |
18 |
Correct |
27 ms |
7476 KB |
Output is correct |
19 |
Correct |
38 ms |
10680 KB |
Output is correct |
20 |
Correct |
26 ms |
7612 KB |
Output is correct |
21 |
Correct |
26 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
25 ms |
7296 KB |
Output is correct |
12 |
Correct |
27 ms |
8212 KB |
Output is correct |
13 |
Correct |
31 ms |
9228 KB |
Output is correct |
14 |
Correct |
34 ms |
9872 KB |
Output is correct |
15 |
Correct |
33 ms |
9832 KB |
Output is correct |
16 |
Correct |
28 ms |
7508 KB |
Output is correct |
17 |
Correct |
27 ms |
9384 KB |
Output is correct |
18 |
Correct |
27 ms |
7476 KB |
Output is correct |
19 |
Correct |
38 ms |
10680 KB |
Output is correct |
20 |
Correct |
26 ms |
7612 KB |
Output is correct |
21 |
Correct |
26 ms |
7372 KB |
Output is correct |
22 |
Correct |
40 ms |
9420 KB |
Output is correct |
23 |
Correct |
37 ms |
7436 KB |
Output is correct |
24 |
Correct |
40 ms |
7572 KB |
Output is correct |
25 |
Correct |
49 ms |
12984 KB |
Output is correct |
26 |
Correct |
40 ms |
8952 KB |
Output is correct |
27 |
Correct |
39 ms |
7632 KB |
Output is correct |
28 |
Correct |
24 ms |
5204 KB |
Output is correct |
29 |
Correct |
38 ms |
7156 KB |
Output is correct |
30 |
Correct |
43 ms |
7292 KB |
Output is correct |
31 |
Correct |
37 ms |
7672 KB |
Output is correct |
32 |
Correct |
37 ms |
9912 KB |
Output is correct |