#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5;
vii adj(MAXN);
vector<set<int>>tadj(MAXN);
vector<int>id(MAXN);
vector<int>tin(MAXN),low(MAXN);
stack<int>stk;
int timer = 0,scc = 0;
void tarjan(int v,int p){
tin[v] = low[v] = ++timer;
stk.push(v);
bool pp = 0;
for(int x:adj[v]){
if(x != p || pp){
if(!tin[x]){
tarjan(x,v);
low[v] = min(low[v],low[x]);
}else{
low[v] = min(low[v],tin[x]);
}
}else pp = 1;
}
if(low[v] == tin[v]){
while(stk.top() != v){
id[stk.top()] = scc;
stk.pop();
}
stk.pop();
id[v] = scc;
scc++;
}
}
vector<int>dep(MAXN),val(MAXN);
void dfs(int v,int u){
for(int x:tadj[v]){
if(x != u){
dep[x] = dep[v]+1;
dfs(x,v);
val[v]+=val[x];
}
}
}
int main()
{
owo
int n,m;
cin>>n>>m;
vector<pii>e;
for(int i=0;i<m;i++){
int v,u;
cin>>v>>u;
adj[v].pb(u);
adj[u].pb(v);
e.pb({v,u});
}
for(int i=1;i<=n;i++){
if(!tin[i])tarjan(i,-1);
}
//for(int i=1;i<=n;i++)cout<<id[i]<<" ";
//cout<<'\n';
for(pii x:e){
if(id[x.fi] == id[x.se])continue;
tadj[id[x.fi]].insert(id[x.se]);
tadj[id[x.se]].insert(id[x.fi]);
}
int p;cin>>p;
while(p--){
int a,b;
cin>>a>>b;
val[id[a]]--;
val[id[b]]++;
}
for(int i=1;i<=n;i++){
if(!dep[id[i]]){
dep[id[i]] = 1;
dfs(id[i],-1);
}
}
for(pii x:e){
int a = id[x.fi];
int b = id[x.se];
if(a == b){cout<<"B";continue;}
if(dep[a] > dep[b]){
if(val[a] <0)cout<<"R";
else if(!val[a])cout<<"B";
else cout<<"L";
}
else{
if(val[b] <0)cout<<"L";
else if(!val[b])cout<<"B";
else cout<<"R";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18252 KB |
Output is correct |
2 |
Correct |
11 ms |
18252 KB |
Output is correct |
3 |
Correct |
12 ms |
18380 KB |
Output is correct |
4 |
Correct |
12 ms |
18380 KB |
Output is correct |
5 |
Correct |
12 ms |
18380 KB |
Output is correct |
6 |
Correct |
11 ms |
18292 KB |
Output is correct |
7 |
Correct |
12 ms |
18384 KB |
Output is correct |
8 |
Correct |
13 ms |
18380 KB |
Output is correct |
9 |
Correct |
12 ms |
18316 KB |
Output is correct |
10 |
Correct |
13 ms |
18380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18252 KB |
Output is correct |
2 |
Correct |
11 ms |
18252 KB |
Output is correct |
3 |
Correct |
12 ms |
18380 KB |
Output is correct |
4 |
Correct |
12 ms |
18380 KB |
Output is correct |
5 |
Correct |
12 ms |
18380 KB |
Output is correct |
6 |
Correct |
11 ms |
18292 KB |
Output is correct |
7 |
Correct |
12 ms |
18384 KB |
Output is correct |
8 |
Correct |
13 ms |
18380 KB |
Output is correct |
9 |
Correct |
12 ms |
18316 KB |
Output is correct |
10 |
Correct |
13 ms |
18380 KB |
Output is correct |
11 |
Correct |
55 ms |
21688 KB |
Output is correct |
12 |
Correct |
53 ms |
22544 KB |
Output is correct |
13 |
Correct |
59 ms |
23460 KB |
Output is correct |
14 |
Correct |
73 ms |
25400 KB |
Output is correct |
15 |
Correct |
87 ms |
26244 KB |
Output is correct |
16 |
Correct |
142 ms |
31820 KB |
Output is correct |
17 |
Correct |
90 ms |
33080 KB |
Output is correct |
18 |
Correct |
127 ms |
31804 KB |
Output is correct |
19 |
Correct |
84 ms |
33992 KB |
Output is correct |
20 |
Correct |
56 ms |
22376 KB |
Output is correct |
21 |
Correct |
52 ms |
22000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
18252 KB |
Output is correct |
2 |
Correct |
11 ms |
18252 KB |
Output is correct |
3 |
Correct |
12 ms |
18380 KB |
Output is correct |
4 |
Correct |
12 ms |
18380 KB |
Output is correct |
5 |
Correct |
12 ms |
18380 KB |
Output is correct |
6 |
Correct |
11 ms |
18292 KB |
Output is correct |
7 |
Correct |
12 ms |
18384 KB |
Output is correct |
8 |
Correct |
13 ms |
18380 KB |
Output is correct |
9 |
Correct |
12 ms |
18316 KB |
Output is correct |
10 |
Correct |
13 ms |
18380 KB |
Output is correct |
11 |
Correct |
55 ms |
21688 KB |
Output is correct |
12 |
Correct |
53 ms |
22544 KB |
Output is correct |
13 |
Correct |
59 ms |
23460 KB |
Output is correct |
14 |
Correct |
73 ms |
25400 KB |
Output is correct |
15 |
Correct |
87 ms |
26244 KB |
Output is correct |
16 |
Correct |
142 ms |
31820 KB |
Output is correct |
17 |
Correct |
90 ms |
33080 KB |
Output is correct |
18 |
Correct |
127 ms |
31804 KB |
Output is correct |
19 |
Correct |
84 ms |
33992 KB |
Output is correct |
20 |
Correct |
56 ms |
22376 KB |
Output is correct |
21 |
Correct |
52 ms |
22000 KB |
Output is correct |
22 |
Correct |
110 ms |
33936 KB |
Output is correct |
23 |
Correct |
133 ms |
34160 KB |
Output is correct |
24 |
Correct |
162 ms |
34056 KB |
Output is correct |
25 |
Correct |
105 ms |
37816 KB |
Output is correct |
26 |
Correct |
109 ms |
35032 KB |
Output is correct |
27 |
Correct |
117 ms |
34212 KB |
Output is correct |
28 |
Correct |
47 ms |
21432 KB |
Output is correct |
29 |
Correct |
88 ms |
24200 KB |
Output is correct |
30 |
Correct |
73 ms |
24304 KB |
Output is correct |
31 |
Correct |
76 ms |
24556 KB |
Output is correct |
32 |
Correct |
80 ms |
28728 KB |
Output is correct |