#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 5;
const ll oo = 1e18 + 5;
const int MAXN = 1e5 + 5;
const int LOG = 16;
#define int ll
int n, m, TimerDFS, low[MAXN], num[MAXN], scc_quanity, scc_id[MAXN], par[MAXN][LOG + 1];
int high[MAXN], f[MAXN];
pair<int, int> edges[MAXN];
vector<pair<int, int>> adj[MAXN];
vector<int> g[MAXN];
bool del[MAXN];
bool vis[MAXN];
stack<int> st;
void DFS_tarjan(int u, int pid) {
++TimerDFS;
st.push(u);
// cout << u << '\n';
num[u] = low[u] = TimerDFS;
for (int i = 0; i < int(adj[u].size()); ++i) {
int v = adj[u][i].first, nid = adj[u][i].second;
if (pid != nid && del[v] == false){
if (num[v] == 0) {
DFS_tarjan(v, nid);
low[u] = min(low[u], low[v]);
} else low[u] = min(low[u], num[v]);
}
}
if (low[u] == num[u]) {
int v;
++scc_quanity;
do {
v = st.top();
del[v] = true;
st.pop();
scc_id[v] = scc_quanity;
} while (v != u);
}
}
//void DFS_high(int u, int p) {
// for (int i = 0; i < int(g[u].size()); ++i) {
// int v = g[u][i];
// if (v != p) {
// high[v] = high[u] + 1;
// par[v][0] = u;
// DFS_high(v, u);
// }
// }
//}
//void prepare_LCA() {
// high[0] = -1;
// DFS_high(1, -1);
// for (int j = 1; j <= LOG; ++j) {
// for (int i = 1; i <= n; ++i) {
// par[i][j] = par[par[i][j - 1]][j - 1];
// }
// }
//}
//int LCA(int u, int v) {
// if (high[u] < high[v]) return LCA(v, u);
//
// int k = high[u] - high[v];
//
// for (int i = 0; i <= LOG; ++i) {
// if ((k >> i) & 1) {
// u = par[u][i];
// }
// }
//
// if (u == v) return u;
//
// for (int i = LOG; i >= 0; --i) {
// if (par[u][i] != par[v][i]) {
// u = par[u][i];
// v = par[v][i];
// }
// }
// return par[u][0];
//}
void DFS_solve(int u, int p) {
vis[u] = true;
for (int i = 0; i < int(g[u].size()); ++i) {
int v = g[u][i];
if (v != p) {
high[v] = high[u] + 1;
if (!vis[v])
DFS_solve(v, u);
f[u] += f[v];
}
}
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
adj[u].push_back({v, i});
adj[v].push_back({u, i});
edges[i] = {u, v};
}
for (int i = 1; i <= n; ++i)
if (num[i] == 0) DFS_tarjan(i, -1);
// cout << TimerDFS << '\n';
// cout << scc_quanity << '\n';
// for (int i = 1; i <= n; ++i) {
// cout << scc_id[i] << ' ';
// }
// cout << '\n';
for (int i = 1; i <= m; ++i) {
int u = scc_id[edges[i].first], v = scc_id[edges[i].second];
// vi la vo huong nen ko co canh trung
if (u != v) {
g[u].push_back(v);
g[v].push_back(u);
}
}
// for (int i = 1; i <= scc)
// prepare_LCA();
int q; cin >> q;
while (q--) {
int u, v; cin >> u >> v;
u = scc_id[u];
v = scc_id[v];
// int uv = LCA(u, v);
++f[u];
--f[v];
// cout << u << ' ' << v << '\n';
// f[uv] -= 3;
}
high[0] = -1;
for (int i = 1; i <= scc_quanity; ++i)
if (!vis[i])
DFS_solve(i, -1);
for (int i = 1; i <= m; ++i) {
int u = scc_id[edges[i].first], v = scc_id[edges[i].second];
// cout << u << ' ' << v << ' ' << high[u] << ' ' << high[v] << ' ' << f[u] << ' ' << f[v];
if (u == v) {
cout << "B";
} else {
if (high[u] > high[v]) {
if (f[u] == 0) cout << "B";
else
if (f[u] >= 1) cout << "R";
else cout << "L";
} else if (f[v] == 0) cout << "B";
else if (f[v] >= 1) cout << "L";
else cout << "R";
}
// cout << '\n';
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
// freopen("nhap.inp", "r", stdin);
// freopen("khon.out", "w", stdout);
// int T = 1; cin >> T; while(T--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
4 ms |
5180 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
4 ms |
5180 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
11 |
Correct |
27 ms |
14540 KB |
Output is correct |
12 |
Correct |
33 ms |
15704 KB |
Output is correct |
13 |
Correct |
37 ms |
16976 KB |
Output is correct |
14 |
Correct |
41 ms |
18512 KB |
Output is correct |
15 |
Correct |
56 ms |
18988 KB |
Output is correct |
16 |
Correct |
49 ms |
20816 KB |
Output is correct |
17 |
Correct |
50 ms |
22384 KB |
Output is correct |
18 |
Correct |
64 ms |
20764 KB |
Output is correct |
19 |
Correct |
57 ms |
23296 KB |
Output is correct |
20 |
Correct |
36 ms |
15444 KB |
Output is correct |
21 |
Correct |
35 ms |
15148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
2 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
4 ms |
5180 KB |
Output is correct |
10 |
Correct |
3 ms |
5208 KB |
Output is correct |
11 |
Correct |
27 ms |
14540 KB |
Output is correct |
12 |
Correct |
33 ms |
15704 KB |
Output is correct |
13 |
Correct |
37 ms |
16976 KB |
Output is correct |
14 |
Correct |
41 ms |
18512 KB |
Output is correct |
15 |
Correct |
56 ms |
18988 KB |
Output is correct |
16 |
Correct |
49 ms |
20816 KB |
Output is correct |
17 |
Correct |
50 ms |
22384 KB |
Output is correct |
18 |
Correct |
64 ms |
20764 KB |
Output is correct |
19 |
Correct |
57 ms |
23296 KB |
Output is correct |
20 |
Correct |
36 ms |
15444 KB |
Output is correct |
21 |
Correct |
35 ms |
15148 KB |
Output is correct |
22 |
Correct |
62 ms |
23376 KB |
Output is correct |
23 |
Correct |
70 ms |
21884 KB |
Output is correct |
24 |
Correct |
80 ms |
21884 KB |
Output is correct |
25 |
Correct |
59 ms |
26452 KB |
Output is correct |
26 |
Correct |
66 ms |
22924 KB |
Output is correct |
27 |
Correct |
72 ms |
21836 KB |
Output is correct |
28 |
Correct |
22 ms |
12092 KB |
Output is correct |
29 |
Correct |
46 ms |
16136 KB |
Output is correct |
30 |
Correct |
59 ms |
16268 KB |
Output is correct |
31 |
Correct |
45 ms |
16748 KB |
Output is correct |
32 |
Correct |
56 ms |
19656 KB |
Output is correct |