#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)
{
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.first==p) continue ;
if(vis[t.first]) low[s] = min(low[s],tin[t.first]) ;
else
{
dfs(t.first,s) ;
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}) ;
}
dfs(1,1) ;
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 ;
}
find_ans(1,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:101:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
101 | scanf("%d",&q) ;
| ~~~~~^~~~~~~~~
oneway.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | scanf("%d%d",&u,&v) ;
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |