답안 #701066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701066 2023-02-20T01:57:53 Z Darren0724 One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 468 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];
    }
    for(int i=0;i<n;i++){
        if(in[i]==0)dfs1(i,-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]--;
    }
    for(int i=1;i<=bcc_cnt;i++){
        if(dis[i]==0){
            dis[i]=i;
            dfs2(i);
        }
    }
    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 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -