#include <bits/stdc++.h>
using namespace std;
#define sz size
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int mxN = 1e5+5;
vector<pii> adj[mxN];
int d[mxN];
int low[mxN];
char res[mxN];
int val[mxN];
void dfs(int c, int depth, int pidx){
d[c] = depth;
low[c] = depth;
for (pii i : adj[c]){
if (i.s == -1*pidx) continue;
if (d[i.f] != -1){ low[c] = min(low[c],low[i.f]); res[abs(i.s)] = 'B'; continue;}
dfs(i.f,depth+1,i.s);
low[c] = min(low[c],low[i.f]);
val[c] += val[i.f];
}
//cout << c << " " << low[c] << " " << d[c] << "\n";
if (pidx == INT_MAX) return;
if (low[c] < d[c] || val[c] == 0) res[abs(pidx)] = 'B';
else if (val[c] < 0){
if (pidx > 0) res[abs(pidx)] = 'R';
else res[abs(pidx)] = 'L';
} else {
if (pidx > 0) res[abs(pidx)] = 'L';
else res[abs(pidx)] = 'R';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
int a,b;
for (int i =0; i < m; i++){
cin >> a >> b;
a -= 1;
b -= 1;
adj[a].pb((pii) {b,i+1});
adj[b].pb((pii) {a,-1*i-1});
}
int p;
cin >> p;
memset(val,0,sizeof(val));
for (int i =0; i < p; i++){
cin >> a >> b;
a -= 1;
b -= 1;
val[a]++;
val[b]--;
}
for (int i = 0; i < n; i++) d[i] = -1;
for (int i = 0; i < n; i++) if (d[i] == -1) dfs(i,0,INT_MAX);
for (int i = 1; i <= m; i++) cout << res[i];
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3084 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3084 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
25 ms |
8528 KB |
Output is correct |
12 |
Correct |
29 ms |
9236 KB |
Output is correct |
13 |
Correct |
31 ms |
10356 KB |
Output is correct |
14 |
Correct |
31 ms |
10840 KB |
Output is correct |
15 |
Correct |
34 ms |
10904 KB |
Output is correct |
16 |
Correct |
26 ms |
9040 KB |
Output is correct |
17 |
Correct |
28 ms |
10580 KB |
Output is correct |
18 |
Correct |
34 ms |
8972 KB |
Output is correct |
19 |
Correct |
28 ms |
11668 KB |
Output is correct |
20 |
Correct |
25 ms |
8792 KB |
Output is correct |
21 |
Correct |
29 ms |
8560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
1 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3084 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
25 ms |
8528 KB |
Output is correct |
12 |
Correct |
29 ms |
9236 KB |
Output is correct |
13 |
Correct |
31 ms |
10356 KB |
Output is correct |
14 |
Correct |
31 ms |
10840 KB |
Output is correct |
15 |
Correct |
34 ms |
10904 KB |
Output is correct |
16 |
Correct |
26 ms |
9040 KB |
Output is correct |
17 |
Correct |
28 ms |
10580 KB |
Output is correct |
18 |
Correct |
34 ms |
8972 KB |
Output is correct |
19 |
Correct |
28 ms |
11668 KB |
Output is correct |
20 |
Correct |
25 ms |
8792 KB |
Output is correct |
21 |
Correct |
29 ms |
8560 KB |
Output is correct |
22 |
Correct |
35 ms |
11604 KB |
Output is correct |
23 |
Correct |
35 ms |
10072 KB |
Output is correct |
24 |
Correct |
41 ms |
9980 KB |
Output is correct |
25 |
Correct |
38 ms |
14672 KB |
Output is correct |
26 |
Correct |
38 ms |
11352 KB |
Output is correct |
27 |
Correct |
40 ms |
10076 KB |
Output is correct |
28 |
Correct |
21 ms |
6492 KB |
Output is correct |
29 |
Correct |
36 ms |
9496 KB |
Output is correct |
30 |
Correct |
44 ms |
9772 KB |
Output is correct |
31 |
Correct |
36 ms |
10068 KB |
Output is correct |
32 |
Correct |
37 ms |
11928 KB |
Output is correct |