Submission #566189

# Submission time Handle Problem Language Result Execution time Memory
566189 2022-05-22T04:21:54 Z shahriarkhan One-Way Streets (CEOI17_oneway) C++14
0 / 100
2 ms 2644 KB
#include<bits/stdc++.h>
using namespace std ;

//1 = L
//2 = B
//3 = R

const int MX = 1e5 + 5 , LG = 25 ;

int bridge[MX] , par[MX] , up[MX][LG] , vis[MX] , depth[MX] , ans[MX] , low[MX] , tin[MX] , tout[MX] , timer = 0 , sub[MX] ;

vector<pair<int,int> > adj[MX] , edges ;

void dfs(int s , int p)
{
    if(vis[s]) return ;
    up[s][0] = p , par[s] = p , vis[s] = 1 , depth[s] = depth[p] + 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] += sub[t.first] ;
        }
    }
    if(bridge[idx])
    {
        if(sub[s]) ans[idx] = 1 ;
        else ans[idx] = 3 ;
    }
    else ans[idx] = 2 ;
}

int main()
{
    int n , m ;
    scanf("%d%d",&n,&m) ;
    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) ;
        ++sub[v] , --sub[find_lca(u,v)] ;
    }
    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:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     scanf("%d%d",&n,&m) ;
      |     ~~~~~^~~~~~~~~~~~~~
oneway.cpp:83:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         scanf("%d%d",&a,&b) ;
      |         ~~~~~^~~~~~~~~~~~~~
oneway.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     scanf("%d",&q) ;
      |     ~~~~~^~~~~~~~~
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",&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 -