#include <bits/stdc++.h>
//#define int long long
#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
//int max(int x,int y){return x>=y?x:y;}
//int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=100005;
const int M=100000005;
const int MOD=1000000007;//998244353;
const int INF=2147483647;//1000000000000000;
int n,m,P,cpCnt,tst;
vector<pi> e[N];
stack<int> st;
int dp[N],dfn[N],low[N],vis[N],comp[N];
struct Edge{
int u,v;
char c;
} ans[N];
void tarjan(int v,int pre){
low[v]=dfn[v]=++tst;
st.push(v);
for (auto &[to,i]:e[v]){
if (i!=pre) continue;
if (dfn[to]) low[v]=min(low[v],dfn[to]);
else{
tarjan(to,i);
low[v]=min(low[v],low[to]);
}
}
if (dfn[v]<=low[v]){
++cpCnt;
while (1){
assert(st.size()!=0);
int u=st.top();st.pop();
comp[u]=cpCnt;
if (v==u) break;
}
}
}
void build_tree(){
for (int i=1;i<=n;i++)
e[i].clear();
for (int i=1;i<=m;i++){
ans[i].u=comp[ans[i].u];
ans[i].v=comp[ans[i].v];
if (ans[i].u!=ans[i].v){
e[ans[i].u].pb({ans[i].v,i});
e[ans[i].v].pb({ans[i].u,i});
}
}
n=cpCnt;
}
void dfs(int v,int pre){
vis[v]=1;
for (auto [u,i]:e[v]) if (u!=pre){
dfs(u,i);
if (dp[u]==0) ans[i].c='B';
else if (dp[u]<0)
ans[i].c= v==ans[i].u?'R':'L';
else if (dp[u]>0)
ans[i].c= v==ans[i].u?'L':'R';
dp[v]+=dp[u];
}
// cout <<"*";
}
inline void sol(){
cin >>n>>m;
for (int i=1,a,b;i<=m;i++){
cin >>a>>b;ans[i]={a,b,'B'};
e[a].pb({b,i});
e[b].pb({a,i});
}
for (int i=1;i<=n;i++)
if (!vis[i])
tarjan(i,0);
build_tree();
cin >>P;
for (int a,b;P--;)
cin >>a>>b,dp[comp[a]]++,dp[comp[b]]--;
memset(vis,0,sizeof(vis));
for (int i=1;i<=n;i++)
if (!vis[i])
dfs(i,0);
for (int i=1;i<=m;i++)
cout <<ans[i].c;
}
signed main(){
Nanase_Kurumi_aka_menhera_chan_is_mine
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |