/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 2e5+100, M = 1e5+10, K = 20;
int n, m, p, tin[N], tout[N], up[N][K], par[N][2], lo[N], timer = 0, ti[N], dp[N];
vector<pair<int, int>> g[N], f[N];
vector<bool> vis, bridge;
string s = "";
void st(int v){
vis[v] = 1;
for(auto U: g[v]){
int u = U.first, idx = U.second;
if(!vis[u]){
f[v].pb({u, idx});
f[u].pb({v, idx^1});
par[u][0] = v;
par[u][1] = idx;
st(u);
}
}
}
void pre(int v, int p){
tin[v] = timer++;
up[v][0] = p;
for(auto U: f[v]){
int u = U.first;
if(u != p){
pre(u, v);
}
}
tout[v] = timer++;
}
bool is_ancestor(int u, int v){
return tin[u] <= tin[v] && tout[v] <= tout[u];
}
int _lca(int u, int v){
if(is_ancestor(u, v)) return u;
if(is_ancestor(v, u)) return v;
for(int j = K - 1; j >= 0 ;--j){
if(!is_ancestor(up[u][j], v)) u = up[u][j];
}
return up[u][0];
}
void bf(int v, int pp){
ti[v] = lo[v] = timer++;
vis[v] = 1;
for(auto U: g[v]){
int u = U.first, idx = U.second;
if(idx/2 == pp/2) continue;
if(vis[u]){
lo[v] = min(lo[v], ti[u]);
}else{
bf(u, idx);
lo[v] = min(lo[v], lo[u]);
if(lo[u] > ti[v]){
bridge[idx>>1] = 1;
}
}
}
}
int dfs(int v, int p){
int w = 0;
vis[v] = 1;
for(auto U: f[v]){
int u = U.first;
if(u != p){
w += dfs(u, v);
}
}
w += dp[v];
if(p != v){
if(w < 0){
int e = par[v][1];
if(bridge[e>>1]){
s[e>>1] = ((e&1)^1) ? 'R' : 'L';
}
}else if(w > 0){
int e = par[v][1];
if(bridge[e>>1]){
s[e>>1] = (e&1) ? 'R' : 'L';
}
}
}
return w;
}
void solve(){
cin >> n >> m;
for(int i = 0 ; i < m; ++i){
int u, v; cin >> u >> v;
g[u].pb({v, i*2});
g[v].pb({u, i*2+1});
s += 'B';
}
vis.resize(n + 1, 0);
for(int i = 1; i <= n; ++i) if(!vis[i]) st(i), pre(i, i);
for(int j = 1; j < K; ++j) for(int i = 1; i <= n; ++i) up[i][j] = up[up[i][j - 1]][j - 1];
vis.clear();
vis.resize(n + 1, 0);
bridge.resize(m, 0);
timer = 0;
for(int i = 1; i <= n; ++i) if(!vis[i]) bf(i, MOD);
cin >> p;
for(int i = 0; i < p; ++i){
int u, v; cin >> u >> v;
dp[u]++;
dp[v]--;
}
vis.clear();
vis.resize(n, 0);
for(int i = 1; i <= n; ++i) if(!vis[i]) dfs(i, i);
cout << s;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// freopen("in.txt", "r", stdin);
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:136:14: warning: unused variable 'aa' [-Wunused-variable]
136 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9844 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9956 KB |
Output is correct |
8 |
Correct |
7 ms |
9864 KB |
Output is correct |
9 |
Correct |
5 ms |
9868 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9844 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9956 KB |
Output is correct |
8 |
Correct |
7 ms |
9864 KB |
Output is correct |
9 |
Correct |
5 ms |
9868 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
42 ms |
17388 KB |
Output is correct |
12 |
Correct |
57 ms |
19928 KB |
Output is correct |
13 |
Correct |
67 ms |
23584 KB |
Output is correct |
14 |
Correct |
85 ms |
28156 KB |
Output is correct |
15 |
Correct |
98 ms |
29360 KB |
Output is correct |
16 |
Correct |
99 ms |
28780 KB |
Output is correct |
17 |
Correct |
91 ms |
30924 KB |
Output is correct |
18 |
Correct |
88 ms |
29132 KB |
Output is correct |
19 |
Correct |
93 ms |
32040 KB |
Output is correct |
20 |
Correct |
65 ms |
22348 KB |
Output is correct |
21 |
Correct |
52 ms |
22092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9844 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9956 KB |
Output is correct |
8 |
Correct |
7 ms |
9864 KB |
Output is correct |
9 |
Correct |
5 ms |
9868 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
42 ms |
17388 KB |
Output is correct |
12 |
Correct |
57 ms |
19928 KB |
Output is correct |
13 |
Correct |
67 ms |
23584 KB |
Output is correct |
14 |
Correct |
85 ms |
28156 KB |
Output is correct |
15 |
Correct |
98 ms |
29360 KB |
Output is correct |
16 |
Correct |
99 ms |
28780 KB |
Output is correct |
17 |
Correct |
91 ms |
30924 KB |
Output is correct |
18 |
Correct |
88 ms |
29132 KB |
Output is correct |
19 |
Correct |
93 ms |
32040 KB |
Output is correct |
20 |
Correct |
65 ms |
22348 KB |
Output is correct |
21 |
Correct |
52 ms |
22092 KB |
Output is correct |
22 |
Correct |
102 ms |
31876 KB |
Output is correct |
23 |
Correct |
106 ms |
30040 KB |
Output is correct |
24 |
Correct |
171 ms |
30296 KB |
Output is correct |
25 |
Correct |
101 ms |
35492 KB |
Output is correct |
26 |
Correct |
99 ms |
31524 KB |
Output is correct |
27 |
Correct |
111 ms |
30164 KB |
Output is correct |
28 |
Correct |
33 ms |
13260 KB |
Output is correct |
29 |
Correct |
73 ms |
23092 KB |
Output is correct |
30 |
Correct |
68 ms |
23168 KB |
Output is correct |
31 |
Correct |
82 ms |
23564 KB |
Output is correct |
32 |
Correct |
75 ms |
27532 KB |
Output is correct |