답안 #696209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696209 2023-02-05T21:36:52 Z Shayan86 One-Way Streets (CEOI17_oneway) C++14
100 / 100
66 ms 16424 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n';
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

const ll N = 1e5 + 5;
const ll inf = 1e9 + 7;

ll n, m, q, sum[N], b[N], res[N], h[N];

bool mark[N];
vector<pair<int, pii>> adj[N];

void dfs(int v, pair<int, pii> ii = Mp(0, Mp(0, 0))){
    mark[v] = true;
    for(auto e: adj[v]){
        int u = e.F;
        if(!mark[u]){
            h[u] = h[v]+1;
            dfs(u, e);
            sum[v] += sum[u];
            b[v] += b[u];
        }
        else if(e.S.F != ii.S.F && h[v] > h[u]){
            b[v]++;
            b[u]--;
        }
    }
    if(b[v] > 0 || !sum[v]) return;

    if(true){
        bool up = sum[v] < 0;
        bool change = ii.S.S;
        if(up ^ change) res[ii.S.F] = 2;
        else res[ii.S.F] = 1;

        //cout << v << sep << up << sep << change << sep << (up ^ change) << endl;
    }
}

int main(){
    fast_io;

    cin >> n >> m;

    int u, v;
    for(int i = 1; i <= m; i++){
        cin >> u >> v;
        adj[u].pb(Mp(v, Mp(i, 0)));
        adj[v].pb(Mp(u, Mp(i, 1)));
    }

    cin >> q;

    for(int i = 1; i <= q; i++){
        cin >> u >> v;
        sum[u]++; sum[v]--;
    }

    for(int i = 1; i <= n; i++){
        if(!mark[i]){
            dfs(i);
        }
    }

    for(int i = 1; i <= m; i++){
        if(res[i] == 1)
            cout << 'L';
        else if(res[i] == 2)
            cout << 'R';
        else
            cout << 'B';
    }
    cout << endl;

}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 31 ms 8756 KB Output is correct
12 Correct 36 ms 10068 KB Output is correct
13 Correct 56 ms 11328 KB Output is correct
14 Correct 47 ms 12336 KB Output is correct
15 Correct 60 ms 12444 KB Output is correct
16 Correct 44 ms 9548 KB Output is correct
17 Correct 43 ms 12324 KB Output is correct
18 Correct 57 ms 10068 KB Output is correct
19 Correct 43 ms 13816 KB Output is correct
20 Correct 39 ms 9420 KB Output is correct
21 Correct 36 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 1 ms 2772 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 31 ms 8756 KB Output is correct
12 Correct 36 ms 10068 KB Output is correct
13 Correct 56 ms 11328 KB Output is correct
14 Correct 47 ms 12336 KB Output is correct
15 Correct 60 ms 12444 KB Output is correct
16 Correct 44 ms 9548 KB Output is correct
17 Correct 43 ms 12324 KB Output is correct
18 Correct 57 ms 10068 KB Output is correct
19 Correct 43 ms 13816 KB Output is correct
20 Correct 39 ms 9420 KB Output is correct
21 Correct 36 ms 9724 KB Output is correct
22 Correct 66 ms 12372 KB Output is correct
23 Correct 56 ms 10064 KB Output is correct
24 Correct 58 ms 10188 KB Output is correct
25 Correct 55 ms 16424 KB Output is correct
26 Correct 54 ms 11696 KB Output is correct
27 Correct 59 ms 10248 KB Output is correct
28 Correct 26 ms 5840 KB Output is correct
29 Correct 52 ms 8848 KB Output is correct
30 Correct 49 ms 9276 KB Output is correct
31 Correct 50 ms 9508 KB Output is correct
32 Correct 50 ms 12828 KB Output is correct