#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 10;
vector<pii> T[N];
int tin[N];
int tout[N];
int low[N];
int u[N], v[N];
bool bridge[N];
int ti;
bool use[N];
void dfs(int u, int pp){
ti++;
tin[u]=ti;
low[u]=tin[u];
for(auto x : T[u]){
if(tin[x.fi] == 0){
dfs(x.fi,x.se);
use[x.se]=true;
low[u]=min(low[u],low[x.fi]);
if(tin[u] < low[x.fi]){
bridge[x.se]=true;
}
}
else if(x.se != pp){
low[u]=min(low[u],tin[x.fi]);
}
}
tout[u]=ti;
}
char sol[N];
void setd(int xi, int yi, int id){
if(xi == u[id]){
sol[id]='R';
}
else{
sol[id]='L';
}
}
int in_low[N], in_high[N];
int out_low[N], out_high[N];
void dfs2(int u, int pi){
for(auto x : T[u]){
if(use[x.se] && x.se != pi){
dfs2(x.fi,x.se);
in_low[u]=min(in_low[u],in_low[x.fi]);
out_low[u]=min(out_low[u],out_low[x.fi]);
in_high[u]=max(in_high[u],in_high[x.fi]);
out_high[u]=max(out_high[u],out_high[x.fi]);
if(bridge[x.se]){
if(in_low[x.fi] < tin[x.fi] || in_high[x.fi] > tout[x.fi]){
setd(u,x.fi,x.se);
}
else if(out_low[x.fi] < tin[x.fi] || out_high[x.fi] > tout[x.fi]){
setd(x.fi,u,x.se);
}
}
}
}
}
int main(){
fastIO;
int n, m, p;
cin >> n >> m;
for(int i = 1; i <= m; i ++ ){
cin >> u[i] >> v[i];
T[u[i]].push_back(mp(v[i],i));
T[v[i]].push_back(mp(u[i],i));
}
vector<int> ord;
for(int i = 1; i <= n; i ++ ){
if(tin[i] == 0){
ord.push_back(i);
dfs(i,-1);
}
}
for(int i = 1; i <= m; i ++ ){
sol[i]='B';
}
for(int i = 1; i <= n; i ++ ){
in_low[i]=n+1;
out_low[i]=n+1;
}
cin >> p;
int xi, yi;
for(int i = 1; i <= p ; i ++ ){
cin >> xi >> yi;
in_low[yi]=min(in_low[yi],tin[xi]);
out_low[xi]=min(out_low[xi],tin[yi]);
in_high[yi]=max(in_high[yi],tin[xi]);
out_high[xi]=max(out_high[xi],tin[yi]);
}
for(auto x : ord )
dfs2(x,-1);
for(int i = 1; i <= m ; i ++ ){
cout << sol[i];
}
cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2796 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2796 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2796 KB |
Output is correct |
11 |
Correct |
45 ms |
8812 KB |
Output is correct |
12 |
Correct |
53 ms |
9996 KB |
Output is correct |
13 |
Correct |
63 ms |
11244 KB |
Output is correct |
14 |
Correct |
74 ms |
12396 KB |
Output is correct |
15 |
Correct |
87 ms |
12672 KB |
Output is correct |
16 |
Correct |
81 ms |
10860 KB |
Output is correct |
17 |
Correct |
68 ms |
12396 KB |
Output is correct |
18 |
Correct |
81 ms |
10820 KB |
Output is correct |
19 |
Correct |
61 ms |
13548 KB |
Output is correct |
20 |
Correct |
53 ms |
9708 KB |
Output is correct |
21 |
Correct |
48 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2796 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2924 KB |
Output is correct |
10 |
Correct |
2 ms |
2796 KB |
Output is correct |
11 |
Correct |
45 ms |
8812 KB |
Output is correct |
12 |
Correct |
53 ms |
9996 KB |
Output is correct |
13 |
Correct |
63 ms |
11244 KB |
Output is correct |
14 |
Correct |
74 ms |
12396 KB |
Output is correct |
15 |
Correct |
87 ms |
12672 KB |
Output is correct |
16 |
Correct |
81 ms |
10860 KB |
Output is correct |
17 |
Correct |
68 ms |
12396 KB |
Output is correct |
18 |
Correct |
81 ms |
10820 KB |
Output is correct |
19 |
Correct |
61 ms |
13548 KB |
Output is correct |
20 |
Correct |
53 ms |
9708 KB |
Output is correct |
21 |
Correct |
48 ms |
9580 KB |
Output is correct |
22 |
Correct |
94 ms |
13292 KB |
Output is correct |
23 |
Correct |
91 ms |
12652 KB |
Output is correct |
24 |
Correct |
102 ms |
12780 KB |
Output is correct |
25 |
Correct |
82 ms |
17244 KB |
Output is correct |
26 |
Correct |
90 ms |
13932 KB |
Output is correct |
27 |
Correct |
88 ms |
12652 KB |
Output is correct |
28 |
Correct |
39 ms |
7020 KB |
Output is correct |
29 |
Correct |
72 ms |
11244 KB |
Output is correct |
30 |
Correct |
75 ms |
11372 KB |
Output is correct |
31 |
Correct |
76 ms |
11628 KB |
Output is correct |
32 |
Correct |
69 ms |
13804 KB |
Output is correct |