#include <bits/stdc++.h>
using namespace std;
int N, M, Q, X[100005], Y[100005], P[100005];
int timer, E[100005], tin[100005], low[100005];
int S[100005], dep[100005];
bool isBridge[100005];
vector<int> adj[100005];
int findSet(int v) {
if(P[v] == v) return v;
return P[v] = findSet(P[v]);
}
void unionSet(int u, int v) {
u = findSet(u), v = findSet(v);
if(u == v) return;
P[u] = v;
}
void dfs(int v, int p) {
tin[v] = low[v] = timer++;
for(auto e : adj[v]) {
int u = v ^ E[e];
if(tin[u] != -1 && e != p) low[v] = min(low[v], tin[u]);
else if(tin[u] == -1) {
dfs(u, e);
low[v] = min(low[v], low[u]);
if(low[u] > tin[v]) isBridge[e] = 1;
}
}
}
void solve(int v, int p) {
for(auto e : adj[v]) {
int u = v ^ E[e];
if(u == p) continue;
dep[u] = dep[v] + 1;
solve(u, v); S[v] += S[u];
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M;
for(int l = 1; l <= N; l++) P[l] = l;
for(int l = 1; l <= M; l++) {
cin >> X[l] >> Y[l];
E[l] = X[l] ^ Y[l];
adj[X[l]].push_back(l);
adj[Y[l]].push_back(l);
}
memset(tin, -1, sizeof tin);
for(int l = 1; l <= N; l++)
if(tin[l] == -1) dfs(l, -1);
for(int l = 1; l <= M; l++) {
if(!isBridge[l]) unionSet(X[l], Y[l]);
}
for(int l = 1; l <= N; l++) adj[l].clear();
for(int l = 1; l <= M; l++) {
if(!isBridge[l]) continue;
X[l] = findSet(X[l]);
Y[l] = findSet(Y[l]);
E[l] = X[l] ^ Y[l];
adj[X[l]].push_back(l);
adj[Y[l]].push_back(l);
}
cin >> Q;
while(Q--) {
int U, V; cin >> U >> V;
U = findSet(U), V = findSet(V);
S[U]++, S[V]--;
}
for(int l = 1; l <= N; l++) {
if(P[l] == l && !dep[l]) {
dep[l] = 1; solve(l, l);
}
}
for(int l = 1; l <= M; l++) {
if(!isBridge[l]) { cout << 'B'; continue; }
int U = X[l], V = Y[l];
if(dep[U] < dep[V]) swap(U, V);
if(S[U]) cout << (((S[U] > 0) == (U == X[l])) ? 'R' : 'L');
else cout << 'B';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3044 KB |
Output is correct |
2 |
Correct |
2 ms |
3068 KB |
Output is correct |
3 |
Correct |
2 ms |
3064 KB |
Output is correct |
4 |
Correct |
2 ms |
3068 KB |
Output is correct |
5 |
Correct |
2 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3072 KB |
Output is correct |
7 |
Correct |
2 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3064 KB |
Output is correct |
10 |
Correct |
3 ms |
3064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3044 KB |
Output is correct |
2 |
Correct |
2 ms |
3068 KB |
Output is correct |
3 |
Correct |
2 ms |
3064 KB |
Output is correct |
4 |
Correct |
2 ms |
3068 KB |
Output is correct |
5 |
Correct |
2 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3072 KB |
Output is correct |
7 |
Correct |
2 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3064 KB |
Output is correct |
10 |
Correct |
3 ms |
3064 KB |
Output is correct |
11 |
Correct |
40 ms |
8556 KB |
Output is correct |
12 |
Correct |
42 ms |
9736 KB |
Output is correct |
13 |
Correct |
35 ms |
11192 KB |
Output is correct |
14 |
Correct |
43 ms |
12176 KB |
Output is correct |
15 |
Correct |
45 ms |
12404 KB |
Output is correct |
16 |
Correct |
54 ms |
10380 KB |
Output is correct |
17 |
Correct |
48 ms |
12288 KB |
Output is correct |
18 |
Correct |
52 ms |
10300 KB |
Output is correct |
19 |
Correct |
57 ms |
13588 KB |
Output is correct |
20 |
Correct |
46 ms |
9364 KB |
Output is correct |
21 |
Correct |
38 ms |
9380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3044 KB |
Output is correct |
2 |
Correct |
2 ms |
3068 KB |
Output is correct |
3 |
Correct |
2 ms |
3064 KB |
Output is correct |
4 |
Correct |
2 ms |
3068 KB |
Output is correct |
5 |
Correct |
2 ms |
3200 KB |
Output is correct |
6 |
Correct |
3 ms |
3072 KB |
Output is correct |
7 |
Correct |
2 ms |
3156 KB |
Output is correct |
8 |
Correct |
2 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3064 KB |
Output is correct |
10 |
Correct |
3 ms |
3064 KB |
Output is correct |
11 |
Correct |
40 ms |
8556 KB |
Output is correct |
12 |
Correct |
42 ms |
9736 KB |
Output is correct |
13 |
Correct |
35 ms |
11192 KB |
Output is correct |
14 |
Correct |
43 ms |
12176 KB |
Output is correct |
15 |
Correct |
45 ms |
12404 KB |
Output is correct |
16 |
Correct |
54 ms |
10380 KB |
Output is correct |
17 |
Correct |
48 ms |
12288 KB |
Output is correct |
18 |
Correct |
52 ms |
10300 KB |
Output is correct |
19 |
Correct |
57 ms |
13588 KB |
Output is correct |
20 |
Correct |
46 ms |
9364 KB |
Output is correct |
21 |
Correct |
38 ms |
9380 KB |
Output is correct |
22 |
Correct |
55 ms |
13476 KB |
Output is correct |
23 |
Correct |
56 ms |
11436 KB |
Output is correct |
24 |
Correct |
83 ms |
11556 KB |
Output is correct |
25 |
Correct |
69 ms |
17036 KB |
Output is correct |
26 |
Correct |
57 ms |
12984 KB |
Output is correct |
27 |
Correct |
57 ms |
11652 KB |
Output is correct |
28 |
Correct |
23 ms |
6604 KB |
Output is correct |
29 |
Correct |
46 ms |
9968 KB |
Output is correct |
30 |
Correct |
47 ms |
10440 KB |
Output is correct |
31 |
Correct |
59 ms |
10528 KB |
Output is correct |
32 |
Correct |
61 ms |
13388 KB |
Output is correct |