#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, p, h[N], mnh[N], st[N], ft[N], tme;
bool vis[N];
vector<pair<int, int>> g[N], edges, important;
string s;
bool in_sub(int u, int v){
return (st[v] <= st[u] && st[u] < ft[v]);
}
void dfs(int v, int prev = -1){
vis[v] = 1;
mnh[v] = h[v];
st[v] = tme;
tme++;
// cout << "Running dfs on " << v << endl;
for (auto [id, u] : g[v]){
if (id == prev) continue;
if (!vis[u]){
h[u] = h[v] + 1;
dfs(u, id);
mnh[v] = min(mnh[v], mnh[u]);
if (mnh[u] > h[v]){ // (v, u) is a bridge
// cout << u << " " << v << endl;
// cout << v << " -- " << u << " is a bridge." << endl;
for (auto [x, y] : important){
bool A = in_sub(x, u);
bool B = in_sub(y, u);
// cout << x << " " << y << " " << u << " " << A << " " << B << endl;
if (A and !B){
// u to v
if (edges[id].first == u)
s[id] = 'R';
else
s[id] = 'L';
}
if (!A and B){
// v to u
if (edges[id].first == v)
s[id] = 'R';
else
s[id] = 'L';
}
}
}
else
s[id] = 'B';
}
else
mnh[v] = min(mnh[v], h[u]);
}
ft[v] = tme;
}
int main(){
cin >> n >> m;
for (int i=0; i<m; i++){
int u, v;
cin >> u >> v;
s += 'B';
edges.push_back({u, v});
if (u == v)
continue;
g[u].push_back({i, v});
g[v].push_back({i, u});
}
for (int i=1; i<=n; i++)
h[i] = mnh[i] = n + 100;
cin >> p;
for (int i=0; i<p; i++){
int u, v;
cin >> u >> v;
if (u == v) continue;
important.push_back({u, v});
}
for (int v = 1; v <= n; v++)
if (!vis[v])
dfs(v);
cout << s << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
52 ms |
8144 KB |
Output is correct |
12 |
Correct |
57 ms |
9232 KB |
Output is correct |
13 |
Correct |
59 ms |
10404 KB |
Output is correct |
14 |
Correct |
66 ms |
11208 KB |
Output is correct |
15 |
Correct |
67 ms |
11316 KB |
Output is correct |
16 |
Correct |
59 ms |
9096 KB |
Output is correct |
17 |
Correct |
85 ms |
10924 KB |
Output is correct |
18 |
Correct |
71 ms |
9064 KB |
Output is correct |
19 |
Correct |
74 ms |
12228 KB |
Output is correct |
20 |
Correct |
57 ms |
8900 KB |
Output is correct |
21 |
Correct |
56 ms |
8384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
52 ms |
8144 KB |
Output is correct |
12 |
Correct |
57 ms |
9232 KB |
Output is correct |
13 |
Correct |
59 ms |
10404 KB |
Output is correct |
14 |
Correct |
66 ms |
11208 KB |
Output is correct |
15 |
Correct |
67 ms |
11316 KB |
Output is correct |
16 |
Correct |
59 ms |
9096 KB |
Output is correct |
17 |
Correct |
85 ms |
10924 KB |
Output is correct |
18 |
Correct |
71 ms |
9064 KB |
Output is correct |
19 |
Correct |
74 ms |
12228 KB |
Output is correct |
20 |
Correct |
57 ms |
8900 KB |
Output is correct |
21 |
Correct |
56 ms |
8384 KB |
Output is correct |
22 |
Execution timed out |
3059 ms |
12888 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |