Submission #1027306

# Submission time Handle Problem Language Result Execution time Memory
1027306 2024-07-19T03:27:39 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
100 / 100
69 ms 35804 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn_khanhtb_0x2ee08"
#endif

using namespace std;

#define fi first 
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int> 
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 2e5;
int tc, tt = 1;

int n, m, u, v, p;
ii ans[N + 5];

struct edge {
    int v, id, x, y;
};
vector<edge> g[N + 5];
vii e;

namespace sub1 {
    bool ck() {
        return true;
    }

    int tin[N + 5], tout[N + 5], low[N + 5], tdfs = 0;
    int p[N + 5][20];
    int mark[N + 5];
    int vis[N + 5];
    int comp[N + 5], curcomp = 0;
    bool bridge[N + 5];
    int h[N + 5];
    int dp[N + 5];
    int s, t;
    vector<edge> adj[N + 5];

    void find_bridge(int u ,int par) {
        tin[u] = low[u] = ++tdfs;
        vis[u] = true;
        for(auto v: g[u])
            if(v.v != par) {
                if(!vis[v.v]) {
                    find_bridge(v.v, u);
                    low[u] = min(low[u], low[v.v]);
                    if(low[v.v] > tin[u])
                        bridge[v.id] = true;
                }
                else low[u] = min(low[u], tin[v.v]);
            }
        tout[u] = tdfs;
    }

    void find_comp(int u, int par) {
        vis[u] = true;
        comp[u] = curcomp;
        for(auto v: g[u])
            if(v.v != par && !vis[v.v] && !bridge[v.id])
                find_comp(v.v, u);
     }

    void dfs(int u, int par) {
        vis[u] = true;
        for(auto v: adj[u])
            if(v.v != par) {
                v.x = u;
                v.y = v.v;
                dfs(v.v, u);
            }
    }

    void cal(int u, int par) {
        vis[u] = true;
        for(auto v: adj[u])
            if(v.v != par) {
                cal(v.v, u);
                dp[u] += dp[v.v];
                if(dp[v.v] > 0) ans[v.id] = {v.y, v.x};
                if(dp[v.v] < 0) ans[v.id] = {v.x, v.y};
            }
    }

    void sol() {
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
            if(!vis[i]) {
                tdfs = 0;
                find_bridge(i, -1);
            }
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
            if(!vis[i]) {
                curcomp++;
                find_comp(i, -1);
            }
        for(int i=1; i<=m; i++)
            if(bridge[i]) {
                int u = e[i - 1].fi;
                int v = e[i - 1].se;
                if(comp[u] != comp[v]) {
                    adj[comp[u]].pb({comp[v], i, u, v});
                    adj[comp[v]].pb({comp[u], i, v, u});
                }
            }

        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++) 
            if(!vis[i]) 
                dfs(i, -1);

        int q;
        cin>>q;
        for(int i=1; i<=q; i++) {
            cin>>s>>t;
            dp[comp[s]]++;
            dp[comp[t]]--;
        }
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++) {
            if(!vis[i]) cal(i, -1);
        }
        for(int i=1; i<=m; i++) {
            if(ans[i].fi < 0 || !bridge[i]) {
                cout<<"B";
            }
            else {
                cout<<(ans[i] == e[i - 1] ? "R" : "L");
            }
        }
    }
}

void solve() {
    cin>>n>>m;
    for(int i=1; i<=m; i++) {
        cin>>u>>v;
        ans[i] = {-1, -1};
        e.pb({u, v});
        g[u].pb({v, i, -1, -1});
        g[v].pb({u, i, -1, -1});
    }
    if(sub1::ck()) {sub1::sol(); return;}
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    for(tc=1; tc<=tt; tc++) solve();
    cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 2 ms 19036 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 3 ms 19036 KB Output is correct
6 Correct 3 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 2 ms 19036 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 3 ms 19036 KB Output is correct
6 Correct 3 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 35 ms 26052 KB Output is correct
12 Correct 30 ms 26892 KB Output is correct
13 Correct 31 ms 27588 KB Output is correct
14 Correct 46 ms 28184 KB Output is correct
15 Correct 37 ms 28716 KB Output is correct
16 Correct 50 ms 30152 KB Output is correct
17 Correct 45 ms 31944 KB Output is correct
18 Correct 43 ms 30148 KB Output is correct
19 Correct 45 ms 33480 KB Output is correct
20 Correct 29 ms 25792 KB Output is correct
21 Correct 31 ms 25540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19032 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
3 Correct 2 ms 19036 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 3 ms 19036 KB Output is correct
6 Correct 3 ms 19036 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 19036 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 19036 KB Output is correct
11 Correct 35 ms 26052 KB Output is correct
12 Correct 30 ms 26892 KB Output is correct
13 Correct 31 ms 27588 KB Output is correct
14 Correct 46 ms 28184 KB Output is correct
15 Correct 37 ms 28716 KB Output is correct
16 Correct 50 ms 30152 KB Output is correct
17 Correct 45 ms 31944 KB Output is correct
18 Correct 43 ms 30148 KB Output is correct
19 Correct 45 ms 33480 KB Output is correct
20 Correct 29 ms 25792 KB Output is correct
21 Correct 31 ms 25540 KB Output is correct
22 Correct 63 ms 31932 KB Output is correct
23 Correct 69 ms 30100 KB Output is correct
24 Correct 60 ms 30160 KB Output is correct
25 Correct 62 ms 35804 KB Output is correct
26 Correct 54 ms 31532 KB Output is correct
27 Correct 55 ms 30116 KB Output is correct
28 Correct 24 ms 24012 KB Output is correct
29 Correct 39 ms 25476 KB Output is correct
30 Correct 34 ms 25500 KB Output is correct
31 Correct 36 ms 25980 KB Output is correct
32 Correct 40 ms 28860 KB Output is correct