#include<bits/stdc++.h>
using namespace std ;
//1 = L
//2 = B
//3 = R
const int MX = 1e5 + 5 , LG = 25 ;
int bridge[MX] , up[MX][LG] , vis[MX] , ans[MX] , low[MX] , tin[MX] , tout[MX] , timer = 0 , sub[MX][2] ;
vector<pair<int,int> > adj[MX] , edges ;
void dfs(int s , int p , int idx_par)
{
if(vis[s]) return ;
up[s][0] = p , vis[s] = 1 , tin[s] = ++timer , low[s] = tin[s] ;
for(int i = 1 ; i < LG ; ++i)
{
up[s][i] = up[up[s][i-1]][i-1] ;
}
for(pair<int,int> t : adj[s])
{
if(t.second==idx_par) continue ;
if(vis[t.first]) low[s] = min(low[s],tin[t.first]) ;
else
{
dfs(t.first,s,t.second) ;
low[s] = min(low[s],low[t.first]) ;
if(low[t.first]>tin[s]) bridge[t.second] = 1 ;
}
}
tout[s] = ++timer ;
}
int is_ancestor(int u , int v)
{
return ((tin[u]<=tin[v]) && (tout[u]>=tout[v])) ;
}
int find_lca(int u , int v)
{
if(is_ancestor(u,v)) return u ;
if(is_ancestor(v,u)) return v ;
for(int i = LG - 1 ; i >= 0 ; --i)
{
if(!is_ancestor(up[u][i],v))
{
u = up[u][i] ;
}
}
return up[u][0] ;
}
void find_ans(int s , int p , int idx)
{
if(vis[s]) return ;
vis[s] = 1 ;
for(pair<int,int> t : adj[s])
{
if(t.first==p) continue ;
if(!vis[t.first])
{
find_ans(t.first,s,t.second) ;
sub[s][0] += sub[t.first][0] ;
sub[s][1] += sub[t.first][1] ;
}
}
if(bridge[idx])
{
if(sub[s][0])
{
if(edges[idx].second==s) ans[idx] = 3 ;
else ans[idx] = 1 ;
}
else if(sub[s][1])
{
if(edges[idx].second==s) ans[idx] = 1 ;
else ans[idx] = 3 ;
}
else ans[idx] = 2 ;
}
else ans[idx] = 2 ;
}
int main()
{
int n , m ;
scanf("%d%d",&n,&m) ;
edges.push_back({0,0}) ;
for(int i = 1 ; i <= m ; ++i)
{
int a , b ;
scanf("%d%d",&a,&b) ;
adj[a].push_back({b,i}) ;
adj[b].push_back({a,i}) ;
edges.push_back({a,b}) ;
}
for(int i = 1 ; i <= n ; ++i)
{
dfs(i,i,0) ;
}
int q ;
scanf("%d",&q) ;
while(q--)
{
int u , v ;
scanf("%d%d",&u,&v) ;
int lca = find_lca(u,v) ;
++sub[v][0] , --sub[lca][0] ;
++sub[u][1] , --sub[lca][1] ;
}
for(int i = 1 ; i <= n ; ++i)
{
vis[i] = 0 ;
}
for(int i = 1 ; i <= n ; ++i)
{
find_ans(i,0,0) ;
}
for(int i = 1 ; i <= m ; ++i)
{
if(!ans[i]) printf("B") ;
else if(ans[i]==1) printf("L") ;
else if(ans[i]==2) printf("B") ;
else printf("R") ;
}
printf("\n") ;
return 0 ;
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%d%d",&n,&m) ;
| ~~~~~^~~~~~~~~~~~~~
oneway.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | scanf("%d%d",&a,&b) ;
| ~~~~~^~~~~~~~~~~~~~
oneway.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | scanf("%d",&q) ;
| ~~~~~^~~~~~~~~
oneway.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | scanf("%d%d",&u,&v) ;
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2900 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2900 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
49 ms |
11328 KB |
Output is correct |
12 |
Correct |
58 ms |
13976 KB |
Output is correct |
13 |
Correct |
80 ms |
17436 KB |
Output is correct |
14 |
Correct |
115 ms |
21440 KB |
Output is correct |
15 |
Correct |
131 ms |
22568 KB |
Output is correct |
16 |
Correct |
87 ms |
21332 KB |
Output is correct |
17 |
Correct |
99 ms |
23100 KB |
Output is correct |
18 |
Correct |
98 ms |
21304 KB |
Output is correct |
19 |
Correct |
126 ms |
24552 KB |
Output is correct |
20 |
Correct |
68 ms |
15384 KB |
Output is correct |
21 |
Correct |
71 ms |
15460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2772 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2900 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
49 ms |
11328 KB |
Output is correct |
12 |
Correct |
58 ms |
13976 KB |
Output is correct |
13 |
Correct |
80 ms |
17436 KB |
Output is correct |
14 |
Correct |
115 ms |
21440 KB |
Output is correct |
15 |
Correct |
131 ms |
22568 KB |
Output is correct |
16 |
Correct |
87 ms |
21332 KB |
Output is correct |
17 |
Correct |
99 ms |
23100 KB |
Output is correct |
18 |
Correct |
98 ms |
21304 KB |
Output is correct |
19 |
Correct |
126 ms |
24552 KB |
Output is correct |
20 |
Correct |
68 ms |
15384 KB |
Output is correct |
21 |
Correct |
71 ms |
15460 KB |
Output is correct |
22 |
Correct |
192 ms |
24280 KB |
Output is correct |
23 |
Correct |
172 ms |
22376 KB |
Output is correct |
24 |
Correct |
153 ms |
22412 KB |
Output is correct |
25 |
Correct |
173 ms |
27840 KB |
Output is correct |
26 |
Correct |
172 ms |
23836 KB |
Output is correct |
27 |
Correct |
147 ms |
22452 KB |
Output is correct |
28 |
Correct |
48 ms |
6676 KB |
Output is correct |
29 |
Correct |
123 ms |
16144 KB |
Output is correct |
30 |
Correct |
110 ms |
16440 KB |
Output is correct |
31 |
Correct |
120 ms |
16576 KB |
Output is correct |
32 |
Correct |
128 ms |
20684 KB |
Output is correct |