Submission #979806

# Submission time Handle Problem Language Result Execution time Memory
979806 2024-05-11T11:48:28 Z VMaksimoski008 One-Way Streets (CEOI17_oneway) C++17
0 / 100
4 ms 14428 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 5;
const double eps = 1e-9;

vector<int> graph[maxn], in(maxn), low(maxn), vis(maxn), cmp(maxn), tree[maxn], dp(maxn), dist(maxn);
int timer = 1, n, m, curr;
set<pii> bridges;
vector<vector<int> > G;

void dfs(int u, int p) {
    vis[u] = 1;
    low[u] = in[u] = timer++;
    bool ok = 0;

    for(int &v : graph[u]) {
        if(v == p && !ok) {
            ok = 1;
            continue;
        }

        if(vis[v]) {
            low[u] = min(low[u], in[v]);
        } else {
            dfs(v, u);
            low[u] = min(low[u], low[v]);
            if(low[v] > in[u]) bridges.insert({ min(u, v), max(u, v) });
        }
    }
}

void dfs2(int u) {
    vis[u] = 1;
    cmp[u] = curr;
    G.back().push_back(u);
    for(int &v : graph[u])
        if(!vis[v] && !bridges.count({ min(u, v), max(u, v) })) dfs2(v);
}

void dfs3(int u, int p) {
    for(int &v : tree[u]) {
        if(v == p) continue;
        dist[v] = dist[u] + 1;
        dfs(v, u);
        dp[v] += dp[u]; 
    } 
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    cin >> n >> m;
    curr = n + 1;
    vector<pii> E;
    for(int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        E.push_back({ a, b });
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    for(int i=1; i<=n; i++)
        if(!vis[i]) dfs(i, i);
    for(int i=1; i<=n; i++) vis[i] = 0;
    for(int i=1; i<=n; i++) {
        if(vis[i]) continue;
        G.push_back({ });
        dfs2(i);
        curr++;
    }

    set<pii> edges;
    for(int i=1; i<=n; i++)
        for(int &j : graph[i])
            if(cmp[i] != cmp[j]) edges.insert({ cmp[i], cmp[j] });
        
    for(auto &x : edges) tree[x.first].push_back(x.second);

    int q;
    cin >> q;
    while(q--) {
        int a, b;
        cin >> a >> b;
        dp[cmp[a]]++, dp[cmp[b]]--;
    }

    for(int i=n+1; i<curr; i++)
        if(!vis[i]) dfs3(i, i);
    
    for(auto &[a, b] : E) {
        if(cmp[a] == cmp[b]) {
            cout << 'B';
            continue;
        }

        if(dist[cmp[a]] > dist[cmp[b]]) {
            if(dp[cmp[a]] > 0) cout << 'R';
            else if(dp[cmp[a]] == 0) cout << 'B';
            else cout << 'L';
        } else {
            if(dp[cmp[b]] > 0) cout << 'L';
            else if(dp[cmp[b]] == 0) cout << 'B';
            else cout << 'R';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -