답안 #701065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701065 2023-02-20T01:47:52 Z Darren0724 One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
int n,m;
vector<int> a,b;
vector<int> low,in;
vector<vector<int>> adj;
vector<int> ab,br;
vector<int> num;
vector<int> bcc;
vector<int> st;
vector<int> dx;
vector<int> dis;
int timet=1,bcc_cnt=0;
void dfs1(int k,int pa){
    in[k]=low[k]=timet++;
    st.push_back(k);
    for(int i:adj[k]){
        int j=ab[i]^k;
        if(pa==j){
            continue;
        }
        if(low[j]){
            low[k]=min(low[k],in[j]);
        }
        else{
            dfs1(j,k);
            low[k]=min(low[k],low[j]);
            if(low[j]==in[j]){
                br[i]=1;
            }
        }
    }
    if(low[k]==in[k]){
        bcc_cnt++;
        while(st.back()!=k){
            bcc[st.back()]=bcc_cnt;
            st.pop_back();
        }
        st.pop_back();
        bcc[k]=bcc_cnt;
    }
}
void dfs2(int k){
    for(int j:adj[k]){
        if(dis[j]){
            continue;
        }
        dis[j]=dis[k]+1;
        dfs2(j);
        dx[k]+=dx[j];
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    adj.resize(n);
    in.resize(n);
    low.resize(n);
    ab.resize(m);
    br.resize(m);
    a.resize(m);
    b.resize(m);
    bcc.resize(n);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];a[i]--;b[i]--;
        adj[a[i]].push_back(i);
        adj[b[i]].push_back(i);
        ab[i]=a[i]^b[i];
    }
    dfs1(0,-1);
    for(int i=0;i<m;i++){
        a[i]=bcc[a[i]];
        b[i]=bcc[b[i]];
    }
    adj.clear();
    adj.resize(bcc_cnt+1);
    dis.resize(bcc_cnt+1);
    dx.resize(bcc_cnt+1);
    for(int i=0;i<m;i++){
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int c,d;cin>>c>>d;c--;d--;
        c=bcc[c],d=bcc[d];
        dx[c]++;
        dx[d]--;
    }
    dis[1]=1;
    dfs2(1);
    for(int i=0;i<m;i++){
        if(!br[i]){
            cout<<'B';
        }
        else{
            if(dis[a[i]]>dis[b[i]]){
                if(dx[a[i]]==0){
                    cout<<'B';
                }
                else if(dx[a[i]]>0){
                    cout<<'R';
                }
                else{
                    cout<<'L';
                }
            }
            else{
                if(dx[b[i]]==0){
                    cout<<'B';
                }
                else if(dx[b[i]]>0){
                    cout<<'L';
                }
                else{
                    cout<<'R';
                }
            }
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -