Submission #236619

# Submission time Handle Problem Language Result Execution time Memory
236619 2020-06-02T15:44:57 Z Autoratch One-Way Streets (CEOI17_oneway) C++14
0 / 100
6 ms 2816 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 1;
const int K = 19;

int n,m,p;
vector<int> adj[N];
map<pair<int,int>,int> mul; 
map<pair<int,int>,pair<int,char> > hsh;
bool visited[N];
int res[N],lv[N],dp[K][N];
int rec[N];
string ans;

void dfs(int u,int p)
{
    if(visited[u]) return;
    visited[u] = true;
    lv[u] = lv[p]+1,dp[0][u] = p;
    for(int v : adj[u]) if(v!=p) dfs(v,u);
}

int lca(int a,int b)
{
    if(lv[a]<lv[b]) swap(a,b);
    for(int i = K-1;i >= 0;i--) if(lv[dp[i][a]]>=lv[b]) a = dp[i][a];
    if(a==b) return a;
    for(int i = K-1;i >= 0;i--) if(dp[i][a]!=dp[i][b]) a = dp[i][a],b = dp[i][b];
    return dp[0][a];
}

void solve(int u,int p)
{
    if(visited[u]){ res[u]++,res[p]++,res[lca(u,p)]-=2; return; }
    visited[u] = true;
    for(int v : adj[u]) if(v!=p) solve(v,u);
}

void sum(int u,int p)
{
    if(visited[u]) return;
    visited[u] = true;
    for(int v : adj[u]) if(v!=p) sum(v,u);
    res[p]+=res[u];
}

void run(int u,int p)
{
    if(visited[u]) return;
    visited[u] = true;
    for(int v : adj[u]) if(v!=p) run(v,u);
    rec[p]+=rec[u];
    if(mul[{min(u,p),max(u,p)}]>1) return;
    if(res[u]) return;
    if(rec[u]>0) ans[hsh[{u,p}].first] = hsh[{u,p}].second;
    else if(rec[u]<0) ans[hsh[{p,u}].first] = hsh[{p,u}].second;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;
    for(int i = 0;i < m;i++)
    {
        int a,b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        hsh[{a,b}] = {i,'R'};
        hsh[{b,a}] = {i,'L'};
        mul[{min(a,b),max(a,b)}]++;
    }
    dfs(1,0);
    for(int i = 1;i < K;i++) for(int j = 1;j <= n;j++) dp[i][j] =  dp[i-1][dp[i-1][j]];
    for(int i = 1;i <= n;i++) visited[i] = false;
    solve(1,0);
    for(int i = 1;i <= n;i++) visited[i] = false;
    sum(1,0);
    cin >> p;
    while(p--)
    {
        int a,b;
        cin >> a >> b;
        rec[a] = 1,rec[b] = -1;
    }
    for(int i = 1;i <= n;i++) visited[i] = false;
    ans.resize(m);
    run(1,0);
    for(int i = 0;i < m;i++) if(ans[i]!='L' and ans[i]!='R') ans[i] = 'B';
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -