#pragma GCC optimize("Ofast, unrool-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pll pair<int, int>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 480;
ll n,m,p,timer=0;
struct ccjv{ll v, prv, nxt;};
vector<pll>adj[N];
vector<ccjv>g[N];
ll cmp[N], low[N], num[N], b[N], pa[N];
pll edge[N];
ll cur = 0;
vector<pll>order;
map<pll,ll>dir;
void pre_dfs(ll u, ll par){
low[u] = num[u] = ++timer;
for(auto x : adj[u]){
ll v = x.F, idx = x.S;
if(idx == par) continue;
if(num[v]) low[u] = min(low[u], num[v]);
else{
pre_dfs(v, idx);
low[u] = min(low[u], low[v]);
if(low[v] == num[v]) {
//cout << "bridge" << ' ' << u << ' ' << v << '\n';
b[idx] = 1;
}
}
}
}
void dfs_cmp(ll u, ll par){
cmp[u] = cur;
for(auto x : adj[u]){
ll v = x.F, idx = x.S;
if(idx == par) continue;
if(b[idx]){
if(cmp[v]) g[cmp[u]].pb({cmp[v], u, v}), g[cmp[v]].pb({cmp[u], v, u});
}
else if(!cmp[v]) dfs_cmp(v, idx);
}
}
void dfs(ll u, ll par, ll b){
if(u == b){
for(auto x : order){
dir[{x.F, x.S}] = 1;
dir[{x.S, x.F}] = -1;
}
}
for(auto x : g[u]){
ll v = x.v;
if(v == par) continue;
order.pb({x.prv, x.nxt});
dfs(v, u, b);
order.pop_back();
}
}
void to_thic_cau(){
cin >> n >> m;
for(int i = 1; i <= m;i++){
ll u,v; cin >> u >> v;
edge[i] = {u, v};
adj[u].pb({v, i});
adj[v].pb({u, i});
}
for(int i = 1; i <= n;i++) if(!num[i]) pre_dfs(i, 0);
for(int i = 1; i <= n;i++){
if(!cmp[i]){
++cur;
dfs_cmp(i, 0);
}
}
cin >> p;
for(int i = 1; i <= p;i++){
ll a,b; cin >> a >> b;
dfs(cmp[a], 0, cmp[b]);
order.clear();
}
for(int i = 1; i <= m;i++){
if(!b[i]){
cout << 'B';
}
else{
if(!dir[{edge[i].F, edge[i].S}]) cout << 'B';
else if(dir[{edge[i].F, edge[i].S}] == 1) cout << 'R';
else cout << 'L';
}
}
cout << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
Compilation message
oneway.cpp:1:43: warning: bad option '-f unrool-loops' to pragma 'optimize' [-Wpragmas]
1 | #pragma GCC optimize("Ofast, unrool-loops")
| ^
oneway.cpp:13:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
13 | const ll inf = 1e18;
| ^~~~
oneway.cpp:25:26: warning: bad option '-f unrool-loops' to attribute 'optimize' [-Wattributes]
25 | void pre_dfs(ll u, ll par){
| ^
oneway.cpp:41:26: warning: bad option '-f unrool-loops' to attribute 'optimize' [-Wattributes]
41 | void dfs_cmp(ll u, ll par){
| ^
oneway.cpp:52:28: warning: bad option '-f unrool-loops' to attribute 'optimize' [-Wattributes]
52 | void dfs(ll u, ll par, ll b){
| ^
oneway.cpp:67:18: warning: bad option '-f unrool-loops' to attribute 'optimize' [-Wattributes]
67 | void to_thic_cau(){
| ^
oneway.cpp:101:13: warning: bad option '-f unrool-loops' to attribute 'optimize' [-Wattributes]
101 | signed main(){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
3 ms |
10840 KB |
Output is correct |
3 |
Correct |
3 ms |
11188 KB |
Output is correct |
4 |
Correct |
3 ms |
11240 KB |
Output is correct |
5 |
Correct |
6 ms |
11100 KB |
Output is correct |
6 |
Correct |
3 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
4 ms |
11100 KB |
Output is correct |
9 |
Correct |
3 ms |
11096 KB |
Output is correct |
10 |
Correct |
3 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
3 ms |
10840 KB |
Output is correct |
3 |
Correct |
3 ms |
11188 KB |
Output is correct |
4 |
Correct |
3 ms |
11240 KB |
Output is correct |
5 |
Correct |
6 ms |
11100 KB |
Output is correct |
6 |
Correct |
3 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
4 ms |
11100 KB |
Output is correct |
9 |
Correct |
3 ms |
11096 KB |
Output is correct |
10 |
Correct |
3 ms |
11100 KB |
Output is correct |
11 |
Correct |
26 ms |
18268 KB |
Output is correct |
12 |
Correct |
30 ms |
20012 KB |
Output is correct |
13 |
Correct |
37 ms |
21584 KB |
Output is correct |
14 |
Correct |
64 ms |
23892 KB |
Output is correct |
15 |
Correct |
70 ms |
24680 KB |
Output is correct |
16 |
Correct |
78 ms |
28596 KB |
Output is correct |
17 |
Correct |
890 ms |
36052 KB |
Output is correct |
18 |
Correct |
306 ms |
28752 KB |
Output is correct |
19 |
Correct |
887 ms |
36076 KB |
Output is correct |
20 |
Correct |
30 ms |
18068 KB |
Output is correct |
21 |
Correct |
38 ms |
17948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
3 ms |
10840 KB |
Output is correct |
3 |
Correct |
3 ms |
11188 KB |
Output is correct |
4 |
Correct |
3 ms |
11240 KB |
Output is correct |
5 |
Correct |
6 ms |
11100 KB |
Output is correct |
6 |
Correct |
3 ms |
11100 KB |
Output is correct |
7 |
Correct |
5 ms |
11096 KB |
Output is correct |
8 |
Correct |
4 ms |
11100 KB |
Output is correct |
9 |
Correct |
3 ms |
11096 KB |
Output is correct |
10 |
Correct |
3 ms |
11100 KB |
Output is correct |
11 |
Correct |
26 ms |
18268 KB |
Output is correct |
12 |
Correct |
30 ms |
20012 KB |
Output is correct |
13 |
Correct |
37 ms |
21584 KB |
Output is correct |
14 |
Correct |
64 ms |
23892 KB |
Output is correct |
15 |
Correct |
70 ms |
24680 KB |
Output is correct |
16 |
Correct |
78 ms |
28596 KB |
Output is correct |
17 |
Correct |
890 ms |
36052 KB |
Output is correct |
18 |
Correct |
306 ms |
28752 KB |
Output is correct |
19 |
Correct |
887 ms |
36076 KB |
Output is correct |
20 |
Correct |
30 ms |
18068 KB |
Output is correct |
21 |
Correct |
38 ms |
17948 KB |
Output is correct |
22 |
Execution timed out |
3054 ms |
32356 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |