#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
vector<pair<int,int>> adj[maxn],tree[maxn];
pair<int,int> edge[maxn];
int n,m,p;
char res[maxn];
int low[maxn],num[maxn],stt[maxn],del[maxn],cc,timedfs;
int a[maxn],b[maxn];
stack<int> st;
void dfs1(int u,int p){
num[u]=low[u]=++timedfs;
st.push(u);
bool skip=false;
for(auto i:adj[u]){
int v=i.first;
if(v==p && !skip){
skip=true;
continue;
}
if(!num[v]){
dfs1(v,u);
low[u]=min(low[u],low[v]);
}
else low[u]=min(low[u],num[v]);
}
if(low[u]==num[u]){
cc++;
int v;
do{
v=st.top();
st.pop();
stt[v]=cc;
del[v]=true;
}
while(v!=u);
}
}
int vis[maxn];
vector<int> dir[maxn];
void dfs2(int u,int idx){
vis[u]=1;
for(auto i:tree[u])if(!vis[i.first]){
dfs2(i.first,i.second);
a[u]+=a[i.first];
b[u]+=b[i.first];
}
if(a[u]==b[u]) res[idx]='B';
else if(a[u]>b[u]){
if(stt[edge[idx].first]==u) res[idx]='R';
else res[idx]='L';
}
else{
if(stt[edge[idx].first]==u) res[idx]='L';
else res[idx]='R';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
edge[i]={u,v};
adj[u].push_back({v,i});
adj[v].push_back({u,i});
}
for(int i=1;i<=n;i++) if(!del[i]) dfs1(i,i);
for(int u=1;u<=n;u++)
for(auto i:adj[u])
if(stt[u]!=stt[i.first]) tree[stt[u]].push_back({stt[i.first],i.second});
cin>>p;
for(int i=1;i<=p;i++){
int u,v;
cin>>u>>v;
if(stt[u]==stt[v]) continue;
a[stt[u]]++;
b[stt[v]]++;
}
for(int i=1;i<=cc;i++) if(!vis[i]) dfs2(i,0);
for(int i=1;i<=m;i++){
if(!res[i]) cout<<'B';
else cout<<res[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12380 KB |
Output is correct |
2 |
Correct |
2 ms |
12380 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12584 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12380 KB |
Output is correct |
2 |
Correct |
2 ms |
12380 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12584 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12680 KB |
Output is correct |
11 |
Correct |
28 ms |
19292 KB |
Output is correct |
12 |
Correct |
28 ms |
20316 KB |
Output is correct |
13 |
Correct |
32 ms |
21336 KB |
Output is correct |
14 |
Correct |
40 ms |
22220 KB |
Output is correct |
15 |
Correct |
37 ms |
22876 KB |
Output is correct |
16 |
Correct |
51 ms |
24916 KB |
Output is correct |
17 |
Correct |
41 ms |
26444 KB |
Output is correct |
18 |
Correct |
42 ms |
24912 KB |
Output is correct |
19 |
Correct |
46 ms |
27900 KB |
Output is correct |
20 |
Correct |
26 ms |
19800 KB |
Output is correct |
21 |
Correct |
25 ms |
19544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12380 KB |
Output is correct |
2 |
Correct |
2 ms |
12380 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
3 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
3 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
2 ms |
12584 KB |
Output is correct |
9 |
Correct |
3 ms |
12632 KB |
Output is correct |
10 |
Correct |
2 ms |
12680 KB |
Output is correct |
11 |
Correct |
28 ms |
19292 KB |
Output is correct |
12 |
Correct |
28 ms |
20316 KB |
Output is correct |
13 |
Correct |
32 ms |
21336 KB |
Output is correct |
14 |
Correct |
40 ms |
22220 KB |
Output is correct |
15 |
Correct |
37 ms |
22876 KB |
Output is correct |
16 |
Correct |
51 ms |
24916 KB |
Output is correct |
17 |
Correct |
41 ms |
26444 KB |
Output is correct |
18 |
Correct |
42 ms |
24912 KB |
Output is correct |
19 |
Correct |
46 ms |
27900 KB |
Output is correct |
20 |
Correct |
26 ms |
19800 KB |
Output is correct |
21 |
Correct |
25 ms |
19544 KB |
Output is correct |
22 |
Correct |
56 ms |
26304 KB |
Output is correct |
23 |
Correct |
62 ms |
24916 KB |
Output is correct |
24 |
Correct |
66 ms |
24768 KB |
Output is correct |
25 |
Correct |
62 ms |
30036 KB |
Output is correct |
26 |
Correct |
59 ms |
26192 KB |
Output is correct |
27 |
Correct |
52 ms |
24912 KB |
Output is correct |
28 |
Correct |
21 ms |
16732 KB |
Output is correct |
29 |
Correct |
39 ms |
19304 KB |
Output is correct |
30 |
Correct |
44 ms |
19456 KB |
Output is correct |
31 |
Correct |
37 ms |
19924 KB |
Output is correct |
32 |
Correct |
44 ms |
22868 KB |
Output is correct |