답안 #375452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375452 2021-03-09T12:22:48 Z ritul_kr_singh One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 492 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

vector<vector<pair<int, int>>> g0, g1;

vector<int> id, low, dfsNum, st;
int dfsTimer = 1;

void tarjan(int u, int parentEdge){
    dfsNum[u] = low[u] = dfsTimer++;
    st.push_back(u);
    for(auto e : g0[u]){
        if(e.second==parentEdge) continue;
        if(!dfsNum[e.first]) tarjan(e.first, e.second);
        low[u] = min(low[u], low[e.first]);
    }
    if(low[u]==dfsNum[u]){
        int v = -1;
        while(v!=u){
            v = st.back(); st.pop_back();
            id[v] = u;
        }
    }
}

vector<int> parentEdge, parent, depth;
void dfs(int u, int currDepth){
    depth[u] = currDepth;
    dfsNum[u] = 1;
    for(auto e : g1[u]){
        if(!dfsNum[e.first]){
            parentEdge[e.first] = e.second;
            parent[e.first] = u;
            dfs(e.first, currDepth+1);
        }
    }
}

int ans[100000] = {};
pair<int, int> edges[100000];

void orient(int u, int v){
    int e = parentEdge[u];
    if(e<0 or min(id[edges[e].first], id[edges[e].second]) != min(u, v)
        or max(id[edges[e].first], id[edges[e].second]) != max(u, v)){
        e = parentEdge[v];
    }
    if(edges[e].first != u) ans[e] = -1;
    else ans[e] = 1;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m; cin >> n >> m;

    g0.resize(n), g1.resize(n);
    for(int i=0; i<m; ++i){
        cin >> edges[i].first >> edges[i].second;
        --edges[i].first, --edges[i].second;
        g0[edges[i].first].emplace_back(edges[i].second, i);
        g0[edges[i].second].emplace_back(edges[i].first, i);
    }
    dfsNum.assign(n, 0), id.assign(n, -1), low.resize(n);
    for(int i=0; i<n; ++i) if(!dfsNum[i]) tarjan(i, -1);

    for(int i=0; i<m; ++i){
        int x = id[edges[i].first], y = id[edges[i].second];
        if(x==y) continue;
        g1[x].emplace_back(y, i);
        g1[y].emplace_back(x, i);
    }

    dfsNum.assign(n, 0), parent.assign(n, 0), parentEdge.assign(n, -1), depth.resize(n);
    for(int i=0; i<n; ++i) if(!dfsNum[i] and id[i]==i) dfs(i, 0);

    int p; cin >> p;
    while(p--){
        int x, y; cin >> x >> y;
        x = id[x-1], y = id[y-1];
        while(depth[x] > depth[y]){
            orient(x, parent[x]), x = parent[x];
        }
        while(depth[y] > depth[x]){
            orient(parent[y], y), y = parent[y];
        }
        while(x!=y){
            orient(x, parent[x]), x = parent[x];
            orient(parent[y], y), y = parent[y];
        }
    }

    for(int i=0; i<m; ++i){
        char c = 'B';
        if(ans[i]<0) c = 'L';
        if(ans[i]>0) c = 'R';
        cout << c;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 492 KB Output isn't correct
4 Halted 0 ms 0 KB -