답안 #493336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493336 2021-12-11T06:24:28 Z Biaz One-Way Streets (CEOI17_oneway) C++17
0 / 100
2 ms 3020 KB
#include <bits/stdc++.h>
//#define int long long
#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
//int max(int x,int y){return x>=y?x:y;}
//int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=100005;
const int M=100000005;
const int MOD=1000000007;//998244353;
const int INF=2147483647;//1000000000000000;

int n,m,P,cpCnt;
vector<pi> e[N];
stack<int> st;
int dp[N],dep[N],low[N],vis[N],comp[N];
struct Edge{
    int u,v;
    char c;
} ans[N];
void tarjan(int v,int pre){
    low[v]=dep[v]=dep[pre]+1;
    vis[v]=1;
    st.push(v);
    for (auto &[to,i]:e[v]){
        if (to==pre) continue;
        if (vis[to]) low[v]=min(low[v],dep[to]);
        else{
            tarjan(to,v);
            low[v]=min(low[v],low[to]);
        }
    }
    if (dep[v]==low[v]){
        ++cpCnt;
        while (1){
            int u=st.top();st.pop();
            comp[u]=cpCnt;
            if (v==u) break;
        }
    }
}
void build_tree(){
    for (int i=1;i<=n;i++)
        e[i].clear();
    for (int i=1;i<=m;i++){
        ans[i].u=comp[ans[i].u];
        ans[i].v=comp[ans[i].v];
        if (ans[i].u!=ans[i].v){
            e[ans[i].u].pb({ans[i].v,i});
            e[ans[i].v].pb({ans[i].u,i});
        }
    }
    n=cpCnt;
}
void dfs(int v,int pre){
    vis[v]=1;
    for (auto [u,i]:e[v]) if (u!=pre){
        dfs(u,v);
        if (dp[u]==0) ans[i].c='B';
        else if (dp[v]<0)
            ans[i].c= v==ans[i].u?'R':'L';
        else
            ans[i].c= v==ans[i].u?'L':'R';
        dp[v]+=dp[u];
    }
}
inline void sol(){
    cin >>n>>m;
    for (int i=1,a,b;i<=m;i++){
        cin >>a>>b;ans[i]={a,b,'B'};
        e[a].pb({b,i});
        e[b].pb({a,i});
    }
    tarjan(1,1);
    build_tree();
    cin >>P;
    for (int a,b;P--;)
        cin >>a>>b,dp[comp[a]]++,dp[comp[b]]--;
    memset(vis,0,sizeof(vis));
    for (int i=1;i<=n;i++)
        if (!vis[i])
            dfs(i,0);
    for (int i=1;i<=m;i++)
        cout <<ans[i].c;
}
signed main(){
    Nanase_Kurumi_aka_menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -