#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<pair<int, int>, pair<int, int>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
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 |
3448 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3600 KB |
Output is correct |
4 |
Correct |
3 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3540 KB |
Output is correct |
6 |
Correct |
2 ms |
3584 KB |
Output is correct |
7 |
Correct |
3 ms |
3584 KB |
Output is correct |
8 |
Correct |
2 ms |
3584 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3448 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3600 KB |
Output is correct |
4 |
Correct |
3 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3540 KB |
Output is correct |
6 |
Correct |
2 ms |
3584 KB |
Output is correct |
7 |
Correct |
3 ms |
3584 KB |
Output is correct |
8 |
Correct |
2 ms |
3584 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3452 KB |
Output is correct |
11 |
Correct |
40 ms |
11172 KB |
Output is correct |
12 |
Correct |
45 ms |
12408 KB |
Output is correct |
13 |
Correct |
69 ms |
14212 KB |
Output is correct |
14 |
Correct |
73 ms |
15624 KB |
Output is correct |
15 |
Correct |
60 ms |
15828 KB |
Output is correct |
16 |
Correct |
69 ms |
13896 KB |
Output is correct |
17 |
Correct |
64 ms |
15468 KB |
Output is correct |
18 |
Correct |
85 ms |
13904 KB |
Output is correct |
19 |
Correct |
54 ms |
16624 KB |
Output is correct |
20 |
Correct |
45 ms |
11852 KB |
Output is correct |
21 |
Correct |
38 ms |
12432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3448 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3600 KB |
Output is correct |
4 |
Correct |
3 ms |
3540 KB |
Output is correct |
5 |
Correct |
2 ms |
3540 KB |
Output is correct |
6 |
Correct |
2 ms |
3584 KB |
Output is correct |
7 |
Correct |
3 ms |
3584 KB |
Output is correct |
8 |
Correct |
2 ms |
3584 KB |
Output is correct |
9 |
Correct |
2 ms |
3456 KB |
Output is correct |
10 |
Correct |
2 ms |
3452 KB |
Output is correct |
11 |
Correct |
40 ms |
11172 KB |
Output is correct |
12 |
Correct |
45 ms |
12408 KB |
Output is correct |
13 |
Correct |
69 ms |
14212 KB |
Output is correct |
14 |
Correct |
73 ms |
15624 KB |
Output is correct |
15 |
Correct |
60 ms |
15828 KB |
Output is correct |
16 |
Correct |
69 ms |
13896 KB |
Output is correct |
17 |
Correct |
64 ms |
15468 KB |
Output is correct |
18 |
Correct |
85 ms |
13904 KB |
Output is correct |
19 |
Correct |
54 ms |
16624 KB |
Output is correct |
20 |
Correct |
45 ms |
11852 KB |
Output is correct |
21 |
Correct |
38 ms |
12432 KB |
Output is correct |
22 |
Correct |
97 ms |
16640 KB |
Output is correct |
23 |
Correct |
78 ms |
15104 KB |
Output is correct |
24 |
Correct |
95 ms |
15132 KB |
Output is correct |
25 |
Correct |
80 ms |
19700 KB |
Output is correct |
26 |
Correct |
78 ms |
16288 KB |
Output is correct |
27 |
Correct |
77 ms |
15288 KB |
Output is correct |
28 |
Correct |
30 ms |
9104 KB |
Output is correct |
29 |
Correct |
63 ms |
12692 KB |
Output is correct |
30 |
Correct |
75 ms |
13216 KB |
Output is correct |
31 |
Correct |
71 ms |
12976 KB |
Output is correct |
32 |
Correct |
59 ms |
15968 KB |
Output is correct |