Submission #634009

# Submission time Handle Problem Language Result Execution time Memory
634009 2022-08-23T16:16:48 Z radal One-Way Streets (CEOI17_oneway) C++17
0 / 100
13 ms 20428 KB
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2")
#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 5e5+20,mod = 1e9+7,inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k /= 2;
    } 
    return z; 
}

bool vis[N];
int h[N],lw[N],tin[N],mx[N][2],T,tout[N],mi[N][2];
char ans[N];
vector<pair<int,pair<int,bool> >> adj[N];
void pre(int v){
    vis[v] = 1;
    tin[v] = T++;
    for (auto u : adj[v]){
        if (vis[u.X]) continue;
        h[u.X] = h[v]+1;
        pre(u.X);
    }
    tout[v] = T++;
}

void dfs(int v,int p){
    bool fl = 0;
    lw[v] = h[v];
    vis[v] = 1;
    for (auto u : adj[v]){
        if (v == 1){
           // debug(u.X);
        }
        if (u.X == v){
            ans[u.Y.X] = 'B';
            continue;
        }
        if (vis[u.X]){
            if (u.X == p){
                if (fl) lw[v] = min(lw[v],h[v]-1);
                fl = 1;
            }
            else{
                lw[v] = min(lw[v],h[u.X]);
                ans[u.Y.X] = 'B';
            }
            continue;
        }
        dfs(u.X,v);
        rep(i,0,2){
            mx[v][i] = max(mx[v][i],mx[u.X][i]);
            mi[v][i] = min(mi[v][i],mi[u.X][i]);
        }
        if (lw[u.X] > h[v]){
            if (max(mx[u.X][0],mx[u.X][1]) <= tout[u.X] && min(mi[u.X][1],mi[u.X][0]) >= tin[u.X]){
                ans[u.Y.X] = 'B';
            }
            else{
                if ((u.Y.Y && mx[u.X][0] != -1) || (!u.Y.Y && mx[u.X][1] != -1)) ans[u.Y.X] = 'L';
                else ans[u.Y.X] = 'R';
            }
        }
        else{
            lw[v] = min(lw[v],lw[u.X]);
            ans[u.Y.X] = 'B';
        }
    }
}
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(0);
    memset(mx,-1,sizeof mx);
    memset(mi,63,sizeof mi);
    int n,m;
    cin >> n >> m;
    rep(i,0,m){
        int u,v;
        cin >> u >> v;
        adj[v].pb({u,{i,1}});
        adj[u].pb({v,{i,0}});
    }
    rep(i,1,n+1) if (!vis[i]) pre(i);
    memset(vis,0,sizeof vis);
    int q;
    cin >> q;
    while (q--){
        int u,v;
        cin >> u >> v;
        mx[u][1] = max(mx[u][1],tin[v]);
        mx[v][0] = max(mx[v][0],tin[u]);
        mi[u][1] = min(mi[u][1],tin[v]);
        mi[v][1] = min(mi[v][1],tin[u]);
    }
    rep(i,1,n+1) if (!vis[i]) dfs(i,-1);
    rep(i,0,m) cout << ans[i];
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20308 KB Output is correct
2 Correct 10 ms 20292 KB Output is correct
3 Correct 13 ms 20428 KB Output is correct
4 Incorrect 11 ms 20420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20308 KB Output is correct
2 Correct 10 ms 20292 KB Output is correct
3 Correct 13 ms 20428 KB Output is correct
4 Incorrect 11 ms 20420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20308 KB Output is correct
2 Correct 10 ms 20292 KB Output is correct
3 Correct 13 ms 20428 KB Output is correct
4 Incorrect 11 ms 20420 KB Output isn't correct
5 Halted 0 ms 0 KB -