답안 #493365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493365 2021-12-11T07:07:15 Z Biaz One-Way Streets (CEOI17_oneway) C++17
100 / 100
96 ms 18468 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,tst;
vector<pi> e[N];
stack<int> st;
int dp[N],dfn[N],low[N],vis[N],comp[N];
struct Edge{
    int u,v;char c;
} ans[N];
void tarjan(int v,int pre){
    low[v]=dfn[v]=++tst;
    st.push(v);
    for (auto &[to,i]:e[v]){
        if (i==pre) continue;
        if (dfn[to]) low[v]=min(low[v],dfn[to]);
        else{
            tarjan(to,i);
            low[v]=min(low[v],low[to]);
        }
    }
    if (dfn[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[u]<0)
            ans[i].c= v==ans[i].u?'R':'L';
        else if (dp[u]>0)
            ans[i].c= v==ans[i].u?'L':'R';
        dp[v]+=dp[u];
    }
    //cout <<"*";
}
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});
    }
    for (int i=1;i<=n;i++)
        if (!vis[i])
            tarjan(i,0);
    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 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3188 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 2 ms 3148 KB Output is correct
9 Correct 2 ms 3056 KB Output is correct
10 Correct 2 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3188 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 2 ms 3148 KB Output is correct
9 Correct 2 ms 3056 KB Output is correct
10 Correct 2 ms 3020 KB Output is correct
11 Correct 40 ms 9816 KB Output is correct
12 Correct 48 ms 10876 KB Output is correct
13 Correct 64 ms 12268 KB Output is correct
14 Correct 67 ms 13300 KB Output is correct
15 Correct 58 ms 13376 KB Output is correct
16 Correct 69 ms 12072 KB Output is correct
17 Correct 56 ms 13764 KB Output is correct
18 Correct 77 ms 12052 KB Output is correct
19 Correct 65 ms 15156 KB Output is correct
20 Correct 45 ms 10456 KB Output is correct
21 Correct 40 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3020 KB Output is correct
2 Correct 2 ms 3020 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3148 KB Output is correct
5 Correct 2 ms 3188 KB Output is correct
6 Correct 2 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 2 ms 3148 KB Output is correct
9 Correct 2 ms 3056 KB Output is correct
10 Correct 2 ms 3020 KB Output is correct
11 Correct 40 ms 9816 KB Output is correct
12 Correct 48 ms 10876 KB Output is correct
13 Correct 64 ms 12268 KB Output is correct
14 Correct 67 ms 13300 KB Output is correct
15 Correct 58 ms 13376 KB Output is correct
16 Correct 69 ms 12072 KB Output is correct
17 Correct 56 ms 13764 KB Output is correct
18 Correct 77 ms 12052 KB Output is correct
19 Correct 65 ms 15156 KB Output is correct
20 Correct 45 ms 10456 KB Output is correct
21 Correct 40 ms 10092 KB Output is correct
22 Correct 79 ms 14932 KB Output is correct
23 Correct 82 ms 13108 KB Output is correct
24 Correct 96 ms 13396 KB Output is correct
25 Correct 80 ms 18468 KB Output is correct
26 Correct 89 ms 14532 KB Output is correct
27 Correct 82 ms 13116 KB Output is correct
28 Correct 29 ms 7508 KB Output is correct
29 Correct 55 ms 11112 KB Output is correct
30 Correct 56 ms 11444 KB Output is correct
31 Correct 59 ms 11680 KB Output is correct
32 Correct 66 ms 14008 KB Output is correct