Submission #943370

# Submission time Handle Problem Language Result Execution time Memory
943370 2024-03-11T12:14:09 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
0 / 100
3 ms 9052 KB
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
	return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
	return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const ll inf=1e18;
const ll mod=998244353;
const ll N=1e5+5;
const ld eps=1e-9;
vector<vll> g(N),g2(N);
ll n,m;
ll d[N],up[N];
pair<ll,ll> e[N];
bool br[N];
ll comp[N];
char ans[N];
void dfs(ll v,ll x){
    up[v]=d[v];
    ll b;
    for(auto i : g[v]){
        if(i==x) continue;
        if(v==e[i].fr)b=e[i].sc;
        else b=e[i].fr;
        if(d[b]){chmin(up[v],d[b]);continue;}
        d[b]=d[v]+1;
        dfs(b,i);
        chmin(up[v],up[b]);
    }
    if(up[v]>=d[v]){
        br[x]=1;
    }
}
void build(ll v,ll x){
    ll b;
    for(auto i : g[v]){
        if(v==e[i].fr)b=e[i].sc;
        else b=e[i].fr;
        if(comp[b])continue;
        if(br[i]) comp[b]=b;
        else comp[b]=comp[v];
        build(b,i);
    }
}
ll c[N],c2[N];
void dfs2(ll v,ll x){
    ll b;
    for(auto i : g2[v]){
        if(i==x) continue;
        if(v==e[i].fr)b=e[i].sc;
        else b=e[i].fr;
        dfs2(b,i);
        c[v]+=c[b];
        c2[v]+=c2[b];
    }
    if(c[v]==c2[v])ans[x]='B';
    else if(c[v]<c2[v]){
        if(e[x].fr==v)ans[x]='L';
        else ans[x]='R';
    }else{
        if(e[x].fr==v)ans[x]='R';
        else ans[x]='L';
    }
}
void solve(){
    ll i,j;
    ll q;
    cin>>n>>m;
    ll a,b;
    for(i=1;i<=m;i++){
        cin>>a>>b;
        e[i]={a,b};
        if(a==b) continue;
        g[a].pb(i);
        g[b].pb(i);
    }
    d[1]=1;
    dfs(1,0);
    comp[1]=1;
    build(1,0);
    for(i=1;i<=m;i++){
        e[i].fr=comp[e[i].fr],e[i].sc=comp[e[i].sc];
        a=e[i].fr,b=e[i].sc;
        if(!br[i])ans[i]='B';
        else {
            g2[a].pb(i);
            g2[b].pb(i);
        }
    }
    cin>>q;
    for(i=1;i<=m;i++)ans[i]=0;
    for(i=1;i<=q;i++){
        cin>>a>>b;
        c[comp[a]]++;
        c2[comp[b]]++;
    }
    dfs2(1,0);
    for(i=1;i<=m;i++) cout<<ans[i];
}

signed main(){
	start();
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
/*

9 11
1 2
2 1
1 3
3 4
4 5
3 5
4 6
2 7
2 8
8 9
7 1
2
7 5
9 6



*/

Compilation message

oneway.cpp: In function 'void solve()':
oneway.cpp:100:10: warning: unused variable 'j' [-Wunused-variable]
  100 |     ll i,j;
      |          ^
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -