답안 #939558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939558 2024-03-06T13:58:55 Z phoenix0423 One-Way Streets (CEOI17_oneway) C++17
100 / 100
83 ms 37404 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
const int maxn = 2e5 + 5;
int n, m, q;
vector<pll> adj[maxn];
vector<pll> nadj[maxn];
int scc[maxn], low[maxn], in[maxn], dfn = 0, cnt = 0;
int val[maxn];
pll ori[maxn];
stack<int> st;

void dfs(int pos, int pid){
    low[pos] = in[pos] = ++dfn;
    st.push(pos);
    for(auto [x, id] : adj[pos]){
        if(id == pid) continue;
        if(in[x]) low[pos] = min(low[pos], in[x]);
        else{
            dfs(x, id);
            low[pos] = min(low[pos], low[x]);
        }
    }
    if(low[pos] >= in[pos]){
        cnt++;
        while(st.top() != pos){
            scc[st.top()] = cnt;
            st.pop();
        }
        scc[pos] = cnt;
        st.pop();
    }
}

void dfs2(int pos, int prev){
    in[pos] = -1;
    for(auto [x, id] : nadj[pos]){
        if(x == prev) continue;
        dfs2(x, pos);
        if(val[x] > 0) ori[id] = {x, pos};
        if(val[x] < 0) ori[id] = {pos, x};
        val[pos] += val[x];
    }
}
signed main(void){
    fastio;
    cin>>n>>m;
    vector<pll> e;
    for(int i = 0; i < m; i++){
        int a, b;
        cin>>a>>b;
        a--, b--;
        adj[a].eb(b, i);
        adj[b].eb(a, i);
        e.pb({a, b});
    }
    for(int i = 0; i < n; i++) if(!in[i]) dfs(i, -1);
    for(int i = 0; i < n; i++){
        for(auto [x, id] : adj[i]){
            if(scc[i] != scc[x]){
                nadj[scc[i]].eb(scc[x], id);
            }
        }
    }
    cin>>q;
    for(int i = 0; i < q; i++){
        int a, b;
        cin>>a>>b;
        a--, b--;
        val[scc[a]] ++, val[scc[b]] --;
    }
    for(int i = 1; i <= cnt; i++) if(in[i] != -1) dfs2(i, -1);
    for(int i = 0; i < m; i++){
        if(ori[i].f == ori[i].s) cout<<'B';
        else if(ori[i] == pll(scc[e[i].f], scc[e[i].s])) cout<<'R';
        else cout<<'L';
    }
    cout<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14968 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14968 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 32 ms 24232 KB Output is correct
12 Correct 35 ms 27340 KB Output is correct
13 Correct 40 ms 28092 KB Output is correct
14 Correct 46 ms 28652 KB Output is correct
15 Correct 47 ms 29380 KB Output is correct
16 Correct 71 ms 31104 KB Output is correct
17 Correct 69 ms 32444 KB Output is correct
18 Correct 64 ms 30924 KB Output is correct
19 Correct 63 ms 34032 KB Output is correct
20 Correct 34 ms 26560 KB Output is correct
21 Correct 34 ms 26308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14968 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 32 ms 24232 KB Output is correct
12 Correct 35 ms 27340 KB Output is correct
13 Correct 40 ms 28092 KB Output is correct
14 Correct 46 ms 28652 KB Output is correct
15 Correct 47 ms 29380 KB Output is correct
16 Correct 71 ms 31104 KB Output is correct
17 Correct 69 ms 32444 KB Output is correct
18 Correct 64 ms 30924 KB Output is correct
19 Correct 63 ms 34032 KB Output is correct
20 Correct 34 ms 26560 KB Output is correct
21 Correct 34 ms 26308 KB Output is correct
22 Correct 70 ms 33728 KB Output is correct
23 Correct 83 ms 32192 KB Output is correct
24 Correct 68 ms 32256 KB Output is correct
25 Correct 74 ms 37404 KB Output is correct
26 Correct 73 ms 33468 KB Output is correct
27 Correct 69 ms 32300 KB Output is correct
28 Correct 26 ms 21800 KB Output is correct
29 Correct 48 ms 27068 KB Output is correct
30 Correct 45 ms 27324 KB Output is correct
31 Correct 46 ms 27840 KB Output is correct
32 Correct 56 ms 30724 KB Output is correct