/*Author: KawakiMeido*/
#include <bits/stdc++.h>
#define pb push_back
#define endl "\n"
#define ll long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second
using namespace std;
/*Constants*/
const int N = 2e5+10;
const int INF = 1e9+7;
const long long LLINF = 1e18+3;
/*TestCases*/
int test=1;
void solve();
void TestCases(bool v){
if (v) cin >> test;
while(test--) solve();
}
/*Global Variables*/
int n,m,timedfs=0,q;
vector<piii> adj[N];
int num[N],low[N];
int dir[N];
int pre[N];
int luutmp[N];
bool IsBridge[N];
//DSU
//void Init(){
// for (int i=1; i<=n; i++){
// parent[i] = i;
// }
//}
//
//int Find(int x){
// return (x == parent[x])? x : parent[x] = Find(parent[x]);
//}
//
//void Union(int u, int v){
// int x = Find(u);
// int y = Find(v);
// if (x!=y){
// parent[y] = x;
// }
//}
int DFS(int u, int prev){
int t = 0;
bool multie = 0;
num[u] = low[u] = ++timedfs;
for (auto in:adj[u]){
int v = in.fi.fi;
int id = in.fi.se;
int dr = in.se;
if (!multie && v == prev){
multie = 1;
continue;
}
if (!num[v]){
int tmp = DFS(v,u);
t+=tmp;
// cout << u << " " << v << " " << tmp << endl;
low[u] = min(low[u],low[v]);
if (num[v] == low[v]){
// Union(u,v);
IsBridge[id] = true;
if (tmp!= 0){
dir[id] = dr;
if (tmp<0) dir[id] = -dir[id];
}
// adj2[Find(u)].push_back(Find(v));
// adj2[Find(v)].push_back(Find(u));
}
}
else low[u] = min(low[u],num[v]);
}
t+=pre[u];
return t;
}
/*Solution*/
void solve(){
cin >> n >> m;
// cout << n << "_" << m << endl;
// Init();
for (int i=1; i<=m; i++){
int u,v; cin >> u >> v;
// if (i==12) cout << u << "-" << v << endl;
adj[u].push_back({{v,i},1});
adj[v].push_back({{u,i},-1});
}
cin >> q;
for (int i=1; i<=q; i++){
int u,v; cin >> u >> v;
pre[u]--;
pre[v]++;
}
for (int i=1; i<=n; i++){
if (!num[i]) DFS(i,0);
}
for (int i=1; i<=m; i++){
// if (i==7){
// if (IsBridge[i]) cout << "rawr" << endl;
// else cout << "ewww" << endl;
// }
if (dir[i] == 0) cout << "B";
else if (dir[i] == 1) cout << "R";
else cout << "L";
// cout << luutmp[i] << "-";
}
// cout << endl;
// for (int i=1; i<=n; i++){
// cout << low[i] << " ";
// }
// cout << endl;
}
/*Driver Code*/
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
TestCases(0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
2 ms |
9076 KB |
Output is correct |
10 |
Correct |
1 ms |
9052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
2 ms |
9076 KB |
Output is correct |
10 |
Correct |
1 ms |
9052 KB |
Output is correct |
11 |
Correct |
29 ms |
15432 KB |
Output is correct |
12 |
Correct |
29 ms |
16412 KB |
Output is correct |
13 |
Correct |
30 ms |
17248 KB |
Output is correct |
14 |
Correct |
34 ms |
17240 KB |
Output is correct |
15 |
Correct |
31 ms |
16976 KB |
Output is correct |
16 |
Correct |
28 ms |
14428 KB |
Output is correct |
17 |
Correct |
30 ms |
16208 KB |
Output is correct |
18 |
Correct |
27 ms |
14488 KB |
Output is correct |
19 |
Correct |
28 ms |
17748 KB |
Output is correct |
20 |
Correct |
25 ms |
15452 KB |
Output is correct |
21 |
Correct |
25 ms |
15188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
1 ms |
9052 KB |
Output is correct |
3 |
Correct |
2 ms |
9052 KB |
Output is correct |
4 |
Correct |
1 ms |
9052 KB |
Output is correct |
5 |
Correct |
1 ms |
9052 KB |
Output is correct |
6 |
Correct |
1 ms |
9052 KB |
Output is correct |
7 |
Correct |
2 ms |
9052 KB |
Output is correct |
8 |
Correct |
1 ms |
9052 KB |
Output is correct |
9 |
Correct |
2 ms |
9076 KB |
Output is correct |
10 |
Correct |
1 ms |
9052 KB |
Output is correct |
11 |
Correct |
29 ms |
15432 KB |
Output is correct |
12 |
Correct |
29 ms |
16412 KB |
Output is correct |
13 |
Correct |
30 ms |
17248 KB |
Output is correct |
14 |
Correct |
34 ms |
17240 KB |
Output is correct |
15 |
Correct |
31 ms |
16976 KB |
Output is correct |
16 |
Correct |
28 ms |
14428 KB |
Output is correct |
17 |
Correct |
30 ms |
16208 KB |
Output is correct |
18 |
Correct |
27 ms |
14488 KB |
Output is correct |
19 |
Correct |
28 ms |
17748 KB |
Output is correct |
20 |
Correct |
25 ms |
15452 KB |
Output is correct |
21 |
Correct |
25 ms |
15188 KB |
Output is correct |
22 |
Correct |
36 ms |
17492 KB |
Output is correct |
23 |
Correct |
42 ms |
15700 KB |
Output is correct |
24 |
Correct |
47 ms |
15700 KB |
Output is correct |
25 |
Correct |
37 ms |
21072 KB |
Output is correct |
26 |
Correct |
39 ms |
16896 KB |
Output is correct |
27 |
Correct |
40 ms |
15676 KB |
Output is correct |
28 |
Correct |
22 ms |
13404 KB |
Output is correct |
29 |
Correct |
37 ms |
16000 KB |
Output is correct |
30 |
Correct |
38 ms |
16244 KB |
Output is correct |
31 |
Correct |
39 ms |
16468 KB |
Output is correct |
32 |
Correct |
36 ms |
18516 KB |
Output is correct |