답안 #938875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938875 2024-03-05T17:41:45 Z Aiperiii One-Way Streets (CEOI17_oneway) C++14
0 / 100
4 ms 10844 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g_brg[N];
vector <pair <int,int> > g_gr[N];
int vis_brg[N],low[N],tin[N],gr[N],To[N],from[N],vis_gr[N];
char ans[N];
map <pair <int,int> ,int> brg,ind,cnt;
int tt=0,Cnt=0;
void dfs_brg(int v,int p){
    vis_brg[v]=1;
    tt++;
    tin[v]=tt;low[v]=tt;
    for(auto to : g_brg[v]){
        if(to!=p){
            if(vis_brg[to])low[v]=min(low[v],tin[to]);
            else{
                dfs_brg(to,v);
                low[v]=min(low[v],low[to]);
                if(low[to]>tin[v]){
                    brg[{v,to}]++;
                    brg[{to,v}]++;
                }
            }
        }
    }
}
void groups(int v,int p){
    gr[v]=Cnt;
    for(auto to : g_brg[v]){
        if(!gr[to] && (cnt[{v,to}]>1 or !brg[{v,to}]))groups(to,v);
    }
}
void dfs(int v,int p){
    vis_gr[v]=1;
    for(auto to : g_gr[v]){
        if(to.ff!=p){
            dfs(to.ff,v);
            from[v]+=from[to.ff];
            To[v]+=To[to.ff];
        }
    }
    for(auto to : g_gr[v]){
        if(to.ff!=p){
            if(from[to.ff]<To[to.ff]){
                if(to.ss<0)ans[abs(to.ss)]='L';
                else ans[to.ss]='R';
            }
            else if(from[to.ff]>To[to.ss]){
                if(to.ss<0)ans[abs(to.ss)]='R';
                else ans[to.ss]='L';
            }
        }
    }
}
 
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector <int> a(m),b(m);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        g_brg[a[i]].pb(b[i]);
        g_brg[b[i]].pb(a[i]);
        cnt[{a[i],b[i]}]++;
        cnt[{b[i],a[i]}]++;
        ind[{a[i],b[i]}]=i+1;
        ind[{b[i],a[i]}]=-i-1;
    }
    for(int i=1;i<=n;i++){
        if(!vis_brg[i])dfs_brg(i,0);
    }
    for(int i=1;i<=n;i++){
        if(!gr[i]){
            Cnt++;
            groups(i,0);
            
        }
    }
    for(int i=0;i<m;i++){
        if(gr[a[i]]!=gr[b[i]]){
            g_gr[gr[a[i]]].pb({gr[b[i]],ind[{a[i],b[i]}]});
            g_gr[gr[b[i]]].pb({gr[a[i]],ind[{b[i],a[i]}]});
        }
    }
    int q;cin>>q;
    while(q--){
        int s,t;
        cin>>s>>t;
        from[gr[s]]++;
        To[gr[t]]++;
    }
    for(int i=1;i<=m;i++)ans[i]='B';
    for(int i=1;i<=Cnt;i++){
        if(!vis_gr[i]){
            dfs(i,0);
        }
    }
    for(int i=1;i<=m;i++)cout<<ans[i];
}
/*
5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10328 KB Output is correct
2 Correct 2 ms 10332 KB Output is correct
3 Correct 4 ms 10844 KB Output is correct
4 Incorrect 4 ms 10844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10328 KB Output is correct
2 Correct 2 ms 10332 KB Output is correct
3 Correct 4 ms 10844 KB Output is correct
4 Incorrect 4 ms 10844 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10328 KB Output is correct
2 Correct 2 ms 10332 KB Output is correct
3 Correct 4 ms 10844 KB Output is correct
4 Incorrect 4 ms 10844 KB Output isn't correct
5 Halted 0 ms 0 KB -