Submission #1032782

# Submission time Handle Problem Language Result Execution time Memory
1032782 2024-07-24T08:29:31 Z amine_aroua One-Way Streets (CEOI17_oneway) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
vector<vector<pair<int , int>>> adj;
vector<int> depth;
vector<int> dp;
vector<int> pref;
vector<vector<int>> up;
vector<char> ans;
vector<pair<int ,int>> edges;
void dfs(int x)
{
    for(auto [u , i] : adj[x])
    {
        if(depth[u] == 0)
        {
            up[0][u] = x;
            depth[u] = depth[x] + 1;
            for(int j = 1 ; j < 18 ; j++)
            {
                up[j][u] = up[j - 1][up[j - 1][u]];
            }
            dfs(u);
            dp[x]+=dp[u];
        }
        else if(depth[u] < depth[x])
        {
            dp[x]++;
        }
        else
        {
            dp[x]--;
        }
    }
    dp[x]--;
}
void dfs1(int x)
{
    for(auto [u , i] : adj[x])
    {
        if(depth[u] == 0)
        {
            depth[u] = depth[x] + 1;
            dfs1(u);
            if(dp[u] == 0 && pref[u])
            {
                int m1 = (u == edges[i].first ? 1 : -1);
                int m2 = (pref[u] > 0 ? 1 : -1);
                if(m1 * m2 > 0)
                {
                    ans[i] = 'R';
                }
                else
                    ans[i] = 'L';
            }
            pref[x]+=pref[u];
        }
    }
}
void lift(int &u , int k)
{
    for(int i = 0 ; i < 18 ; i++)
    {
        if((1<<i) & k)
        {
            u = up[i][u];
        }
    }
}
int lca(int u  , int v)
{
    if(depth[u] < depth[v])
        swap(u , v);
    int x = depth[u] - depth[v];
    lift(u , x);
    if(u == v)
        return u;
    for(int j = 17 ; j >= 0 ; j--)
    {
        int nu = up[j][u] , nv = up[j][v];
        if(nu == nv)
            continue;
        u = nu , v = nv;
    }
    return up[0][u];
}
int main()
{
    int n , m;
    cin>>n>>m;
    up.assign(18 , vector<int>(n + 1));
    adj = vector<vector<pair<int, int>>> (n + 1);
    depth = vector<int> (n + 1);
    dp = depth;
    pref = depth;
    edges.assign(m , {});
    ans.assign(m , 'B');
    for(int i = 0 ; i < m; i++)
    {
        int x ,y;
        cin>>x>>y;
        edges[i] = {x , y};
        adj[x].push_back({y , i});
        adj[y].push_back({x , i});
    }
    depth[1] = 1;
    dfs(1);
    int p ;
    cin>>p;
    for(int i = 0 ; i < p ; i++)
    {
        int x , y;
        cin>>x>>y;
        int l = lca(x , y);
        pref[x]++;
        pref[y]--;
    }
    depth.assign(n + 1 , 0);
    depth[1] = 1;
    dfs1(1);
    for(int i = 0 ;i < m; i++)
        cout<<ans[i];
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:113:13: warning: unused variable 'l' [-Wunused-variable]
  113 |         int l = lca(x , y);
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -