Submission #634048

# Submission time Handle Problem Language Result Execution time Memory
634048 2022-08-23T18:03:52 Z radal One-Way Streets (CEOI17_oneway) C++17
100 / 100
88 ms 33092 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 (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] > tout[u.X] || mi[u.X][0] < tin[u.X])) || (!u.Y.Y && (mx[u.X][1] > tout[u.X] || mi[u.X][1] < tin[u.X]))){
                 
                    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],tout[v]);
        mx[v][0] = max(mx[v][0],tout[u]);
        mi[u][1] = min(mi[u][1],tin[v]);
        mi[v][0] = min(mi[v][0],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 10 ms 20308 KB Output is correct
2 Correct 10 ms 20296 KB Output is correct
3 Correct 10 ms 20428 KB Output is correct
4 Correct 12 ms 20408 KB Output is correct
5 Correct 13 ms 20436 KB Output is correct
6 Correct 12 ms 20436 KB Output is correct
7 Correct 12 ms 20436 KB Output is correct
8 Correct 11 ms 20436 KB Output is correct
9 Correct 10 ms 20436 KB Output is correct
10 Correct 11 ms 20468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20308 KB Output is correct
2 Correct 10 ms 20296 KB Output is correct
3 Correct 10 ms 20428 KB Output is correct
4 Correct 12 ms 20408 KB Output is correct
5 Correct 13 ms 20436 KB Output is correct
6 Correct 12 ms 20436 KB Output is correct
7 Correct 12 ms 20436 KB Output is correct
8 Correct 11 ms 20436 KB Output is correct
9 Correct 10 ms 20436 KB Output is correct
10 Correct 11 ms 20468 KB Output is correct
11 Correct 42 ms 27064 KB Output is correct
12 Correct 50 ms 27996 KB Output is correct
13 Correct 58 ms 28928 KB Output is correct
14 Correct 68 ms 29416 KB Output is correct
15 Correct 74 ms 29388 KB Output is correct
16 Correct 64 ms 27600 KB Output is correct
17 Correct 67 ms 28904 KB Output is correct
18 Correct 62 ms 27484 KB Output is correct
19 Correct 61 ms 30148 KB Output is correct
20 Correct 50 ms 27408 KB Output is correct
21 Correct 58 ms 27084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20308 KB Output is correct
2 Correct 10 ms 20296 KB Output is correct
3 Correct 10 ms 20428 KB Output is correct
4 Correct 12 ms 20408 KB Output is correct
5 Correct 13 ms 20436 KB Output is correct
6 Correct 12 ms 20436 KB Output is correct
7 Correct 12 ms 20436 KB Output is correct
8 Correct 11 ms 20436 KB Output is correct
9 Correct 10 ms 20436 KB Output is correct
10 Correct 11 ms 20468 KB Output is correct
11 Correct 42 ms 27064 KB Output is correct
12 Correct 50 ms 27996 KB Output is correct
13 Correct 58 ms 28928 KB Output is correct
14 Correct 68 ms 29416 KB Output is correct
15 Correct 74 ms 29388 KB Output is correct
16 Correct 64 ms 27600 KB Output is correct
17 Correct 67 ms 28904 KB Output is correct
18 Correct 62 ms 27484 KB Output is correct
19 Correct 61 ms 30148 KB Output is correct
20 Correct 50 ms 27408 KB Output is correct
21 Correct 58 ms 27084 KB Output is correct
22 Correct 88 ms 30144 KB Output is correct
23 Correct 77 ms 28500 KB Output is correct
24 Correct 80 ms 28620 KB Output is correct
25 Correct 73 ms 33092 KB Output is correct
26 Correct 77 ms 29768 KB Output is correct
27 Correct 78 ms 28596 KB Output is correct
28 Correct 37 ms 24776 KB Output is correct
29 Correct 71 ms 28156 KB Output is correct
30 Correct 66 ms 28228 KB Output is correct
31 Correct 67 ms 28556 KB Output is correct
32 Correct 66 ms 30252 KB Output is correct